Ardour  9.0-pre0-582-g084a23a80d
midi_source.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2016 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2016 Nick Mainsbridge <mainsbridge@gmail.com>
6  * Copyright (C) 2018-2019 Ben Loftis <ben@harrisonconsoles.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
25 #include <string>
26 #include <time.h>
27 #include <glibmm/threads.h>
28 
29 #include "pbd/stateful.h"
30 #include "pbd/xml++.h"
31 
32 #include "evoral/Sequence.h"
33 
34 #include "temporal/range.h"
35 
36 #include "ardour/ardour.h"
37 #include "ardour/automation_list.h"
38 #include "ardour/buffer.h"
39 #include "ardour/midi_cursor.h"
40 #include "ardour/source.h"
41 
42 namespace ARDOUR {
43 
44 class MidiChannelFilter;
45 class MidiModel;
46 class MidiNoteTracker;
47 
48 template<typename T> class MidiRingBuffer;
49 
51 class LIBARDOUR_API MidiSource : virtual public Source
52 {
53  public:
55 
56  MidiSource (Session& session, std::string name, Source::Flag flags = Source::Flag(0));
58  virtual ~MidiSource ();
59 
69  int write_to (const ReaderLock& lock,
70  std::shared_ptr<MidiSource> newsrc,
73 
83  int export_write_to (const ReaderLock& lock,
84  std::shared_ptr<MidiSource> newsrc,
85  Temporal::Beats begin,
86  Temporal::Beats end);
87 
101  virtual timecnt_t midi_read (const ReaderLock& lock,
103  timepos_t const & source_start,
104  timepos_t const & start,
105  timecnt_t const & cnt,
106  Temporal::Range* loop_range,
107  MidiCursor& cursor,
108  MidiNoteTracker* tracker,
109  MidiChannelFilter* filter,
110  const std::set<Evoral::Parameter>& filtered);
111  virtual void render (const ReaderLock& lock, Evoral::EventSink<Temporal::Beats>& dst) = 0;
112 
119  virtual timecnt_t midi_write (const WriterLock& lock,
121  timepos_t const & source_start,
122  timecnt_t const & cnt);
123 
128  virtual void append_event_beats(const WriterLock& lock,
129  const Evoral::Event<Temporal::Beats>& ev) = 0;
130 
135  virtual void append_event_samples(const WriterLock& lock,
136  const Evoral::Event<samplepos_t>& ev,
137  samplepos_t source_start) = 0;
138 
139  virtual void mark_streaming_midi_write_started (const WriterLock& lock, NoteMode mode);
140  virtual void mark_streaming_write_started (const WriterLock& lock);
141  virtual void mark_streaming_write_completed (const WriterLock& lock, Temporal::timecnt_t const & duration);
142 
153  void mark_write_starting_now (timepos_t const & position, samplecnt_t capture_length);
154 
155  /* like ::mark_streaming_write_completed() but with more arguments to
156  * allow control over MIDI-specific behaviour. Expected to be used only
157  * when recording actual MIDI input, rather then when importing files
158  * etc.
159  */
161  const WriterLock& lock,
163  Temporal::timecnt_t const & when);
164 
165  virtual void session_saved();
166 
167  XMLNode& get_state () const;
168  int set_state (const XMLNode&, int version);
169 
170  bool length_mutable() const { return true; }
171 
172  virtual void load_model(const WriterLock& lock, bool force_reload=false) = 0;
173  virtual void destroy_model(const WriterLock& lock) = 0;
174 
178  void invalidate(const WriterLock& lock);
179 
181  mutable PBD::Signal<void(bool)> Invalidated;
182 
183  void set_note_mode(const WriterLock& lock, NoteMode mode);
184 
185  std::shared_ptr<MidiModel> model() { return _model; }
186  void set_model(const WriterLock& lock, std::shared_ptr<MidiModel>);
187  void drop_model(const WriterLock& lock);
188 
191  void copy_interpolation_from (std::shared_ptr<MidiSource>);
193 
196  void copy_automation_state_from (std::shared_ptr<MidiSource>);
198 
205 
206  protected:
207  virtual void flush_midi(const WriterLock& lock) = 0;
208 
209  virtual timecnt_t read_unlocked (const ReaderLock& lock,
211  timepos_t const & position,
212  timepos_t const & start,
213  timecnt_t const & cnt,
214  Temporal::Range* loop_range,
215  MidiNoteTracker* tracker,
216  MidiChannelFilter* filter) const = 0;
217 
224  virtual timecnt_t write_unlocked (const WriterLock& lock,
226  timepos_t const & position,
227  timecnt_t const & cnt) = 0;
228 
229  std::shared_ptr<MidiModel> _model;
230  bool _writing;
231 
234 
238  typedef std::map<Evoral::Parameter, AutomationList::InterpolationStyle> InterpolationStyleMap;
240 
244  typedef std::map<Evoral::Parameter, AutoState> AutomationStateMap;
246 };
247 
248 }
249 
virtual timecnt_t read_unlocked(const ReaderLock &lock, Evoral::EventSink< samplepos_t > &dst, timepos_t const &position, timepos_t const &start, timecnt_t const &cnt, Temporal::Range *loop_range, MidiNoteTracker *tracker, MidiChannelFilter *filter) const =0
AutoState automation_state_of(Evoral::Parameter const &) const
InterpolationStyleMap _interpolation_style
Definition: midi_source.h:239
PBD::Signal< void()> ModelChanged
Definition: midi_source.h:200
PBD::Signal< void(Evoral::Parameter, AutoState)> AutomationStateChanged
Definition: midi_source.h:204
virtual ~MidiSource()
virtual void mark_midi_streaming_write_completed(const WriterLock &lock, Evoral::Sequence< Temporal::Beats >::StuckNoteOption stuck_option, Temporal::timecnt_t const &when)
samplecnt_t _capture_length
Definition: midi_source.h:233
std::shared_ptr< MidiModel > model()
Definition: midi_source.h:185
virtual timecnt_t midi_read(const ReaderLock &lock, Evoral::EventSink< samplepos_t > &dst, timepos_t const &source_start, timepos_t const &start, timecnt_t const &cnt, Temporal::Range *loop_range, MidiCursor &cursor, MidiNoteTracker *tracker, MidiChannelFilter *filter, const std::set< Evoral::Parameter > &filtered)
void copy_interpolation_from(std::shared_ptr< MidiSource >)
bool length_mutable() const
Definition: midi_source.h:170
virtual void mark_streaming_write_started(const WriterLock &lock)
std::map< Evoral::Parameter, AutoState > AutomationStateMap
Definition: midi_source.h:244
XMLNode & get_state() const
void set_interpolation_of(Evoral::Parameter const &, AutomationList::InterpolationStyle)
virtual void load_model(const WriterLock &lock, bool force_reload=false)=0
virtual void append_event_samples(const WriterLock &lock, const Evoral::Event< samplepos_t > &ev, samplepos_t source_start)=0
void copy_interpolation_from(MidiSource *)
virtual void append_event_beats(const WriterLock &lock, const Evoral::Event< Temporal::Beats > &ev)=0
PBD::Signal< void(bool)> Invalidated
Definition: midi_source.h:181
virtual void mark_streaming_midi_write_started(const WriterLock &lock, NoteMode mode)
virtual void mark_streaming_write_completed(const WriterLock &lock, Temporal::timecnt_t const &duration)
void set_model(const WriterLock &lock, std::shared_ptr< MidiModel >)
std::map< Evoral::Parameter, AutomationList::InterpolationStyle > InterpolationStyleMap
Definition: midi_source.h:238
AutomationList::InterpolationStyle interpolation_of(Evoral::Parameter const &) const
void copy_automation_state_from(std::shared_ptr< MidiSource >)
Temporal::Beats TimeType
Definition: midi_source.h:54
virtual void render(const ReaderLock &lock, Evoral::EventSink< Temporal::Beats > &dst)=0
virtual timecnt_t midi_write(const WriterLock &lock, MidiRingBuffer< samplepos_t > &source, timepos_t const &source_start, timecnt_t const &cnt)
virtual timecnt_t write_unlocked(const WriterLock &lock, MidiRingBuffer< samplepos_t > &source, timepos_t const &position, timecnt_t const &cnt)=0
int write_to(const ReaderLock &lock, std::shared_ptr< MidiSource > newsrc, Temporal::Beats begin=Temporal::Beats(), Temporal::Beats end=std::numeric_limits< Temporal::Beats >::max())
int export_write_to(const ReaderLock &lock, std::shared_ptr< MidiSource > newsrc, Temporal::Beats begin, Temporal::Beats end)
virtual void destroy_model(const WriterLock &lock)=0
PBD::Signal< void(Evoral::Parameter, AutomationList::InterpolationStyle)> InterpolationChanged
Definition: midi_source.h:202
MidiSource(Session &session, const XMLNode &)
virtual void flush_midi(const WriterLock &lock)=0
void drop_model(const WriterLock &lock)
void copy_automation_state_from(MidiSource *)
MidiSource(Session &session, std::string name, Source::Flag flags=Source::Flag(0))
std::shared_ptr< MidiModel > _model
Definition: midi_source.h:229
void set_note_mode(const WriterLock &lock, NoteMode mode)
void mark_write_starting_now(timepos_t const &position, samplecnt_t capture_length)
void set_automation_state_of(Evoral::Parameter const &, AutoState)
void invalidate(const WriterLock &lock)
virtual void session_saved()
int set_state(const XMLNode &, int version)
AutomationStateMap _automation_state
Definition: midi_source.h:245
Glib::Threads::RWLock::ReaderLock ReaderLock
Glib::Threads::RWLock::WriterLock WriterLock
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
void session(lua_State *L)
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t
DebugBits MidiRingBuffer
static Temporal::Beats max()
Definition: beats.h:300