Ardour  9.0-pre0-582-g084a23a80d
smf_source.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2008-2009 Hans Baier <hansfbaier@googlemail.com>
5  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
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 <cstdio>
26 #include <time.h>
27 #include "evoral/SMF.h"
28 #include "ardour/midi_source.h"
29 #include "ardour/file_source.h"
30 
31 namespace Evoral { template<typename T> class Event; }
32 
33 namespace ARDOUR {
34 
35 template<typename T> class MidiRingBuffer;
36 
38 class LIBARDOUR_API SMFSource : public MidiSource, public FileSource, public Evoral::SMF {
39 public:
41  SMFSource (Session& session, const std::string& path, Source::Flag flags);
42 
44  SMFSource (Session& session, const std::string& path);
45 
47  SMFSource (Session& session, const XMLNode&, bool must_exist = false);
48 
49  virtual ~SMFSource ();
50 
51  bool safe_file_extension (const std::string& path) const {
52  return safe_midi_file_extension(path);
53  }
54 
56  void append_event_samples (const WriterLock& lock, const Evoral::Event<samplepos_t>& ev, samplepos_t source_start);
57 
58  void update_length (timepos_t const & dur);
59 
61 
62  void mark_streaming_write_completed (const WriterLock& lock, Temporal::timecnt_t const & duration);
65  Temporal::timecnt_t const & duration);
66 
67  XMLNode& get_state () const;
68  int set_state (const XMLNode&, int version);
69 
70  void load_model (const WriterLock& lock, bool force_reload=false);
71  void destroy_model (const WriterLock& lock);
72 
73  static bool safe_midi_file_extension (const std::string& path);
74  static bool valid_midi_file (const std::string& path);
75 
77  void set_path (const std::string& newpath);
78 
80  SMF::UsedChannels used_midi_channels();
81 
83 
85 
86  protected:
87  void close ();
88  void flush_midi (const WriterLock& lock);
89 
90  private:
91  bool _open;
98 
100 
101  void ensure_disk_file (const WriterLock& lock);
102 
105  timepos_t const & position,
106  timepos_t const & start,
107  timecnt_t const & cnt,
108  Temporal::Range* loop_range,
109  MidiNoteTracker* tracker,
110  MidiChannelFilter* filter) const;
111 
114  timepos_t const & position,
115  timecnt_t const & cnt);
116 
117  void load_model_unlocked (bool force_reload=false);
118 
119 };
120 
121 }; /* namespace ARDOUR */
122 
void destroy_model(const WriterLock &lock)
static bool valid_midi_file(const std::string &path)
void ensure_disk_file(const WriterLock &lock)
SMF::UsedChannels used_midi_channels()
virtual ~SMFSource()
void set_path(const std::string &newpath)
XMLNode & get_state() const
Temporal::Beats duration() const
Temporal::Beats _last_ev_time_beats
Definition: smf_source.h:92
void append_event_samples(const WriterLock &lock, const Evoral::Event< samplepos_t > &ev, samplepos_t source_start)
static bool safe_midi_file_extension(const std::string &path)
samplepos_t _last_ev_time_samples
Definition: smf_source.h:93
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
timecnt_t write_unlocked(const WriterLock &lock, MidiRingBuffer< samplepos_t > &src, timepos_t const &position, timecnt_t const &cnt)
void mark_streaming_midi_write_started(const WriterLock &lock, NoteMode mode)
SMFSource(Session &session, const std::string &path, Source::Flag flags)
SMFSource(Session &session, const std::string &path)
void mark_midi_streaming_write_completed(const WriterLock &lock, Evoral::Sequence< Temporal::Beats >::StuckNoteOption, Temporal::timecnt_t const &duration)
bool safe_file_extension(const std::string &path) const
Definition: smf_source.h:51
void render(const ReaderLock &lock, Evoral::EventSink< Temporal::Beats > &dst)
int set_state(const XMLNode &, int version)
SMFSource(Session &session, const XMLNode &, bool must_exist=false)
timepos_t _smf_last_read_time
Definition: smf_source.h:97
void append_event_beats(const WriterLock &lock, const Evoral::Event< Temporal::Beats > &ev)
void load_model(const WriterLock &lock, bool force_reload=false)
timepos_t _smf_last_read_end
Definition: smf_source.h:95
void mark_streaming_write_completed(const WriterLock &lock, Temporal::timecnt_t const &duration)
void load_model_unlocked(bool force_reload=false)
void update_length(timepos_t const &dur)
void flush_midi(const WriterLock &lock)
Glib::Threads::RWLock::ReaderLock ReaderLock
Glib::Threads::RWLock::WriterLock WriterLock
Definition: xml++.h:114
#define LIBARDOUR_API
void session(lua_State *L)
PBD::PropertyDescriptor< timepos_t > start
Temporal::samplepos_t samplepos_t
Definition: editor.h:86
DebugBits MidiRingBuffer