2 Copyright (C) 1998-2010 Paul Barton-Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __libmidi_port_h__
20 #define __libmidi_port_h__
25 #include <jack/types.h>
27 #include "pbd/xml++.h"
28 #include "pbd/crossthread.h"
29 #include "pbd/signals.h"
30 #include "pbd/ringbuffer.h"
32 #include "evoral/Event.hpp"
33 #include "evoral/EventRingBuffer.hpp"
35 #include "midi++/types.h"
36 #include "midi++/parser.h"
37 #include "midi++/port_base.h"
44 class Port : public PortBase {
46 Port (std::string const &, PortBase::Flags, jack_client_t *);
47 Port (const XMLNode&, jack_client_t *);
50 XMLNode& get_state () const;
51 void set_state (const XMLNode&);
53 void cycle_start (pframes_t nframes);
56 void parse (framecnt_t timestamp);
57 int write (byte *msg, size_t msglen, timestamp_t timestamp);
58 int read (byte *buf, size_t bufsize);
59 void drain (int check_interval_usecs);
60 int selectable () const { return xthread.selectable(); }
62 pframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
64 void reestablish (jack_client_t *);
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 static PBD::Signal0<void> MakeConnections;
72 static PBD::Signal0<void> JackHalted;
75 bool _currently_in_cycle;
76 pframes_t _nframes_this_cycle;
77 jack_client_t* _jack_client;
78 jack_port_t* _jack_port;
79 timestamp_t _last_write_timestamp;
80 RingBuffer< Evoral::Event<double> > output_fifo;
81 Evoral::EventRingBuffer<timestamp_t> input_fifo;
82 Glib::Mutex output_fifo_lock;
83 CrossThreadChannel xthread;
87 /** Channel used to signal to the MidiControlUI that input has arrived */
89 std::string _connections;
90 PBD::ScopedConnection connect_connection;
91 PBD::ScopedConnection halt_connection;
92 void flush (void* jack_port_buffer);
94 void make_connections ();
95 void init (std::string const &, Flags);
97 static pthread_t _process_thread;
103 #endif // __libmidi_port_h__