use new method in MidiPatchManager to use MIDNAM data when setting a MidiTimeAxisView
[ardour.git] / gtk2_ardour / midi_list_editor.h
1 /*
2  * Copyright (C) 2009-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef __ardour_gtk2_midi_list_editor_h_
21 #define __ardour_gtk2_midi_list_editor_h_
22
23 #include <gtkmm/treeview.h>
24 #include <gtkmm/table.h>
25 #include <gtkmm/box.h>
26 #include <gtkmm/liststore.h>
27 #include <gtkmm/scrolledwindow.h>
28
29 #include "ardour/session_handle.h"
30
31 #include "ardour_window.h"
32
33 namespace Evoral {
34         template<typename Time> class Note;
35         class                         Beats;
36 };
37
38 namespace ARDOUR {
39         class MidiRegion;
40         class MidiModel;
41         class MidiTrack;
42         class Session;
43 };
44
45 class MidiListEditor : public ArdourWindow
46 {
47 public:
48         typedef Evoral::Note<Temporal::Beats> NoteType;
49
50         MidiListEditor(ARDOUR::Session*, boost::shared_ptr<ARDOUR::MidiRegion>,
51                        boost::shared_ptr<ARDOUR::MidiTrack>);
52         ~MidiListEditor();
53
54 private:
55         struct MidiListModelColumns : public Gtk::TreeModel::ColumnRecord
56         {
57                 MidiListModelColumns() {
58                         add (channel);
59                         add (note);
60                         add (note_name);
61                         add (velocity);
62                         add (start);
63                         add (length);
64                         add (_note);
65                 };
66                 Gtk::TreeModelColumn<uint8_t>     channel;
67                 Gtk::TreeModelColumn<uint8_t>     note;
68                 Gtk::TreeModelColumn<std::string> note_name;
69                 Gtk::TreeModelColumn<uint8_t>     velocity;
70                 Gtk::TreeModelColumn<std::string> start;
71                 Gtk::TreeModelColumn<std::string> length;
72                 Gtk::TreeModelColumn<boost::shared_ptr<NoteType> > _note;
73         };
74
75         struct NoteLengthColumns : public Gtk::TreeModel::ColumnRecord
76         {
77                 NoteLengthColumns() {
78                         add (ticks);
79                         add (name);
80                 }
81                 Gtk::TreeModelColumn<int>         ticks;
82                 Gtk::TreeModelColumn<std::string> name;
83         };
84
85         MidiListModelColumns         columns;
86         Glib::RefPtr<Gtk::ListStore> model;
87         NoteLengthColumns            note_length_columns;
88         Glib::RefPtr<Gtk::ListStore> note_length_model;
89         Gtk::TreeView                view;
90         Gtk::ScrolledWindow          scroller;
91         Gtk::TreeModel::Path         edit_path;
92         int                          edit_column;
93         Gtk::CellRendererText*       editing_renderer;
94         Gtk::CellEditable*           editing_editable;
95         Gtk::Table                   buttons;
96         Gtk::VBox                    vbox;
97         Gtk::ToggleButton            sound_notes_button;
98
99         boost::shared_ptr<ARDOUR::MidiRegion> region;
100         boost::shared_ptr<ARDOUR::MidiTrack>  track;
101
102         /** connection used to connect to model's ContentChanged signal */
103         PBD::ScopedConnection content_connection;
104
105         void edited (const std::string&, const std::string&);
106         void editing_started (Gtk::CellEditable*, const std::string& path, int);
107         void editing_canceled ();
108         void stop_editing (bool cancelled = false);
109
110         void redisplay_model ();
111
112         bool key_press (GdkEventKey* ev);
113         bool key_release (GdkEventKey* ev);
114         bool scroll_event (GdkEventScroll*);
115
116         void delete_selected_note ();
117         void selection_changed ();
118 };
119
120 #endif /* __ardour_gtk2_midi_list_editor_h_ */