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 <pbd/error.h>
26 #include <midi++/types.h>
27 #include <midi++/jack.h>
33 JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client)
35 , _jack_client(jack_client)
36 , _jack_input_port(NULL)
37 , _jack_output_port(NULL)
40 int err = create_ports (node);
47 JACK_MidiPort::~JACK_MidiPort()
53 JACK_MidiPort::cycle_start (nframes_t nframes)
55 Port::cycle_start(nframes);
56 assert(_nframes_this_cycle == nframes);
58 jack_midi_clear_buffer(jack_port_get_buffer(_jack_output_port, nframes));
62 JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp)
64 if (!_currently_in_cycle) {
65 error << "JACK MIDI write ignored - not in cycle ... FIX ME PAUL!" << endmsg;
68 assert(timestamp < _nframes_this_cycle);
69 assert(_jack_output_port);
71 // FIXME: return value correct?
72 return jack_midi_event_write (
73 jack_port_get_buffer(_jack_output_port, _nframes_this_cycle),
74 timestamp, msg, msglen);
78 JACK_MidiPort::read(byte * buf, size_t max, timestamp_t timestamp)
80 assert(_currently_in_cycle);
81 assert(timestamp < _nframes_this_cycle);
82 assert(_jack_input_port);
86 int err = jack_midi_event_get (&ev,
87 jack_port_get_buffer(_jack_input_port, _nframes_this_cycle),
91 memcpy(buf, ev.buffer, ev.size);
99 JACK_MidiPort::create_ports(const XMLNode& node)
101 Descriptor desc (node);
103 assert(!_jack_input_port);
104 assert(!_jack_output_port);
106 jack_nframes_t nframes = jack_get_buffer_size(_jack_client);
110 if (desc.mode == O_RDWR || desc.mode == O_WRONLY) {
111 _jack_output_port = jack_port_register(_jack_client,
112 string(desc.tag).append("_out").c_str(),
113 JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
114 jack_midi_clear_buffer(jack_port_get_buffer(_jack_output_port, nframes));
115 ret = ret && (_jack_output_port != NULL);
118 if (desc.mode == O_RDWR || desc.mode == O_RDONLY) {
119 _jack_input_port = jack_port_register(_jack_client,
120 string(desc.tag).append("_in").c_str(),
121 JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
122 jack_midi_clear_buffer(jack_port_get_buffer(_jack_input_port, nframes));
123 ret = ret && (_jack_input_port != NULL);
130 JACK_MidiPort::get_state () const
132 XMLNode& root (Port::get_state ());
137 JACK_MidiPort::set_state (const XMLNode& node)