ardour
smf_source.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Paul Davis
3  Author: David Robillard
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
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #ifndef __ardour_smf_source_h__
22 #define __ardour_smf_source_h__
23 
24 #include <cstdio>
25 #include <time.h>
26 #include "evoral/SMF.hpp"
27 #include "ardour/midi_source.h"
28 #include "ardour/file_source.h"
29 
30 namespace Evoral { template<typename T> class Event; }
31 
32 namespace ARDOUR {
33 
34 template<typename T> class MidiRingBuffer;
35 
37 class LIBARDOUR_API SMFSource : public MidiSource, public FileSource, public Evoral::SMF {
38 public:
40  SMFSource (Session& session, const std::string& path, Source::Flag flags);
41 
43  SMFSource (Session& session, const std::string& path);
44 
46  SMFSource (Session& session, const XMLNode&, bool must_exist = false);
47 
48  virtual ~SMFSource ();
49 
50  bool safe_file_extension (const std::string& path) const {
51  return safe_midi_file_extension(path);
52  }
53 
54  void append_event_beats (const Lock& lock, const Evoral::Event<Evoral::Beats>& ev);
55  void append_event_frames (const Lock& lock, const Evoral::Event<framepos_t>& ev, framepos_t source_start);
56 
57  void mark_streaming_midi_write_started (const Lock& lock, NoteMode mode);
58  void mark_streaming_write_completed (const Lock& lock);
59  void mark_midi_streaming_write_completed (const Lock& lock,
61  Evoral::Beats when = Evoral::Beats());
62 
63  XMLNode& get_state ();
64  int set_state (const XMLNode&, int version);
65 
66  void load_model (const Glib::Threads::Mutex::Lock& lock, bool force_reload=false);
67  void destroy_model (const Glib::Threads::Mutex::Lock& lock);
68 
69  static bool safe_midi_file_extension (const std::string& path);
70  static bool valid_midi_file (const std::string& path);
71 
72  void prevent_deletion ();
73 
74  protected:
75  void close ();
76  void set_path (const std::string& newpath);
77  void flush_midi (const Lock& lock);
78 
79  private:
80  bool _open;
87 
88  int open_for_write ();
89 
90  void ensure_disk_file (const Lock& lock);
91 
92  framecnt_t read_unlocked (const Lock& lock,
96  framecnt_t cnt,
97  MidiStateTracker* tracker,
98  MidiChannelFilter* filter) const;
99 
100  framecnt_t write_unlocked (const Lock& lock,
103  framecnt_t cnt);
104 
105 };
106 
107 }; /* namespace ARDOUR */
108 
109 #endif /* __ardour_smf_source_h__ */
110 
framepos_t _smf_last_read_end
Definition: smf_source.h:84
NoteMode
Definition: types.h:204
Glib::Threads::Mutex::Lock Lock
Definition: source.h:54
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
framepos_t _smf_last_read_time
Definition: smf_source.h:86
int64_t framecnt_t
Definition: types.h:76
Definition: amp.h:29
int64_t framepos_t
Definition: types.h:66
bool safe_file_extension(const std::string &path) const
Definition: smf_source.h:50
#define LIBARDOUR_API
Definition: xml++.h:95
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
Evoral::Beats _last_ev_time_beats
Definition: smf_source.h:81
framepos_t _last_ev_time_frames
Definition: smf_source.h:82