second (and hopefully) final part of changes to respond to header format changes...
[ArdourMidi.git] / libs / midi++2 / mmctest.cc
blob527e1491eac295f16bd0af9ddbbbec3b77fe0b71
1 #include <cstdio>
2 #include <fcntl.h>
4 #include "pbd/error.h"
5 #include "pbd/textreceiver.h"
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");
13 #include "midi++/port.h"
14 #include "midi++/manager.h"
15 #include "midi++/mmc.h"
17 using namespace MIDI;
18 using namespace PBD;
20 Port *port;
21 PortRequest midi_device;
22 Parser *parser;
23 MachineControl *mmc;
24 MachineControl::CommandSignature cs;
25 MachineControl::ResponseSignature rs;
27 int
28 setup_midi ()
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;
36 if ((port = MIDI::Manager::instance()->add_port (midi_device)) == 0) {
37 info << "MIDI port is not valid" << endmsg;
38 return -1;
41 mmc = new MachineControl (*port, 0.0, cs, rs);
43 return 0;
46 void
47 do_deferred_play (MachineControl &mmc)
50 cout << "Deferred Play" << endl;
53 void
54 do_stop (MachineControl &mmc)
57 cout << "Stop" << endl;
60 void
61 do_ffwd (MachineControl &mmc)
64 cout << "Fast Forward" << endl;
67 void
68 do_rewind (MachineControl &mmc)
71 cout << "Rewind" << endl;
74 void
75 do_record_status (MachineControl &mmc, size_t track, bool enabled)
78 cout << "Track " << track + 1 << (enabled ? " enabled" : " disabled")
79 << endl;
82 main (int argc, char *argv[])
85 byte buf[1];
87 text_receiver.listen_to (error);
88 text_receiver.listen_to (info);
89 text_receiver.listen_to (fatal);
90 text_receiver.listen_to (warning);
92 if (setup_midi ()) {
93 exit (1);
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));
103 while (1) {
104 if (port->read (buf, 1) < 0) {
105 error << "cannot read byte"
106 << endmsg;
107 break;