Fix wrongly exposed set_parameter methods on PluginInsert.
[ardour.git] / libs / ardour / ardour / midi_model.h
1 /*
2     Copyright (C) 2007 Paul Davis
3     Author: Dave 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_midi_model_h__ 
22 #define __ardour_midi_model_h__
23
24 #include <queue>
25 #include <deque>
26 #include <utility>
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>
37
38 namespace ARDOUR {
39
40 class Session;
41 class MidiSource;
42
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.
49  */
50 class MidiModel : public AutomatableSequence {
51 public:
52         MidiModel(MidiSource* s, size_t size=0);
53         
54         NoteMode note_mode() const { return (percussive() ? Percussive : Sustained); }
55         void set_note_mode(NoteMode mode) { set_percussive(mode == Percussive); };
56
57         /** Add/Remove notes.
58          * Technically all note operations can be implemented as one of these, but
59          * a custom command can be more efficient.
60          */
61         class DeltaCommand : public Command {
62         public:
63                 DeltaCommand (boost::shared_ptr<MidiModel> m, const std::string& name);
64                 DeltaCommand (boost::shared_ptr<MidiModel> m, const XMLNode& node);
65
66                 const std::string& name() const { return _name; }
67                 
68                 void operator()();
69                 void undo();
70                 
71                 int set_state (const XMLNode&);
72                 XMLNode& get_state ();
73
74                 void add(const boost::shared_ptr<Evoral::Note> note);
75                 void remove(const boost::shared_ptr<Evoral::Note> note);
76
77         private:
78                 XMLNode &marshal_note(const boost::shared_ptr<Evoral::Note> note);
79                 boost::shared_ptr<Evoral::Note> unmarshal_note(XMLNode *xml_note);
80                 
81                 boost::shared_ptr<MidiModel> _model;
82                 const std::string            _name;
83                 
84                 typedef std::list< boost::shared_ptr<Evoral::Note> > NoteList;
85                 
86                 NoteList _added_notes;
87                 NoteList _removed_notes;
88         };
89
90         MidiModel::DeltaCommand* new_delta_command(const std::string name="midi edit");
91         void                     apply_command(Session& session, Command* cmd);
92
93         bool write_to(boost::shared_ptr<MidiSource> source);
94                 
95         // MidiModel doesn't use the normal AutomationList serialisation code
96         // since controller data is stored in the .mid
97         XMLNode& get_state();
98         int set_state(const XMLNode&) { return 0; }
99
100         sigc::signal<void> ContentsChanged;
101         
102         const MidiSource* midi_source() const { return _midi_source; }
103         void set_midi_source(MidiSource* source) { _midi_source = source; } 
104         
105 private:
106         friend class DeltaCommand;
107         
108         // We cannot use a boost::shared_ptr here to avoid a retain cycle
109         MidiSource* _midi_source;
110 };
111
112 } /* namespace ARDOUR */
113
114 #endif /* __ardour_midi_model_h__ */
115