Ardour  8.12
async_midi_port.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __libardour_async_midiport_h__
21 #define __libardour_async_midiport_h__
22 
23 #include <string>
24 #include <iostream>
25 
26 #include <boost/function.hpp>
27 
28 #include "pbd/xml++.h"
29 #include "pbd/crossthread.h"
30 #include "pbd/signals.h"
31 #include "pbd/ringbuffer.h"
32 
33 #include "evoral/Event.h"
34 
35 #include "midi++/types.h"
36 #include "midi++/parser.h"
37 #include "midi++/port.h"
38 
41 #include "ardour/midi_port.h"
42 
43 namespace ARDOUR {
44 
46 
47  public:
48  AsyncMIDIPort (std::string const &, PortFlags);
50 
51  bool flush_at_cycle_start () const { return _flush_at_cycle_start; }
52  void set_flush_at_cycle_start (bool en) { _flush_at_cycle_start = en; }
53 
54  /* called from an RT context */
55  void cycle_start (pframes_t nframes);
56  void cycle_end (pframes_t nframes);
57 
58  /* called from non-RT context */
59  void parse (samplecnt_t timestamp);
60  int write (const MIDI::byte *msg, size_t msglen, MIDI::timestamp_t timestamp);
61  int read (MIDI::byte *buf, size_t bufsize);
62  /* waits for output to be cleared */
63  void drain (int check_interval_usecs, int total_usecs_to_wait);
64 
65  /* clears async request communication channel */
66  void clear () {
67  _xthread.drain ();
68  }
69 
71  return _xthread;
72  }
73 
74  /* Not selectable; use ios() */
75  int selectable() const { return -1; }
76  void set_timer (boost::function<samplecnt_t (void)>&);
77 
78  static void set_process_thread (pthread_t);
79  static pthread_t get_process_thread () { return _process_thread; }
80  static bool is_process_thread();
81 
82  private:
86  bool have_timer;
87  boost::function<samplecnt_t (void)> timer;
90  Glib::Threads::Mutex output_fifo_lock;
92 
93  int create_port ();
94 
97  std::string _connections;
100  void jack_halted ();
102  void init (std::string const &, Flags);
103 
105 
106  static pthread_t _process_thread;
107 };
108 
109 } // namespace ARDOUR
110 
111 #endif /* __libardour_async_midiport_h__ */
void parse(samplecnt_t timestamp)
int write(const MIDI::byte *msg, size_t msglen, MIDI::timestamp_t timestamp)
int read(MIDI::byte *buf, size_t bufsize)
static bool is_process_thread()
void set_flush_at_cycle_start(bool en)
static pthread_t _process_thread
void cycle_start(pframes_t nframes)
void flush_output_fifo(pframes_t)
PBD::ScopedConnection connect_connection
void cycle_end(pframes_t nframes)
AsyncMIDIPort(std::string const &, PortFlags)
PBD::ScopedConnection halt_connection
boost::function< samplecnt_t(void)> timer
static pthread_t get_process_thread()
Glib::Threads::Mutex output_fifo_lock
bool flush_at_cycle_start() const
PBD::RingBuffer< Evoral::Event< double > > output_fifo
void init(std::string const &, Flags)
MIDI::timestamp_t _last_write_timestamp
void drain(int check_interval_usecs, int total_usecs_to_wait)
CrossThreadChannel & xthread()
CrossThreadChannel _xthread
void set_timer(boost::function< samplecnt_t(void)> &)
EventRingBuffer< MIDI::timestamp_t > input_fifo
static void set_process_thread(pthread_t)
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
uint32_t timestamp_t