bdd52d5265bcac21fa4cf12f4ed48ee474c2ef9e
[ardour.git] / gtk2_ardour / midi_time_axis.h
1 /*
2     Copyright (C) 2006 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_midi_time_axis_h__
20 #define __ardour_midi_time_axis_h__
21
22 #include <gtkmm/table.h>
23 #include <gtkmm/button.h>
24 #include <gtkmm/box.h>
25 #include <gtkmm/menu.h>
26 #include <gtkmm/menuitem.h>
27 #include <gtkmm/radiomenuitem.h>
28 #include <gtkmm/checkmenuitem.h>
29
30 #include <gtkmm2ext/selector.h>
31 #include <list>
32
33 #include "ardour/types.h"
34 #include "ardour/region.h"
35
36 #include "ardour_dialog.h"
37 #include "route_ui.h"
38 #include "enums.h"
39 #include "route_time_axis.h"
40 #include "canvas.h"
41 #include "midi_streamview.h"
42 #include "midi_channel_selector.h"
43
44 namespace ARDOUR {
45         class Session;
46         class RouteGroup;
47         class Processor;
48         class Location;
49         class MidiPlaylist;
50 }
51
52 class PublicEditor;
53 class MidiStreamView;
54 class MidiScroomer;
55 class PianoRollHeader;
56 class StepEntry;
57
58 class MidiTimeAxisView : public RouteTimeAxisView
59 {
60   public:
61         MidiTimeAxisView (PublicEditor&, ARDOUR::Session*, boost::shared_ptr<ARDOUR::Route>, ArdourCanvas::Canvas& canvas);
62         virtual ~MidiTimeAxisView ();
63
64         MidiStreamView* midi_view();
65
66         /* overridden from parent to store display state */
67         guint32 show_at (double y, int& nth, Gtk::VBox *parent);
68         void set_height (uint32_t);
69         void hide ();
70
71         boost::shared_ptr<ARDOUR::Region> add_region (ARDOUR::framepos_t pos);
72
73         void show_all_automation ();
74         void show_existing_automation ();
75         void create_automation_child (const Evoral::Parameter& param, bool show);
76
77         ARDOUR::NoteMode  note_mode() const { return _note_mode; }
78         ARDOUR::ColorMode color_mode() const { return _color_mode; }
79
80         void update_range();
81
82         sigc::signal<void, ARDOUR::ChannelMode, uint16_t>& signal_channel_mode_changed() {
83                 return _channel_selector.mode_changed;
84         }
85
86         sigc::signal<void, std::string, std::string>& signal_midi_patch_settings_changed() {
87                 return _midi_patch_settings_changed;
88         }
89
90         void check_step_edit ();
91         void step_edit_rest (Evoral::MusicalTime beats);
92         void step_edit_beat_sync ();
93         void step_edit_bar_sync ();
94         int  step_add_bank_change (uint8_t channel, uint8_t bank);
95         int  step_add_program_change (uint8_t channel, uint8_t program);
96         int  step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, 
97                             Evoral::MusicalTime beat_duration);
98         bool step_edit_within_triplet () const;
99         void step_edit_toggle_triplet ();
100         bool step_edit_within_chord () const;
101         void step_edit_toggle_chord ();
102         void set_step_edit_cursor_width (Evoral::MusicalTime beats);
103         
104         const MidiMultipleChannelSelector& channel_selector() { return _channel_selector; }
105
106         Gtk::CheckMenuItem* automation_child_menu_item (Evoral::Parameter);
107
108   protected:
109         void start_step_editing ();
110         void stop_step_editing ();
111
112   private:
113         sigc::signal<void, std::string, std::string>  _midi_patch_settings_changed;
114
115         void model_changed();
116         void custom_device_mode_changed();
117
118         void append_extra_display_menu_items ();
119         void build_automation_action_menu ();
120         Gtk::Menu* build_note_mode_menu();
121         Gtk::Menu* build_color_mode_menu();
122
123         void set_note_mode (ARDOUR::NoteMode mode);
124         void set_color_mode(ARDOUR::ColorMode mode);
125         void set_note_range(MidiStreamView::VisibleNoteRange range);
126
127         void route_active_changed ();
128
129         bool                         _ignore_signals;
130         MidiScroomer*                _range_scroomer;
131         PianoRollHeader*             _piano_roll_header;
132         ARDOUR::NoteMode             _note_mode;
133         Gtk::RadioMenuItem*          _note_mode_item;
134         Gtk::RadioMenuItem*          _percussion_mode_item;
135         ARDOUR::ColorMode            _color_mode;
136         Gtk::RadioMenuItem*          _meter_color_mode_item;
137         Gtk::RadioMenuItem*          _channel_color_mode_item;
138         Gtk::RadioMenuItem*          _track_color_mode_item;
139         Gtk::VBox                    _midi_controls_box;
140         MidiMultipleChannelSelector  _channel_selector;
141         Gtk::ComboBoxText            _model_selector;
142         Gtk::ComboBoxText            _custom_device_mode_selector;
143
144         Gtk::CheckMenuItem*          _step_edit_item;
145         Gtk::CheckMenuItem*          _midi_thru_item;
146         Gtk::Menu*                    default_channel_menu;
147
148         nframes64_t step_edit_insert_position;
149         Evoral::MusicalTime step_edit_beat_pos;
150         boost::shared_ptr<ARDOUR::Region> step_edit_region;
151         MidiRegionView* step_edit_region_view;
152         uint8_t _step_edit_triplet_countdown;
153         bool    _step_edit_within_chord;
154         Evoral::MusicalTime _step_edit_chord_duration;
155         void region_removed (boost::weak_ptr<ARDOUR::Region>);
156         void playlist_changed ();
157         PBD::ScopedConnection step_edit_region_connection;
158
159         Gtk::Menu* build_def_channel_menu();
160         void set_default_channel (int);
161         void toggle_midi_thru ();
162
163         void change_all_channel_tracks_visibility (bool yn, Evoral::Parameter param);
164         void add_basic_parameter_menu_item (Gtk::Menu_Helpers::MenuList& items, const std::string& label, Evoral::Parameter param);
165         void add_channel_command_menu_item (Gtk::Menu_Helpers::MenuList& items, const std::string& label, ARDOUR::AutomationType auto_type, uint8_t cmd);
166
167         Gtk::Menu* controller_menu;
168         void build_controller_menu ();
169         void set_channel_mode (ARDOUR::ChannelMode, uint16_t);
170
171         void add_note_selection (uint8_t note);
172         void extend_note_selection (uint8_t note);
173         void toggle_note_selection (uint8_t note);
174         void add_note_selection_region_view (RegionView* rv, uint8_t note, uint16_t chn_mask);
175         void extend_note_selection_region_view (RegionView*, uint8_t note, uint16_t chn_mask);
176         void toggle_note_selection_region_view (RegionView*, uint8_t note, uint16_t chn_mask);
177
178         /** parameter -> menu item map for the channel command items */
179         ParameterMenuMap _channel_command_menu_map;
180         /** parameter -> menu item map for the controller menu */
181         ParameterMenuMap _controller_menu_map;
182
183         StepEntry* step_editor;
184         bool step_editor_hidden (GdkEventAny*);
185 };
186
187 #endif /* __ardour_midi_time_axis_h__ */
188