Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
21 
22 #include <string>
23 #include <iostream>
24 
25 
26 #include "pbd/xml++.h"
27 #include "pbd/crossthread.h"
28 #include "pbd/signals.h"
29 #include "pbd/ringbuffer.h"
30 
31 #include "evoral/Event.h"
32 
33 #include "midi++/types.h"
34 #include "midi++/parser.h"
35 #include "midi++/port.h"
36 
39 #include "ardour/midi_port.h"
40 
41 namespace ARDOUR {
42 
44 
45  public:
46  AsyncMIDIPort (std::string const &, PortFlags);
48 
49  bool flush_at_cycle_start () const { return _flush_at_cycle_start; }
50  void set_flush_at_cycle_start (bool en) { _flush_at_cycle_start = en; }
51 
52  /* called from an RT context */
53  void cycle_start (pframes_t nframes);
54  void cycle_end (pframes_t nframes);
55 
56  /* called from non-RT context */
57  void parse (samplecnt_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, int total_usecs_to_wait);
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 (std::function<samplecnt_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:
84  bool have_timer;
85  std::function<samplecnt_t (void)> timer;
88  Glib::Threads::Mutex output_fifo_lock;
90 
91  int create_port ();
92 
95  std::string _connections;
98  void jack_halted ();
100  void init (std::string const &, Flags);
101 
103 
104  static pthread_t _process_thread;
105 };
106 
107 } // namespace ARDOUR
108 
void parse(samplecnt_t timestamp)
int write(const MIDI::byte *msg, size_t msglen, MIDI::timestamp_t timestamp)
void set_timer(std::function< samplecnt_t(void)> &)
std::function< samplecnt_t(void)> timer
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
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
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