2 Copyright (C) 2007 Paul Davis
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.
21 #ifndef __ardour_midi_model_h__
22 #define __ardour_midi_model_h__
27 #include <boost/utility.hpp>
28 #include <glibmm/thread.h>
29 #include <pbd/command.h>
30 #include <ardour/types.h>
31 #include <ardour/midi_buffer.h>
32 #include <ardour/midi_ring_buffer.h>
33 #include <ardour/automatable.h>
34 #include <ardour/types.h>
35 #include <evoral/Note.hpp>
36 #include <evoral/Sequence.hpp>
43 /** This is a higher level (than MidiBuffer) model of MIDI data, with separate
44 * representations for notes (instead of just unassociated note on/off events)
45 * and controller data. Controller data is represented as part of the
46 * Automatable base (i.e. in a map of AutomationList, keyed by Parameter).
47 * Because of this MIDI controllers and automatable controllers/widgets/etc
48 * are easily interchangeable.
50 class MidiModel : public AutomatableSequence {
52 MidiModel(MidiSource* s, size_t size=0);
54 NoteMode note_mode() const { return (percussive() ? Percussive : Sustained); }
55 void set_note_mode(NoteMode mode) { set_percussive(mode == Percussive); };
58 * Technically all note operations can be implemented as one of these, but
59 * a custom command can be more efficient.
61 class DeltaCommand : public Command {
63 DeltaCommand (boost::shared_ptr<MidiModel> m, const std::string& name);
64 DeltaCommand (boost::shared_ptr<MidiModel> m, const XMLNode& node);
66 const std::string& name() const { return _name; }
71 int set_state (const XMLNode&);
72 XMLNode& get_state ();
74 void add(const boost::shared_ptr<Evoral::Note> note);
75 void remove(const boost::shared_ptr<Evoral::Note> note);
78 XMLNode &marshal_note(const boost::shared_ptr<Evoral::Note> note);
79 boost::shared_ptr<Evoral::Note> unmarshal_note(XMLNode *xml_note);
81 boost::shared_ptr<MidiModel> _model;
82 const std::string _name;
84 typedef std::list< boost::shared_ptr<Evoral::Note> > NoteList;
86 NoteList _added_notes;
87 NoteList _removed_notes;
90 MidiModel::DeltaCommand* new_delta_command(const std::string name="midi edit");
91 void apply_command(Session& session, Command* cmd);
93 bool write_to(boost::shared_ptr<MidiSource> source);
95 // MidiModel doesn't use the normal AutomationList serialisation code
96 // since controller data is stored in the .mid
98 int set_state(const XMLNode&) { return 0; }
100 sigc::signal<void> ContentsChanged;
102 const MidiSource* midi_source() const { return _midi_source; }
103 void set_midi_source(MidiSource* source) { _midi_source = source; }
106 friend class DeltaCommand;
108 // We cannot use a boost::shared_ptr here to avoid a retain cycle
109 MidiSource* _midi_source;
112 } /* namespace ARDOUR */
114 #endif /* __ardour_midi_model_h__ */