-
Notifications
You must be signed in to change notification settings - Fork 716
/
Copy pathmidi_time_axis.cc
1735 lines (1423 loc) · 51.9 KB
/
midi_time_axis.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2006-2015 David Robillard <[email protected]>
* Copyright (C) 2008-2012 Hans Baier <[email protected]>
* Copyright (C) 2008-2017 Paul Davis <[email protected]>
* Copyright (C) 2009-2012 Carl Hetherington <[email protected]>
* Copyright (C) 2013-2014 John Emmas <[email protected]>
* Copyright (C) 2013-2016 Tim Mayberry <[email protected]>
* Copyright (C) 2013-2019 Robin Gareus <[email protected]>
* Copyright (C) 2014-2017 Ben Loftis <[email protected]>
* Copyright (C) 2015-2017 Nick Mainsbridge <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <sigc++/bind.h>
#include <gtkmm/separator.h>
#include <gtkmm/stock.h>
#include "pbd/error.h"
#include "pbd/ffs.h"
#include "pbd/stl_delete.h"
#include "pbd/whitespace.h"
#include "pbd/basename.h"
#include "pbd/enumwriter.h"
#include "pbd/memento_command.h"
#include "pbd/stateful_diff_command.h"
#include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/utils.h"
#include "widgets/tooltips.h"
#include "ardour/event_type_map.h"
#include "ardour/midi_patch_manager.h"
#include "ardour/midi_playlist.h"
#include "ardour/midi_region.h"
#include "ardour/midi_source.h"
#include "ardour/midi_track.h"
#include "ardour/operations.h"
#include "ardour/pannable.h"
#include "ardour/panner.h"
#include "ardour/panner_shell.h"
#include "ardour/playlist.h"
#include "ardour/plugin_insert.h"
#include "ardour/profile.h"
#include "ardour/region.h"
#include "ardour/region_factory.h"
#include "ardour/route.h"
#include "ardour/session.h"
#include "ardour/session_object.h"
#include "ardour/source.h"
#include "ardour/track.h"
#include "ardour/types.h"
#include "automation_line.h"
#include "automation_time_axis.h"
#include "editor.h"
#include "enums.h"
#include "ghostregion.h"
#include "gui_thread.h"
#include "keyboard.h"
#include "midi_channel_selector.h"
#include "midi_scroomer.h"
#include "midi_streamview.h"
#include "midi_region_view.h"
#include "midi_time_axis.h"
#include "patch_change_dialog.h"
#include "patch_change_widget.h"
#include "piano_roll_header.h"
#include "playlist_selector.h"
#include "plugin_selector.h"
#include "plugin_ui.h"
#include "point_selection.h"
#include "region_view.h"
#include "rgb_macros.h"
#include "selection.h"
#include "step_editor.h"
#include "utils.h"
#include "note_base.h"
#include "ardour/midi_track.h"
#include "pbd/i18n.h"
using namespace ARDOUR;
using namespace PBD;
using namespace Gtk;
using namespace Gtkmm2ext;
using namespace Editing;
using namespace std;
// Minimum height at which a control is displayed
static const uint32_t MIDI_CONTROLS_BOX_MIN_HEIGHT = 160;
static const uint32_t KEYBOARD_MIN_HEIGHT = 130;
#define DEFAULT_MIDNAM_MODEL (X_("Generic"))
MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
: SessionHandlePtr (sess)
, RouteTimeAxisView (ed, sess, canvas)
, _ignore_signals(false)
, _range_scroomer(0)
, _piano_roll_header(0)
, _note_mode(Sustained)
, _note_mode_item(0)
, _percussion_mode_item(0)
, _color_mode(MeterColors)
, _meter_color_mode_item(0)
, _channel_color_mode_item(0)
, _track_color_mode_item(0)
, _channel_selector (0)
, _step_edit_item (0)
, controller_menu (0)
, _step_editor (0)
{
_midnam_model_selector.disable_scrolling();
_midnam_custom_device_mode_selector.disable_scrolling();
}
void
MidiTimeAxisView::set_note_highlight (uint8_t note) {
_piano_roll_header->set_note_highlight (note);
}
void
MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
{
_route = rt;
_view = new MidiStreamView (*this);
if (is_track ()) {
_piano_roll_header = new PianoRollHeader(*midi_view());
_range_scroomer = new MidiScroomer(midi_view()->note_range_adjustment);
_range_scroomer->DoubleClicked.connect (
sigc::bind (sigc::mem_fun(*this, &MidiTimeAxisView::set_note_range),
MidiStreamView::ContentsRange, false));
}
/* This next call will result in our height being set up, so it must come after
* the creation of the piano roll / range scroomer as their visibility is set up
* when our height is.
*/
RouteTimeAxisView::set_route (rt);
_view->apply_color (ARDOUR_UI_UTILS::gdk_color_to_rgba (color()), StreamView::RegionColor);
subplugin_menu.set_name ("ArdourContextMenu");
_note_range_changed_connection.disconnect();
if (!gui_property ("note-range-min").empty ()) {
midi_view()->apply_note_range (atoi (gui_property ("note-range-min").c_str()),
atoi (gui_property ("note-range-max").c_str()),
true);
}
_view->ContentsHeightChanged.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::contents_height_changed));
ignore_toggle = false;
if (is_midi_track()) {
_note_mode = midi_track()->note_mode();
}
/* if set_state above didn't create a gain automation child, we need to make one */
if (automation_child (GainAutomation) == 0) {
create_automation_child (GainAutomation, false);
}
/* if set_state above didn't create a mute automation child, we need to make one */
if (automation_child (MuteAutomation) == 0) {
create_automation_child (MuteAutomation, false);
}
if (_route->panner_shell()) {
_route->panner_shell()->Changed.connect (*this, invalidator (*this), boost::bind (&MidiTimeAxisView::ensure_pan_views, this, false), gui_context());
}
/* map current state of the route */
ensure_pan_views (false);
update_control_names();
processors_changed (RouteProcessorChange ());
if (is_track()) {
_piano_roll_header->SetNoteSelection.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::set_note_selection));
_piano_roll_header->AddNoteSelection.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::add_note_selection));
_piano_roll_header->ExtendNoteSelection.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::extend_note_selection));
_piano_roll_header->ToggleNoteSelection.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::toggle_note_selection));
/* Put the scroomer and the keyboard in a VBox with a padding
* label so that they can be reduced in height for stacked-view
* tracks.
*/
HSeparator* separator = manage (new HSeparator());
separator->set_name("TrackSeparator");
separator->set_size_request(-1, 1);
separator->show();
VBox* v = manage (new VBox);
HBox* h = manage (new HBox);
h->pack_end (*_piano_roll_header);
h->pack_end (*_range_scroomer);
v->pack_start (*separator, false, false);
v->pack_start (*h, true, true);
v->show ();
h->show ();
top_hbox.remove(scroomer_placeholder);
time_axis_hbox.pack_end(*v, false, false, 0);
midi_scroomer_size_group->add_widget (*v);
/* callback from StreamView scroomer drags, as well as
* automatic changes of note-range (e.g. at rec-stop).
* This callback is used to save the note-range-min/max
* GUI Object property
*/
_note_range_changed_connection = midi_view()->NoteRangeChanged.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::note_range_changed));
/* ask for notifications of any new RegionViews */
_view->RegionViewAdded.connect (
sigc::mem_fun(*this, &MidiTimeAxisView::region_view_added));
if (!_editor.have_idled()) {
/* first idle will do what we need */
} else {
first_idle ();
}
}
ArdourWidgets::set_tooltip (_midnam_model_selector, _("External MIDI Device"));
ArdourWidgets::set_tooltip (_midnam_custom_device_mode_selector, _("External Device Mode"));
_midi_controls_box.pack_start (_midnam_model_selector, false, false, 2);
_midi_controls_box.pack_start (_midnam_custom_device_mode_selector, false, false, 2);
_midi_controls_box.set_homogeneous(false);
_midi_controls_box.set_border_width (2);
/* this directly calls use_midnam_info() if there are midnam's already */
MIDI::Name::MidiPatchManager::instance().maybe_use (*this, invalidator (*this), boost::bind (&MidiTimeAxisView::use_midnam_info, this), gui_context());
controls_vbox.pack_start(_midi_controls_box, false, false);
const string color_mode = gui_property ("color-mode");
if (!color_mode.empty()) {
_color_mode = ColorMode (string_2_enum(color_mode, _color_mode));
if (_channel_selector && _color_mode == ChannelColors) {
_channel_selector->set_channel_colors(NoteBase::midi_channel_colors);
}
}
set_color_mode (_color_mode, true, false);
const string note_mode = gui_property ("note-mode");
if (!note_mode.empty()) {
_note_mode = NoteMode (string_2_enum (note_mode, _note_mode));
if (_percussion_mode_item) {
_percussion_mode_item->set_active (_note_mode == Percussive);
}
}
/* Look for any GUI object state nodes that represent automation children
* that should exist, and create the children.
*/
const list<string> gui_ids = gui_object_state().all_ids ();
for (list<string>::const_iterator i = gui_ids.begin(); i != gui_ids.end(); ++i) {
PBD::ID route_id;
bool has_parameter;
Evoral::Parameter parameter (0, 0, 0);
bool const p = AutomationTimeAxisView::parse_state_id (
*i, route_id, has_parameter, parameter);
if (p && route_id == _route->id () && has_parameter) {
const std::string& visible = gui_object_state().get_string (*i, X_("visible"));
create_automation_child (parameter, string_to<bool> (visible));
}
}
}
void
MidiTimeAxisView::first_idle ()
{
if (is_track ()) {
_view->attach ();
}
}
MidiTimeAxisView::~MidiTimeAxisView ()
{
delete _channel_selector;
delete _piano_roll_header;
_piano_roll_header = 0;
delete _range_scroomer;
_range_scroomer = 0;
delete controller_menu;
delete _step_editor;
}
void
MidiTimeAxisView::check_step_edit ()
{
ensure_step_editor ();
_step_editor->check_step_edit ();
}
void
MidiTimeAxisView::processors_changed (RouteProcessorChange c)
{
RouteTimeAxisView::processors_changed (c);
maybe_trigger_model_change ();
}
void
MidiTimeAxisView::use_midnam_info ()
{
/* Rebuild controller menu */
_controller_menu_map.clear ();
delete controller_menu;
controller_menu = 0;
setup_midnam_patches ();
/* update names on any automation lane with MIDNAM names */
for (AutomationTracks::iterator i = _automation_tracks.begin(); i != _automation_tracks.end(); ++i) {
switch (i->first.type()) {
case MidiCCAutomation:
i->second->update_name_from_param ();
break;
default:
continue;
}
}
}
void
MidiTimeAxisView::maybe_trigger_model_change ()
{
if (_route->instrument_info().have_custom_plugin_info ()) {
/* ensure that "Plugin Provided" is at the top of the list */
if (_midnam_model_selector.items().empty () || _midnam_model_selector.items().begin()->get_label() != _("Plugin Provided")) {
/* setup_midnam_patches unconditionally calls model_changed() */
setup_midnam_patches ();
}
} else {
/* no plugin provided MIDNAM for this plugin */
if (!_midnam_model_selector.items().empty () && _midnam_model_selector.items().begin()->get_label() == _("Plugin Provided")) {
/* setup_midnam_patches unconditionally calls model_changed() */
setup_midnam_patches ();
}
}
}
void
MidiTimeAxisView::setup_midnam_patches ()
{
typedef MIDI::Name::MidiPatchManager PatchManager;
PatchManager& patch_manager = PatchManager::instance();
_midnam_model_selector.clear_items ();
if (_route->instrument_info().have_custom_plugin_info ()) {
Menu_Helpers::MenuElem elem = Gtk::Menu_Helpers::MenuElem(_("Plugin Provided"), sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::model_changed), ""));
_midnam_model_selector.AddMenuElem(elem);
}
for (PatchManager::DeviceNamesByMaker::const_iterator m = patch_manager.devices_by_manufacturer().begin(); m != patch_manager.devices_by_manufacturer().end(); ++m) {
Menu* menu = Gtk::manage(new Menu);
Menu_Helpers::MenuList& items = menu->items();
/* Build manufacturer submenu */
for (MIDI::Name::MIDINameDocument::MasterDeviceNamesList::const_iterator n = m->second.begin(); n != m->second.end(); ++n) {
if (patch_manager.is_custom_model (n->first)) {
continue;
}
Menu_Helpers::MenuElem elem = Gtk::Menu_Helpers::MenuElem(
n->first.c_str(),
sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::model_changed),
n->first.c_str()));
items.push_back(elem);
}
if (items.empty ()) {
delete menu;
continue;
}
/* Add manufacturer submenu to selector */
_midnam_model_selector.AddMenuElem(Menu_Helpers::MenuElem(m->first, *menu));
}
if (patch_manager.all_models().empty()) {
_midnam_model_selector.hide ();
_midnam_custom_device_mode_selector.hide ();
} else {
_midnam_model_selector.show ();
if (_midnam_custom_device_mode_selector.items().size() > 1) {
_midnam_custom_device_mode_selector.show ();
}
}
/* call _midnam_model_selector.set_text ()
* and show/hide _midnam_custom_device_mode_selector
*/
std::string model = gui_property (X_("midnam-model-name"));
if (model.empty() && _route->instrument_info().have_custom_plugin_info ()) {
/* use plugin's MIDNAM */
model_changed ("");
} else if (model.empty() || ! MIDI::Name::MidiPatchManager::instance ().master_device_by_model (model)) {
/* invalid model, switch to use default */
model_changed ("");
} else {
model_changed (model);
}
}
void
MidiTimeAxisView::model_changed (const std::string& m)
{
typedef MIDI::Name::MidiPatchManager PatchManager;
PatchManager& patch_manager = PatchManager::instance();
std::string model (m);
bool save_model = m != "";
if (model.empty() && !_route->instrument_info().have_custom_plugin_info ()) {
model = DEFAULT_MIDNAM_MODEL;
}
std::list<std::string> device_modes = patch_manager.custom_device_mode_names_by_model (model);
if (device_modes.empty()) {
save_model = false;
if (_route->instrument_info().have_custom_plugin_info ()) {
model = "";
} else {
model = DEFAULT_MIDNAM_MODEL;
}
device_modes = patch_manager.custom_device_mode_names_by_model (model);
}
if (model == "") {
_midnam_model_selector.set_text (_("Plugin Provided"));
} else {
_midnam_model_selector.set_text (model);
}
if (save_model) {
set_gui_property (X_("midnam-model-name"), model);
} else {
remove_gui_property (X_("midnam-model-name"));
}
/* set new mode */
const std::string current_mode = gui_property (X_("midnam-custom-device-mode"));
std::string mode;
if (find (device_modes.begin(), device_modes.end(), current_mode) == device_modes.end()) {
if (device_modes.size() > 0) {
mode = device_modes.front();
if (save_model) {
custom_device_mode_changed (device_modes.front());
}
} else {
mode = "";
}
} else {
mode = current_mode;
}
/* set backend state */
_route->instrument_info().set_external_instrument (model, mode);
/* query effective model/mode -- may be plugin provided */
if (_effective_model == _route->instrument_info().model () && _effective_mode == _route->instrument_info().mode ()) {
/* no change */
return;
}
_effective_model = _route->instrument_info().model ();
_effective_mode = _route->instrument_info().mode ();
/* update GUI */
_midnam_custom_device_mode_selector.clear_items();
for (std::list<std::string>::const_iterator i = device_modes.begin(); i != device_modes.end(); ++i) {
_midnam_custom_device_mode_selector.AddMenuElem (Gtk::Menu_Helpers::MenuElem(*i, sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::custom_device_mode_changed), *i)));
}
if (device_modes.size() > 1) {
_midnam_custom_device_mode_selector.show();
} else {
_midnam_custom_device_mode_selector.hide();
}
/* set _midnam_custom_device_mode_selector */
custom_device_mode_changed (mode);
/* Rebuild controller menu */
_controller_menu_map.clear ();
delete controller_menu;
controller_menu = 0;
if (patch_change_dialog ()) {
patch_change_dialog ()->refresh ();
}
}
void
MidiTimeAxisView::custom_device_mode_changed(const std::string& mode)
{
const std::string model = gui_property (X_("midnam-model-name"));
set_gui_property (X_("midnam-custom-device-mode"), mode);
_midnam_custom_device_mode_selector.set_text (mode);
if (model.empty () && !mode.empty ()) {
/* model.empty () && model.empty () -> plugin provided
* otherwise at least a model must be set. */
return;
}
/* inform the backend, route owned instrument info */
_route->instrument_info().set_external_instrument (model, mode);
}
MidiStreamView*
MidiTimeAxisView::midi_view()
{
return dynamic_cast<MidiStreamView*>(_view);
}
void
MidiTimeAxisView::update_midi_controls_visibility (uint32_t h)
{
if (_route && !_route->active ()) {
h = 0;
}
if (h >= MIDI_CONTROLS_BOX_MIN_HEIGHT) {
_midi_controls_box.show ();
} else {
_midi_controls_box.hide();
}
}
void
MidiTimeAxisView::set_height (uint32_t h, TrackHeightMode m)
{
update_midi_controls_visibility (h);
if (h >= MIDI_CONTROLS_BOX_MIN_HEIGHT) {
_midi_controls_box.show ();
} else {
_midi_controls_box.hide();
}
if (h >= KEYBOARD_MIN_HEIGHT) {
if (is_track() && _range_scroomer) {
_range_scroomer->show();
}
if (is_track() && _piano_roll_header) {
_piano_roll_header->show();
}
} else {
if (is_track() && _range_scroomer) {
_range_scroomer->hide();
}
if (is_track() && _piano_roll_header) {
_piano_roll_header->hide();
}
}
/* We need to do this after changing visibility of our stuff, as it will
* eventually trigger a call to Editor::reset_controls_layout_width(),
* which needs to know if we have just shown or hidden a scroomer /
* piano roll.
*/
RouteTimeAxisView::set_height (h, m);
}
void
MidiTimeAxisView::append_extra_display_menu_items ()
{
using namespace Menu_Helpers;
MenuList& items = display_menu->items();
// Note range
Menu *range_menu = manage(new Menu);
MenuList& range_items = range_menu->items();
range_menu->set_name ("ArdourContextMenu");
range_items.push_back (
MenuElem (_("Show Full Range"),
sigc::bind (sigc::mem_fun(*this, &MidiTimeAxisView::set_note_range),
MidiStreamView::FullRange, true)));
range_items.push_back (
MenuElem (_("Fit Contents"),
sigc::bind (sigc::mem_fun(*this, &MidiTimeAxisView::set_note_range),
MidiStreamView::ContentsRange, true)));
range_items.push_back (
MenuElem (_("One Note"),
sigc::bind (sigc::mem_fun(*this, &MidiTimeAxisView::set_note_range),
MidiStreamView::OneNoteRange, true)));
items.push_back (MenuElem (_("Note Range"), *range_menu));
items.push_back (MenuElem (_("Note Mode"), *build_note_mode_menu()));
items.push_back (MenuElem (_("Channel Selector..."),
sigc::mem_fun(*this, &MidiTimeAxisView::toggle_channel_selector)));
items.push_back (MenuElem (_("Patch Selector..."),
sigc::mem_fun(*this, &RouteUI::select_midi_patch)));
items.push_back (MenuElem (_("Color Mode"), *build_color_mode_menu ()));
items.push_back (SeparatorElem ());
}
void
MidiTimeAxisView::toggle_channel_selector ()
{
if (!_channel_selector) {
_channel_selector = new MidiChannelSelectorWindow (midi_track());
if (_color_mode == ChannelColors) {
_channel_selector->set_channel_colors(NoteBase::midi_channel_colors);
} else {
_channel_selector->set_default_channel_color ();
}
_channel_selector->show_all ();
} else {
_channel_selector->cycle_visibility ();
}
}
void
MidiTimeAxisView::build_automation_action_menu (bool for_selection)
{
using namespace Menu_Helpers;
/* If we have a controller menu, we need to detach it before
* RouteTimeAxis::build_automation_action_menu destroys the
* menu it is attached to. Otherwise GTK destroys
* controller_menu's gobj, meaning that it can't be reattached
* below. See bug #3134.
*/
if (controller_menu) {
detach_menu (*controller_menu);
}
_channel_command_menu_map.clear ();
RouteTimeAxisView::build_automation_action_menu (for_selection);
MenuList& automation_items = automation_action_menu->items();
uint16_t selected_channels = midi_track()->get_playback_channel_mask();
if (selected_channels != 0) {
automation_items.push_back (SeparatorElem());
/* these 2 MIDI "command" types are semantically more like automation
* than note data, but they are not MIDI controllers. We give them
* special status in this menu, since they will not show up in the
* controller list and anyone who actually knows something about MIDI
* (!) would not expect to find them there.
*/
add_channel_command_menu_item (automation_items, _("Bender"), MidiPitchBenderAutomation, 0);
automation_items.back().set_sensitive (!for_selection || _editor.get_selection().tracks.size() == 1);
add_channel_command_menu_item (automation_items, _("Pressure"), MidiChannelPressureAutomation, 0);
automation_items.back().set_sensitive (!for_selection || _editor.get_selection().tracks.size() == 1);
/* now all MIDI controllers. Always offer the possibility that we will
* rebuild the controllers menu since it might need to be updated after
* a channel mode change or other change. Also detach it first in case
* it has been used anywhere else.
*/
build_controller_menu ();
automation_items.push_back (MenuElem (_("Controllers"), *controller_menu));
add_channel_command_menu_item (automation_items, _("Polyphonic Pressure"), MidiNotePressureAutomation, 0);
automation_items.back().set_sensitive (!for_selection || _editor.get_selection().tracks.size() == 1);
} else {
automation_items.push_back (
MenuElem (string_compose ("<i>%1</i>", _("No MIDI Channels selected"))));
dynamic_cast<Label*> (automation_items.back().get_child())->set_use_markup (true);
}
}
void
MidiTimeAxisView::change_all_channel_tracks_visibility (bool yn, Evoral::Parameter param)
{
const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
Evoral::Parameter fully_qualified_param (param.type(), chn, param.id());
Gtk::CheckMenuItem* menu = automation_child_menu_item (fully_qualified_param);
if (menu) {
menu->set_active (yn);
}
}
}
}
void
MidiTimeAxisView::add_channel_command_menu_item (Menu_Helpers::MenuList& items,
const string& label,
AutomationType auto_type,
uint8_t cmd)
{
using namespace Menu_Helpers;
/* count the number of selected channels because we will build a different menu
* structure if there is more than 1 selected.
*/
const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
int chn_cnt = 0;
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
if (++chn_cnt > 1) {
break;
}
}
}
if (chn_cnt > 1) {
/* multiple channels - create a submenu, with 1 item per channel */
Menu* chn_menu = manage (new Menu);
MenuList& chn_items (chn_menu->items());
Evoral::Parameter param_without_channel (auto_type, 0, cmd);
/* add a couple of items to hide/show all of them */
chn_items.push_back (
MenuElem (_("Hide all channels"),
sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility),
false, param_without_channel)));
chn_items.push_back (
MenuElem (_("Show all channels"),
sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility),
true, param_without_channel)));
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
/* for each selected channel, add a menu item for this controller */
Evoral::Parameter fully_qualified_param (auto_type, chn, cmd);
chn_items.push_back (
CheckMenuElem (string_compose (_("Channel %1"), chn+1),
sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
fully_qualified_param)));
boost::shared_ptr<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
bool visible = false;
if (track) {
if (track->marked_for_display()) {
visible = true;
}
}
Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&chn_items.back());
_channel_command_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
}
}
/* now create an item in the parent menu that has the per-channel list as a submenu */
items.push_back (MenuElem (label, *chn_menu));
} else {
/* just one channel - create a single menu item for this command+channel combination*/
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
Evoral::Parameter fully_qualified_param (auto_type, chn, cmd);
items.push_back (
CheckMenuElem (label,
sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
fully_qualified_param)));
boost::shared_ptr<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
bool visible = false;
if (track) {
if (track->marked_for_display()) {
visible = true;
}
}
Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&items.back());
_channel_command_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
/* one channel only */
break;
}
}
}
}
/** Add a single menu item for a controller on one channel. */
void
MidiTimeAxisView::add_single_channel_controller_item(Menu_Helpers::MenuList& ctl_items,
int ctl,
const std::string& name)
{
using namespace Menu_Helpers;
const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl);
ctl_items.push_back (
CheckMenuElem (
string_compose ("<b>%1</b>: %2 [%3]", ctl, name, int (chn + 1)),
sigc::bind (
sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
fully_qualified_param)));
dynamic_cast<Label*> (ctl_items.back().get_child())->set_use_markup (true);
boost::shared_ptr<AutomationTimeAxisView> track = automation_child (
fully_qualified_param);
bool visible = false;
if (track) {
if (track->marked_for_display()) {
visible = true;
}
}
Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&ctl_items.back());
_controller_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
/* one channel only */
break;
}
}
}
/** Add a submenu with 1 item per channel for a controller on many channels. */
void
MidiTimeAxisView::add_multi_channel_controller_item(Menu_Helpers::MenuList& ctl_items,
const uint16_t channels,
int ctl,
const std::string& name)
{
using namespace Menu_Helpers;
Menu* chn_menu = manage (new Menu);
MenuList& chn_items (chn_menu->items());
/* add a couple of items to hide/show this controller on all channels */
Evoral::Parameter param_without_channel (MidiCCAutomation, 0, ctl);
chn_items.push_back (
MenuElem (_("Hide all channels"),
sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility),
false, param_without_channel)));
chn_items.push_back (
MenuElem (_("Show all channels"),
sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility),
true, param_without_channel)));
for (uint8_t chn = 0; chn < 16; chn++) {
if (channels & (0x0001 << chn)) {
/* for each selected channel, add a menu item for this controller */
Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl);
chn_items.push_back (
CheckMenuElem (string_compose (_("Channel %1"), chn+1),
sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
fully_qualified_param)));
boost::shared_ptr<AutomationTimeAxisView> track = automation_child (
fully_qualified_param);
bool visible = false;
if (track) {
if (track->marked_for_display()) {
visible = true;
}
}
Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&chn_items.back());
_controller_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
}
}
/* add the per-channel menu to the list of controllers, with the name of the controller */
ctl_items.push_back (MenuElem (string_compose ("<b>%1</b>: %2", ctl, name),
*chn_menu));
dynamic_cast<Label*> (ctl_items.back().get_child())->set_use_markup (true);
}
void
MidiTimeAxisView::build_controller_menu ()
{
using namespace Menu_Helpers;
if (controller_menu) {
/* it exists and has not been invalidated by a channel mode change */
return;
}
controller_menu = new Menu; // explicitly managed by us
MenuList& items (controller_menu->items());
/* create several "top level" menu items for sets of controllers (16 at a
* time), and populate each one with a submenu for each controller+channel
* combination covering the currently selected channels for this track
*/
size_t total_ctrls = _route->instrument_info().master_controller_count ();
if (total_ctrls > 0) {
/* Controllers names available in midnam file, generate fancy menu */
using namespace MIDI::Name;
unsigned n_items = 0;
unsigned n_groups = 0;
/* keep track of CC numbers that are added */
uint16_t ctl_start = 1;
uint16_t ctl_end = 1;
MasterDeviceNames::ControlNameLists const& ctllist (_route->instrument_info().master_device_names ()->controls ());
bool per_name_list = ctllist.size () > 1;
bool to_top_level = total_ctrls < 32 && !per_name_list;
/* reverse lookup which "ChannelNameSet" has "UsesControlNameList <this list>"
* then check for which channels it is valid "AvailableForChannels"
*/
for (MasterDeviceNames::ControlNameLists::const_iterator l = ctllist.begin(); l != ctllist.end(); ++l) {
uint16_t channels = _route->instrument_info().channels_for_control_list (l->first);
bool multi_channel = 0 != (channels & (channels - 1));
boost::shared_ptr<ControlNameList> name_list = l->second;
Menu* ctl_menu = NULL;
for (ControlNameList::Controls::const_iterator c = name_list->controls().begin();
c != name_list->controls().end();) {
const uint16_t ctl = c->second->number();
/* Skip bank select controllers since they're handled specially */
if (ctl != MIDI_CTL_MSB_BANK && ctl != MIDI_CTL_LSB_BANK) {