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