summaryrefslogtreecommitdiff
path: root/libs/midi++2
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-06-09 01:48:38 +0000
committerDavid Robillard <d@drobilla.net>2006-06-09 01:48:38 +0000
commit2f4392f043fe174f798f0d2ca60dc37b2dd8ec7b (patch)
tree3291ee209671d0d49c4ec93080ba4167fda4e6aa /libs/midi++2
parent5905d4f7b6481b3c51fb4c5c687cd87b8361ab06 (diff)
Removed excessive debug printing, added missing files for SMPTE namespace and Jack libmidi++ ports
git-svn-id: svn://localhost/ardour2/branches/midi@577 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/midi++2')
-rw-r--r--libs/midi++2/jack_midiport.cc128
-rw-r--r--libs/midi++2/midi++/jack.h68
2 files changed, 196 insertions, 0 deletions
diff --git a/libs/midi++2/jack_midiport.cc b/libs/midi++2/jack_midiport.cc
new file mode 100644
index 0000000000..4fc24e8711
--- /dev/null
+++ b/libs/midi++2/jack_midiport.cc
@@ -0,0 +1,128 @@
+/*
+ Copyright (C) 2006 Paul Davis
+ Written by Dave Robillard
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id: alsa_sequencer_midiport.cc 244 2006-01-06 04:59:17Z essej $
+*/
+
+#include <fcntl.h>
+#include <cerrno>
+#include <cassert>
+
+#include <midi++/types.h>
+#include <midi++/jack.h>
+#include <midi++/port_request.h>
+
+using namespace std;
+using namespace MIDI;
+
+JACK_MidiPort::JACK_MidiPort(PortRequest & req, jack_client_t* jack_client)
+ : Port(req)
+ , _jack_client(jack_client)
+ , _jack_input_port(NULL)
+ , _jack_output_port(NULL)
+ , _last_read_index(0)
+{
+ int err = create_ports(req);
+
+ if (!err) {
+ req.status = PortRequest::OK;
+ _ok = true;
+ } else {
+ req.status = PortRequest::Unknown;
+ }
+}
+
+JACK_MidiPort::~JACK_MidiPort()
+{
+ // FIXME: remove port
+}
+
+void
+JACK_MidiPort::cycle_start (nframes_t nframes)
+{
+ Port::cycle_start(nframes);
+ assert(_nframes_this_cycle == nframes);
+ _last_read_index = 0;
+ jack_midi_clear_buffer(jack_port_get_buffer(_jack_output_port, nframes), nframes);
+}
+
+int
+JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp)
+{
+ assert(_currently_in_cycle);
+ assert(timestamp < _nframes_this_cycle);
+ assert(_jack_output_port);
+
+ // FIXME: return value correct?
+ return jack_midi_event_write (
+ jack_port_get_buffer(_jack_output_port, _nframes_this_cycle),
+ timestamp, msg, msglen, _nframes_this_cycle);
+}
+
+int
+JACK_MidiPort::read(byte * buf, size_t max, timestamp_t timestamp)
+{
+ assert(_currently_in_cycle);
+ assert(timestamp < _nframes_this_cycle);
+ assert(_jack_input_port);
+
+ jack_midi_event_t ev;
+
+ int err = jack_midi_event_get (&ev,
+ jack_port_get_buffer(_jack_input_port, _nframes_this_cycle),
+ _last_read_index++, _nframes_this_cycle);
+
+ if (!err) {
+ memcpy(buf, ev.buffer, ev.size);
+ return ev.size;
+ } else {
+ return 0;
+ }
+}
+
+int
+JACK_MidiPort::create_ports(PortRequest & req)
+{
+ assert(!_jack_input_port);
+ assert(!_jack_output_port);
+
+ jack_nframes_t nframes = jack_get_buffer_size(_jack_client);
+
+ bool ret = true;
+
+ if (req.mode == O_RDWR || req.mode == O_WRONLY) {
+ _jack_output_port = jack_port_register(_jack_client,
+ string(req.tagname).append("_out").c_str(),
+ JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
+ jack_midi_reset_new_port(
+ jack_port_get_buffer(_jack_output_port, nframes), nframes);
+ ret = ret && (_jack_output_port != NULL);
+ }
+
+ if (req.mode == O_RDWR || req.mode == O_RDONLY) {
+ _jack_input_port = jack_port_register(_jack_client,
+ string(req.tagname).append("_in").c_str(),
+ JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
+ jack_midi_reset_new_port(
+ jack_port_get_buffer(_jack_input_port, nframes), nframes);
+ ret = ret && (_jack_input_port != NULL);
+ }
+
+ return ret ? 0 : -1;
+}
+
diff --git a/libs/midi++2/midi++/jack.h b/libs/midi++2/midi++/jack.h
new file mode 100644
index 0000000000..c20b2693f1
--- /dev/null
+++ b/libs/midi++2/midi++/jack.h
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2006 Paul Davis
+ Written by Dave Robillard
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id: jack.h 4 2005-05-13 20:47:18Z taybin $
+*/
+
+#ifndef __jack_midiport_h__
+#define __jack_midiport_h__
+
+#include <vector>
+#include <string>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <jack/jack.h>
+#include <jack/midiport.h>
+#include <midi++/port.h>
+
+namespace MIDI
+{
+
+
+class JACK_MidiPort : public Port
+{
+public:
+ JACK_MidiPort (PortRequest &req, jack_client_t* jack_client);
+ virtual ~JACK_MidiPort ();
+
+ /* No select(2)/poll(2)-based I/O */
+ virtual int selectable() const { return -1; }
+
+ virtual void cycle_start(nframes_t nframes);
+
+protected:
+ /* Direct I/O */
+ int write(byte *msg, size_t msglen, timestamp_t timestamp);
+ int read(byte *buf, size_t max, timestamp_t timestamp);
+
+private:
+ int create_ports(PortRequest &req);
+
+ jack_client_t* _jack_client;
+ jack_port_t* _jack_input_port;
+ jack_port_t* _jack_output_port;
+ nframes_t _last_read_index;
+};
+
+
+} /* namespace MIDI */
+
+#endif // __jack_midiport_h__
+