OSC:: needs the .h file too...
[ardour.git] / gtk2_ardour / midi_list_editor.h
1 /*
2     Copyright (C) 2009 Paul Davis
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #ifndef __ardour_gtk2_midi_list_editor_h_
20 #define __ardour_gtk2_midi_list_editor_h_
21
22 #include <gtkmm/treeview.h>
23 #include <gtkmm/table.h>
24 #include <gtkmm/box.h>
25 #include <gtkmm/liststore.h>
26 #include <gtkmm/scrolledwindow.h>
27
28 #include "ardour/session_handle.h"
29
30 #include "ardour_window.h"
31
32 namespace Evoral {
33         template<typename Time> class Note;
34         class                         Beats;
35 };
36
37 namespace ARDOUR {
38         class MidiRegion;
39         class MidiModel;
40         class MidiTrack;
41         class Session;
42 };
43
44 class MidiListEditor : public ArdourWindow
45 {
46   public:
47         typedef Evoral::Note<Evoral::Beats> NoteType;
48
49         MidiListEditor(ARDOUR::Session*, boost::shared_ptr<ARDOUR::MidiRegion>,
50                        boost::shared_ptr<ARDOUR::MidiTrack>);
51         ~MidiListEditor();
52
53   private:
54         struct MidiListModelColumns : public Gtk::TreeModel::ColumnRecord {
55                 MidiListModelColumns() {
56                         add (channel);
57                         add (note);
58                         add (note_name);
59                         add (velocity);
60                         add (start);
61                         add (length);
62                         add (_note);
63                 };
64                 Gtk::TreeModelColumn<uint8_t>     channel;
65                 Gtk::TreeModelColumn<uint8_t>     note;
66                 Gtk::TreeModelColumn<std::string> note_name;
67                 Gtk::TreeModelColumn<uint8_t>     velocity;
68                 Gtk::TreeModelColumn<std::string> start;
69                 Gtk::TreeModelColumn<std::string> length;
70                 Gtk::TreeModelColumn<boost::shared_ptr<NoteType> > _note;
71         };
72
73         struct NoteLengthColumns : public Gtk::TreeModel::ColumnRecord {
74                 NoteLengthColumns() {
75                         add (ticks);
76                         add (name);
77                 }
78                 Gtk::TreeModelColumn<int>         ticks;
79                 Gtk::TreeModelColumn<std::string> name;
80         };
81
82         MidiListModelColumns         columns;
83         Glib::RefPtr<Gtk::ListStore> model;
84         NoteLengthColumns            note_length_columns;
85         Glib::RefPtr<Gtk::ListStore> note_length_model;
86         Gtk::TreeView                view;
87         Gtk::ScrolledWindow          scroller;
88         Gtk::TreeModel::Path         edit_path;
89         int                          edit_column;
90         Gtk::CellRendererText*       editing_renderer;
91         Gtk::CellEditable*           editing_editable;
92         Gtk::Table                   buttons;
93         Gtk::VBox                    vbox;
94         Gtk::ToggleButton            sound_notes_button;
95
96         boost::shared_ptr<ARDOUR::MidiRegion> region;
97         boost::shared_ptr<ARDOUR::MidiTrack>  track;
98
99         /** connection used to connect to model's ContentChanged signal */
100         PBD::ScopedConnection content_connection;
101
102         void edited (const std::string&, const std::string&);
103         void editing_started (Gtk::CellEditable*, const std::string& path, int);
104         void editing_canceled ();
105         void stop_editing (bool cancelled = false);
106
107         void redisplay_model ();
108
109         bool key_press (GdkEventKey* ev);
110         bool key_release (GdkEventKey* ev);
111         bool scroll_event (GdkEventScroll*);
112
113         void delete_selected_note ();
114         void selection_changed ();
115 };
116
117 #endif /* __ardour_gtk2_midi_list_editor_h_ */