Ardour  9.7-245-g303f7adf54
midi_port.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2007-2018 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include "midi++/parser.h"
25 
26 #include "ardour/port.h"
27 #include "ardour/midi_buffer.h"
28 
29 namespace ARDOUR {
30 
31 class MidiBuffer;
32 class MidiEngine;
33 class ScaleProvider;
34 
35 class LIBARDOUR_API MidiPort : public Port {
36  public:
38 
39  DataType type () const {
40  return DataType::MIDI;
41  }
42 
43  void cycle_start (pframes_t nframes);
44  void cycle_end (pframes_t nframes);
45  void cycle_split ();
46 
47  void flush_buffers (pframes_t nframes);
49  void realtime_locate (bool);
50  void reset ();
51  void require_resolve ();
52 
53  bool input_active() const { return _input_active; }
54  void set_input_active (bool yn);
55 
57  return get_midi_buffer (nframes);
58  }
59 
61 
62  void set_trace (std::weak_ptr<MIDI::Parser> trace_parser);
63  std::shared_ptr<MIDI::Parser> trace_parser() const;
64 
65  typedef std::function<bool(MidiBuffer&,MidiBuffer&)> MidiFilter;
67  int add_shadow_port (std::string const &, MidiFilter);
68  std::shared_ptr<MidiPort> shadow_port() const { return _shadow_port; }
69 
71 
72  PBD::Signal<void(int)> NoteOn;
73  PBD::Signal<void(int)> NoteOff;
74 
76 
78 
79 protected:
80  friend class PortManager;
81 
82  MidiPort (const std::string& name, PortFlags);
83 
84 private:
90  std::shared_ptr<MidiPort> _shadow_port;
92  std::weak_ptr<MIDI::Parser> _trace_parser;
94 
95  void resolve_notes (void* buffer, samplepos_t when);
96  void pull_input (pframes_t nframes, bool adjust_speed);
97  void parse_input (pframes_t nframes, MIDI::Parser& parser);
98 };
99 
100 } // namespace ARDOUR
101 
void realtime_locate(bool)
MidiFilter _inbound_midi_filter
Definition: midi_port.h:89
ScaleProvider * _scale_provider
Definition: midi_port.h:86
void cycle_end(pframes_t nframes)
std::shared_ptr< MIDI::Parser > trace_parser() const
MidiPort(const std::string &name, PortFlags)
void pull_input(pframes_t nframes, bool adjust_speed)
PBD::Signal< void(int)> NoteOn
Definition: midi_port.h:72
void set_inbound_filter(MidiFilter)
bool _input_active
Definition: midi_port.h:88
std::shared_ptr< MidiPort > shadow_port() const
Definition: midi_port.h:68
bool _data_fetched_for_cycle
Definition: midi_port.h:93
static bool sysex_midi_io_may_be_broken
Definition: midi_port.h:77
void set_trace(std::weak_ptr< MIDI::Parser > trace_parser)
int add_shadow_port(std::string const &, MidiFilter)
bool _resolve_required
Definition: midi_port.h:87
void transport_stopped()
PBD::Signal< void(int)> NoteOff
Definition: midi_port.h:73
void require_resolve()
bool input_active() const
Definition: midi_port.h:53
MidiFilter _shadow_midi_filter
Definition: midi_port.h:91
void resolve_notes(void *buffer, samplepos_t when)
MidiBuffer * _buffer
Definition: midi_port.h:85
void cycle_start(pframes_t nframes)
MidiBuffer & get_midi_buffer(pframes_t nframes)
std::function< bool(MidiBuffer &, MidiBuffer &)> MidiFilter
Definition: midi_port.h:65
std::weak_ptr< MIDI::Parser > _trace_parser
Definition: midi_port.h:92
Buffer & get_buffer(pframes_t nframes)
Definition: midi_port.h:56
void set_input_active(bool yn)
void parse_input(pframes_t nframes, MIDI::Parser &parser)
void flush_buffers(pframes_t nframes)
void read_and_parse_entire_midi_buffer_with_no_speed_adjustment(pframes_t nframes, MIDI::Parser &parser, samplepos_t now)
void set_scale_provider(ScaleProvider *)
DataType type() const
Definition: midi_port.h:39
std::shared_ptr< MidiPort > _shadow_port
Definition: midi_port.h:90
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplepos_t samplepos_t