Initial revision
[ardour.git] / libs / midi++2 / mmctest.cc
1 #include <cstdio>
2 #include <fcntl.h>
3
4 #include <pbd/error.h>
5 #include <pbd/textreceiver.h>
6
7 Transmitter error (Transmitter::Error);
8 Transmitter info (Transmitter::Info);
9 Transmitter warning (Transmitter::Warning);
10 Transmitter fatal (Transmitter::Fatal);
11 TextReceiver text_receiver ("mmctest");
12
13 #include "midi++/port.h"
14 #include "midi++/port_request.h"
15 #include "midi++/manager.h"
16 #include "midi++/mmc.h"
17
18 using namespace MIDI;
19
20 Port *port;
21 PortRequest midi_device;
22 Parser *parser;
23 MachineControl *mmc;
24 MachineControl::CommandSignature cs;
25 MachineControl::ResponseSignature rs;
26
27 int 
28 setup_midi ()
29
30 {
31         midi_device.devname = "/dev/snd/midiC0D0";
32         midi_device.tagname = "trident";
33         midi_device.mode = O_RDWR;
34         midi_device.type = Port::ALSA_RawMidi;
35
36         if ((port = MIDI::Manager::instance()->add_port (midi_device)) == 0) {
37                 info << "MIDI port is not valid" << endmsg;
38                 return -1;
39         } 
40
41         mmc = new MachineControl (*port, 0.0, cs, rs);
42
43         return 0;
44 }
45
46 void
47 do_deferred_play (MachineControl &mmc)
48
49 {
50         cout << "Deferred Play" << endl;
51 }
52
53 void
54 do_stop (MachineControl &mmc)
55
56 {
57         cout << "Stop" << endl;
58 }
59
60 void
61 do_ffwd (MachineControl &mmc)
62
63 {
64         cout << "Fast Forward" << endl;
65 }
66
67 void
68 do_rewind (MachineControl &mmc)
69
70 {
71         cout << "Rewind" << endl;
72 }
73
74 void
75 do_record_status (MachineControl &mmc, size_t track, bool enabled)
76
77 {
78         cout << "Track " << track + 1 << (enabled ? " enabled" : " disabled")
79              << endl;
80 }
81
82 main (int argc, char *argv[])
83
84 {
85         byte buf[1];
86         
87         text_receiver.listen_to (error);
88         text_receiver.listen_to (info);
89         text_receiver.listen_to (fatal);
90         text_receiver.listen_to (warning);
91
92         if (setup_midi ()) {
93                 exit (1);
94         }
95
96
97         mmc->DeferredPlay.connect (mem_fun (do_deferred_play));
98         mmc->FastForward.connect (mem_fun (do_ffwd));
99         mmc->Rewind.connect (mem_fun (do_rewind));
100         mmc->Stop.connect (mem_fun (do_stop));
101         mmc->TrackRecordStatusChange.connect (mem_fun (do_record_status));
102
103         while (1) {
104                 if (port->read (buf, 1) < 0) {
105                         error << "cannot read byte"
106                               << endmsg;
107                         break;
108                 } 
109         }
110 }
111
112