Remove bogus test and noisy output.
[ardour.git] / libs / midi++2 / mmctest.cc
1 /*
2     Copyright (C) 2012 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cstdio>
21 #include <fcntl.h>
22
23 #include "pbd/error.h"
24 #include "pbd/textreceiver.h"
25
26 Transmitter error (Transmitter::Error);
27 Transmitter info (Transmitter::Info);
28 Transmitter warning (Transmitter::Warning);
29 Transmitter fatal (Transmitter::Fatal);
30 TextReceiver text_receiver ("mmctest");
31
32 #include "midi++/port.h"
33 #include "midi++/manager.h"
34 #include "midi++/mmc.h"
35
36 using namespace MIDI;
37 using namespace PBD;
38
39 Port *port;
40 PortRequest midi_device;
41 Parser *parser;
42 MachineControl *mmc;
43 MachineControl::CommandSignature cs;
44 MachineControl::ResponseSignature rs;
45
46 int 
47 setup_midi ()
48
49 {
50         midi_device.devname = "/dev/snd/midiC0D0";
51         midi_device.tagname = "trident";
52         midi_device.mode = O_RDWR;
53         midi_device.type = Port::ALSA_RawMidi;
54
55         if ((port = MIDI::Manager::instance()->add_port (midi_device)) == 0) {
56                 info << "MIDI port is not valid" << endmsg;
57                 return -1;
58         } 
59
60         mmc = new MachineControl (*port, 0.0, cs, rs);
61
62         return 0;
63 }
64
65 void
66 do_deferred_play (MachineControl &mmc)
67
68 {
69         cout << "Deferred Play" << endl;
70 }
71
72 void
73 do_stop (MachineControl &mmc)
74
75 {
76         cout << "Stop" << endl;
77 }
78
79 void
80 do_ffwd (MachineControl &mmc)
81
82 {
83         cout << "Fast Forward" << endl;
84 }
85
86 void
87 do_rewind (MachineControl &mmc)
88
89 {
90         cout << "Rewind" << endl;
91 }
92
93 void
94 do_record_status (MachineControl &mmc, size_t track, bool enabled)
95
96 {
97         cout << "Track " << track + 1 << (enabled ? " enabled" : " disabled")
98              << endl;
99 }
100
101 main (int argc, char *argv[])
102
103 {
104         byte buf[1];
105         
106         text_receiver.listen_to (error);
107         text_receiver.listen_to (info);
108         text_receiver.listen_to (fatal);
109         text_receiver.listen_to (warning);
110
111         if (setup_midi ()) {
112                 exit (1);
113         }
114
115
116         mmc->DeferredPlay.connect (mem_fun (do_deferred_play));
117         mmc->FastForward.connect (mem_fun (do_ffwd));
118         mmc->Rewind.connect (mem_fun (do_rewind));
119         mmc->Stop.connect (mem_fun (do_stop));
120         mmc->TrackRecordStatusChange.connect (mem_fun (do_record_status));
121
122         while (1) {
123                 if (port->read (buf, 1) < 0) {
124                         error << "cannot read byte"
125                               << endmsg;
126                         break;
127                 } 
128         }
129 }
130
131