2 Copyright (C) 2006 Paul Davis
3 Written by Dave Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <midi++/types.h>
25 #include <midi++/jack.h>
30 JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client)
32 , _jack_client(jack_client)
33 , _jack_input_port(NULL)
34 , _jack_output_port(NULL)
37 int err = create_ports (node);
44 JACK_MidiPort::~JACK_MidiPort()
50 JACK_MidiPort::cycle_start (nframes_t nframes)
52 Port::cycle_start(nframes);
53 assert(_nframes_this_cycle == nframes);
55 jack_midi_clear_buffer(jack_port_get_buffer(_jack_output_port, nframes));
59 JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp)
61 assert(_currently_in_cycle);
62 assert(timestamp < _nframes_this_cycle);
63 assert(_jack_output_port);
65 // FIXME: return value correct?
66 return jack_midi_event_write (
67 jack_port_get_buffer(_jack_output_port, _nframes_this_cycle),
68 timestamp, msg, msglen);
72 JACK_MidiPort::read(byte * buf, size_t max, timestamp_t timestamp)
74 assert(_currently_in_cycle);
75 assert(timestamp < _nframes_this_cycle);
76 assert(_jack_input_port);
80 int err = jack_midi_event_get (&ev,
81 jack_port_get_buffer(_jack_input_port, _nframes_this_cycle),
85 memcpy(buf, ev.buffer, ev.size);
93 JACK_MidiPort::create_ports(const XMLNode& node)
95 Descriptor desc (node);
97 assert(!_jack_input_port);
98 assert(!_jack_output_port);
100 jack_nframes_t nframes = jack_get_buffer_size(_jack_client);
104 if (desc.mode == O_RDWR || desc.mode == O_WRONLY) {
105 _jack_output_port = jack_port_register(_jack_client,
106 string(desc.tag).append("_out").c_str(),
107 JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
108 jack_midi_clear_buffer(jack_port_get_buffer(_jack_output_port, nframes));
109 ret = ret && (_jack_output_port != NULL);
112 if (desc.mode == O_RDWR || desc.mode == O_RDONLY) {
113 _jack_input_port = jack_port_register(_jack_client,
114 string(desc.tag).append("_in").c_str(),
115 JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
116 jack_midi_clear_buffer(jack_port_get_buffer(_jack_input_port, nframes));
117 ret = ret && (_jack_input_port != NULL);
124 JACK_MidiPort::get_state () const
126 XMLNode& root (Port::get_state ());
131 JACK_MidiPort::set_state (const XMLNode& node)