Merge branch 'master' into saveas
[ardour.git] / libs / midi++2 / miditrace.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
35 using namespace MIDI;
36
37 Port *port;
38 PortRequest midi_device;
39
40 int 
41 setup_midi ()
42
43 {
44         midi_device.devname = "/dev/snd/midiC0D0";
45         midi_device.tagname = "trident";
46         midi_device.mode = O_RDWR;
47         midi_device.type = Port::ALSA_RawMidi;
48
49         if ((port = MIDI::Manager::instance()->add_port (midi_device)) == 0) {
50                 info << "MIDI port is not valid" << endmsg;
51                 return -1;
52         } 
53
54         return 0;
55 }
56
57 main (int argc, char *argv[]) 
58
59 {
60         byte buf[1];
61         
62         text_receiver.listen_to (error);
63         text_receiver.listen_to (info);
64         text_receiver.listen_to (fatal);
65         text_receiver.listen_to (warning);
66
67         if (setup_midi ()) {
68                 exit (1);
69         }
70
71         port->input()->trace (true, &cout);
72
73         while (1) {
74                 if (port->read (buf, 1) < 0) {
75                         error << "cannot read byte"
76                               << endmsg;
77                         break;
78                 } 
79         }
80 }
81
82