ardour
async_midi_port.h
Go to the documentation of this file.
1 /*
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.
7 
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.
12 
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.
16 
17 */
18 
19 #ifndef __libardour_async_midiport_h__
20 #define __libardour_async_midiport_h__
21 
22 #include <string>
23 #include <iostream>
24 
25 #include <boost/function.hpp>
26 
27 #include "pbd/xml++.h"
28 #include "pbd/crossthread.h"
29 #include "pbd/signals.h"
30 #include "pbd/ringbuffer.h"
31 
32 #include "evoral/Event.hpp"
33 
34 #include "midi++/types.h"
35 #include "midi++/parser.h"
36 #include "midi++/port.h"
37 
40 #include "ardour/midi_port.h"
41 
42 namespace ARDOUR {
43 
44 class LIBARDOUR_API AsyncMIDIPort : public ARDOUR::MidiPort, public MIDI::Port {
45 
46  public:
47  AsyncMIDIPort (std::string const &, PortFlags);
48  ~AsyncMIDIPort ();
49 
50  /* called from an RT context */
51 
52  void cycle_start (pframes_t nframes);
53  void cycle_end (pframes_t nframes);
54 
55  /* called from non-RT context */
56 
57  void parse (framecnt_t timestamp);
58  int write (const MIDI::byte *msg, size_t msglen, MIDI::timestamp_t timestamp);
59  int read (MIDI::byte *buf, size_t bufsize);
60  /* waits for output to be cleared */
61  void drain (int check_interval_usecs);
62 
63  /* clears async request communication channel */
64  void clear () {
65  _xthread.drain ();
66  }
67 
69  return _xthread;
70  }
71 
72  /* Not selectable; use ios() */
73  int selectable() const { return -1; }
74  void set_timer (boost::function<framecnt_t (void)>&);
75 
76  static void set_process_thread (pthread_t);
77  static pthread_t get_process_thread () { return _process_thread; }
78  static bool is_process_thread();
79 
80  private:
82  MIDI::timestamp_t _last_write_timestamp;
83  bool have_timer;
84  boost::function<framecnt_t (void)> timer;
87  Glib::Threads::Mutex output_fifo_lock;
89 
90  int create_port ();
91 
94  std::string _connections;
97  void flush (void* jack_port_buffer);
98  void jack_halted ();
99  void make_connections ();
100  void init (std::string const &, Flags);
101 
102  void flush_output_fifo (pframes_t);
103 
104  static pthread_t _process_thread;
105 };
106 
107 } // namespace ARDOUR
108 
109 #endif /* __libardour_async_midiport_h__ */
RingBuffer< Evoral::Event< double > > output_fifo
boost::function< framecnt_t(void)> timer
EventRingBuffer< MIDI::timestamp_t > input_fifo
Glib::Threads::Mutex output_fifo_lock
uint32_t pframes_t
Definition: types.h:61
static pthread_t _process_thread
PBD::ScopedConnection connect_connection
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
PortFlags
Definition: types.h:610
#define LIBARDOUR_API
static pthread_t get_process_thread()
MIDI::timestamp_t _last_write_timestamp
CrossThreadChannel & xthread()
PBD::ScopedConnection halt_connection
LIBARDOUR_API bool init(bool with_vst, bool try_optimization, const char *localedir)
Definition: globals.cc:376
CrossThreadChannel _xthread