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.
19 $Id: jack.h 4 2005-05-13 20:47:18Z taybin $
22 #ifndef __jack_midiport_h__
23 #define __jack_midiport_h__
31 #include <glibmm/thread.h>
33 #include <jack/jack.h>
34 #include <jack/midiport.h>
36 #include "pbd/ringbuffer.h"
37 #include "pbd/signals.h"
38 #include "pbd/crossthread.h"
39 #include "evoral/EventRingBuffer.hpp"
41 #include "midi++/port.h"
42 #include "midi++/event.h"
47 class JACK_MidiPort : public Port
50 JACK_MidiPort (const XMLNode& node, jack_client_t* jack_client);
51 virtual ~JACK_MidiPort ();
53 int write(byte *msg, size_t msglen, timestamp_t timestamp);
54 int read(byte *buf, size_t max);
56 int selectable() const { return xthread.selectable(); }
57 bool must_drain_selectable() const { return true; }
59 void cycle_start(nframes_t nframes);
62 static std::string typestring;
64 XMLNode& get_state () const;
65 void set_state (const XMLNode&);
67 static void set_process_thread (pthread_t);
68 static pthread_t get_process_thread () { return _process_thread; }
69 static bool is_process_thread();
71 nframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
73 static PBD::Signal0<void> MakeConnections;
74 static PBD::Signal0<void> JackHalted;
77 std::string get_typestring () const {
82 int create_ports(const XMLNode&);
84 jack_client_t* _jack_client;
85 jack_port_t* _jack_input_port;
86 jack_port_t* _jack_output_port;
87 nframes_t _last_read_index;
88 timestamp_t _last_write_timestamp;
89 CrossThreadChannel xthread;
90 std::string _inbound_connections;
91 std::string _outbound_connections;
92 PBD::ScopedConnection connect_connection;
93 PBD::ScopedConnection halt_connection;
94 void flush (void* jack_port_buffer);
96 void make_connections();
98 static pthread_t _process_thread;
100 RingBuffer< Evoral::Event<double> > output_fifo;
101 Evoral::EventRingBuffer<timestamp_t> input_fifo;
103 Glib::Mutex output_fifo_lock;
107 } /* namespace MIDI */
109 #endif // __jack_midiport_h__