2 Copyright (C) 2006 Paul Davis
3 Written by Dave Robillard, 2006
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.
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.
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.
20 #ifndef __ardour_midi_source_h__
21 #define __ardour_midi_source_h__
27 #include <glibmm/thread.h>
29 #include <sigc++/signal.h>
31 #include <ardour/source.h>
32 #include <ardour/ardour.h>
33 #include <ardour/buffer.h>
34 #include <ardour/midi_model.h>
35 #include <pbd/stateful.h>
36 #include <pbd/xml++.h>
44 /** Source for MIDI data */
45 class MidiSource : public Source
48 MidiSource (Session& session, string name);
49 MidiSource (Session& session, const XMLNode&);
50 virtual ~MidiSource ();
52 /* Stub Readable interface */
53 virtual nframes64_t read (Sample*, nframes64_t pos, nframes64_t cnt, int channel) const { return 0; }
54 virtual nframes64_t readable_length() const { return length(); }
55 virtual uint32_t n_channels () const { return 1; }
57 // FIXME: integrate this with the Readable::read interface somehow
58 virtual nframes_t midi_read (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const;
59 virtual nframes_t midi_write (MidiRingBuffer& src, nframes_t cnt);
61 virtual void append_event_unlocked(EventTimeUnit unit, const Evoral::Event& ev) = 0;
63 virtual void mark_for_remove() = 0;
64 virtual void mark_streaming_midi_write_started (NoteMode mode, nframes_t start_time);
65 virtual void mark_streaming_write_started ();
66 virtual void mark_streaming_write_completed ();
68 uint64_t timeline_position () { return _timeline_position; }
69 void set_timeline_position (nframes_t when) { _timeline_position = when; }
71 virtual void session_saved();
73 string captured_for() const { return _captured_for; }
74 void set_captured_for (string str) { _captured_for = str; }
76 uint32_t read_data_count() const { return _read_data_count; }
77 uint32_t write_data_count() const { return _write_data_count; }
79 static sigc::signal<void,MidiSource*> MidiSourceCreated;
81 // Signal a range of recorded data is available for reading from model()
82 mutable sigc::signal<void,nframes_t,nframes_t> ViewDataRangeReady;
84 XMLNode& get_state ();
85 int set_state (const XMLNode&);
87 bool length_mutable() const { return true; }
89 virtual void load_model(bool lock=true, bool force_reload=false) = 0;
90 virtual void destroy_model() = 0;
92 void set_note_mode(NoteMode mode) { if (_model) _model->set_note_mode(mode); }
94 boost::shared_ptr<MidiModel> model() { return _model; }
95 void set_model(boost::shared_ptr<MidiModel> m) { _model = m; }
98 virtual void flush_midi() = 0;
99 //virtual int flush_header() = 0;
100 //virtual int flush_footer() = 0;
102 virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset, nframes_t negative_stamp_offset) const = 0;
103 virtual nframes_t write_unlocked (MidiRingBuffer& dst, nframes_t cnt) = 0;
105 mutable Glib::Mutex _lock;
106 string _captured_for;
107 uint64_t _timeline_position;
108 mutable uint32_t _read_data_count; ///< modified in read()
109 mutable uint32_t _write_data_count; ///< modified in write()
111 boost::shared_ptr<MidiModel> _model;
115 bool file_changed (string path);
120 #endif /* __ardour_midi_source_h__ */