2006-07-23 08:03:19 -04:00
/*
2019-08-02 17:26:43 -04:00
* Copyright ( C ) 2006 - 2015 David Robillard < d @ drobilla . net >
* Copyright ( C ) 2008 - 2012 Hans Baier < hansfbaier @ googlemail . com >
* Copyright ( C ) 2008 - 2017 Paul Davis < paul @ linuxaudiosystems . com >
* Copyright ( C ) 2009 - 2012 Carl Hetherington < carl @ carlh . net >
* Copyright ( C ) 2013 - 2014 John Emmas < john @ creativepost . co . uk >
* Copyright ( C ) 2013 - 2016 Tim Mayberry < mojofunk @ gmail . com >
* Copyright ( C ) 2013 - 2019 Robin Gareus < robin @ gareus . org >
* Copyright ( C ) 2014 - 2017 Ben Loftis < ben @ harrisonconsoles . com >
* Copyright ( C ) 2015 - 2017 Nick Mainsbridge < mainsbridge @ gmail . com >
*
* 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 .
*/
2006-07-23 08:03:19 -04:00
# include <cstdlib>
# include <cmath>
# include <algorithm>
# include <string>
# include <vector>
# include <sigc++/bind.h>
2017-07-16 21:48:18 -04:00
# include <gtkmm/separator.h>
# include <gtkmm/stock.h>
2009-02-25 13:26:51 -05:00
# include "pbd/error.h"
2013-07-17 06:03:34 -04:00
# include "pbd/ffs.h"
2009-02-25 13:26:51 -05:00
# include "pbd/stl_delete.h"
# include "pbd/whitespace.h"
2009-09-03 08:39:50 -04:00
# include "pbd/basename.h"
2009-02-25 13:26:51 -05:00
# include "pbd/enumwriter.h"
2009-09-03 08:39:50 -04:00
# include "pbd/memento_command.h"
2010-03-02 13:05:26 -05:00
# include "pbd/stateful_diff_command.h"
2020-09-07 00:44:47 -04:00
# include "pbd/unwind.h"
2006-07-23 08:03:19 -04:00
2022-08-10 23:11:52 -04:00
# include "gtkmm2ext/colors.h"
2010-07-16 10:55:11 -04:00
# include "gtkmm2ext/gtk_ui.h"
# include "gtkmm2ext/utils.h"
2006-07-23 08:03:19 -04:00
2017-07-15 11:38:28 -04:00
# include "widgets/tooltips.h"
2012-05-24 02:09:29 -04:00
# include "ardour/event_type_map.h"
2009-02-25 13:26:51 -05:00
# include "ardour/midi_patch_manager.h"
2011-10-19 17:53:09 -04:00
# include "ardour/midi_playlist.h"
# include "ardour/midi_region.h"
2009-09-03 08:39:50 -04:00
# include "ardour/midi_source.h"
2012-05-24 02:09:29 -04:00
# include "ardour/midi_track.h"
2011-10-19 17:53:09 -04:00
# include "ardour/operations.h"
2014-01-15 05:30:54 -05:00
# include "ardour/pannable.h"
# include "ardour/panner.h"
# include "ardour/panner_shell.h"
2009-02-25 13:26:51 -05:00
# include "ardour/playlist.h"
2016-10-29 13:28:18 -04:00
# include "ardour/plugin_insert.h"
2014-08-31 10:15:52 -04:00
# include "ardour/profile.h"
2012-05-24 02:09:29 -04:00
# include "ardour/region.h"
2009-09-03 08:39:50 -04:00
# include "ardour/region_factory.h"
2012-05-24 02:09:29 -04:00
# include "ardour/route.h"
2009-02-25 13:26:51 -05:00
# include "ardour/session.h"
2012-05-24 02:09:29 -04:00
# include "ardour/session_object.h"
# include "ardour/source.h"
# include "ardour/track.h"
# include "ardour/types.h"
2022-12-18 18:43:29 -05:00
# include "ardour/velocity_control.h"
2006-07-23 08:03:19 -04:00
2020-09-07 00:44:47 -04:00
# include "ardour_message.h"
2007-06-30 14:41:50 -04:00
# include "automation_line.h"
2009-09-03 08:39:50 -04:00
# include "automation_time_axis.h"
# include "editor.h"
2006-07-23 08:03:19 -04:00
# include "enums.h"
2009-09-03 08:39:50 -04:00
# include "ghostregion.h"
2006-07-23 08:03:19 -04:00
# include "gui_thread.h"
# include "keyboard.h"
2013-03-27 21:50:18 -04:00
# include "midi_channel_selector.h"
2009-09-03 08:39:50 -04:00
# include "midi_streamview.h"
# include "midi_region_view.h"
# include "midi_time_axis.h"
2017-03-29 17:41:10 -04:00
# include "patch_change_dialog.h"
2017-09-07 18:30:55 -04:00
# include "patch_change_widget.h"
2009-09-03 08:39:50 -04:00
# include "piano_roll_header.h"
2006-07-23 08:03:19 -04:00
# include "playlist_selector.h"
# include "plugin_selector.h"
# include "plugin_ui.h"
# include "point_selection.h"
2006-08-01 13:19:38 -04:00
# include "region_view.h"
2006-07-23 08:03:19 -04:00
# include "rgb_macros.h"
# include "selection.h"
2010-08-15 12:39:51 -04:00
# include "step_editor.h"
2013-04-04 00:32:52 -04:00
# include "note_base.h"
2006-07-23 08:03:19 -04:00
2009-02-25 13:26:51 -05:00
# include "ardour/midi_track.h"
2006-07-23 08:03:19 -04:00
2016-07-14 14:44:52 -04:00
# include "pbd/i18n.h"
2006-07-23 08:03:19 -04:00
using namespace ARDOUR ;
using namespace PBD ;
using namespace Gtk ;
2010-01-08 21:36:47 -05:00
using namespace Gtkmm2ext ;
2006-07-23 08:03:19 -04:00
using namespace Editing ;
2014-11-30 18:27:04 -05:00
using namespace std ;
2009-10-14 12:10:01 -04:00
2008-10-04 22:32:05 -04:00
// Minimum height at which a control is displayed
2014-08-31 01:12:41 -04:00
static const uint32_t MIDI_CONTROLS_BOX_MIN_HEIGHT = 160 ;
2013-03-27 21:50:18 -04:00
static const uint32_t KEYBOARD_MIN_HEIGHT = 130 ;
2006-07-23 08:03:19 -04:00
2020-02-11 15:41:44 -05:00
# define DEFAULT_MIDNAM_MODEL (X_("Generic"))
2013-04-04 00:32:52 -04:00
MidiTimeAxisView : : MidiTimeAxisView ( PublicEditor & ed , Session * sess , ArdourCanvas : : Canvas & canvas )
2016-06-05 16:07:22 -04:00
: SessionHandlePtr ( sess )
, RouteTimeAxisView ( ed , sess , canvas )
2009-10-14 12:10:01 -04:00
, _ignore_signals ( false )
2020-09-07 00:44:47 -04:00
, _asked_all_automation ( false )
2008-01-13 12:45:17 -05:00
, _piano_roll_header ( 0 )
2007-08-17 13:25:20 -04:00
, _note_mode ( Sustained )
2008-12-23 20:24:49 -05:00
, _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 )
2013-03-27 21:50:18 -04:00
, _channel_selector ( 0 )
2009-09-25 15:00:34 -04:00
, _step_edit_item ( 0 )
2010-01-08 21:36:47 -05:00
, controller_menu ( 0 )
2013-01-19 00:54:44 -05:00
, _step_editor ( 0 )
2023-06-24 18:17:41 -04:00
, velocity_menu_item ( nullptr )
2006-07-23 08:03:19 -04:00
{
2015-10-10 19:32:13 -04:00
_midnam_model_selector . disable_scrolling ( ) ;
_midnam_custom_device_mode_selector . disable_scrolling ( ) ;
2023-08-17 14:19:07 -04:00
_midnam_channel_selector . disable_scrolling ( ) ;
2023-08-18 15:48:39 -04:00
UIConfiguration : : instance ( ) . ParameterChanged . connect ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : parameter_changed ) ) ;
2023-09-13 13:53:18 -04:00
_editor . MouseModeChanged . connect_same_thread ( mouse_mode_connection , sigc : : mem_fun ( * this , & MidiTimeAxisView : : mouse_mode_changed ) ) ;
2023-08-18 15:48:39 -04:00
}
2023-09-13 13:53:18 -04:00
void
MidiTimeAxisView : : mouse_mode_changed ( )
{
_piano_roll_header - > queue_resize ( ) ;
}
2023-08-18 15:48:39 -04:00
void
MidiTimeAxisView : : parameter_changed ( string const & param )
{
if ( param = = X_ ( " note-name-display " ) ) {
if ( _piano_roll_header ) {
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2023-08-18 15:48:39 -04:00
}
}
2011-07-06 20:37:13 -04:00
}
2015-08-14 21:08:55 -04:00
void
2023-08-18 15:48:39 -04:00
MidiTimeAxisView : : set_note_highlight ( uint8_t note )
{
2015-08-14 21:08:55 -04:00
_piano_roll_header - > set_note_highlight ( note ) ;
}
2011-07-06 20:37:13 -04:00
void
2023-02-16 18:33:28 -05:00
MidiTimeAxisView : : set_route ( std : : shared_ptr < Route > rt )
2011-07-06 20:37:13 -04:00
{
2011-11-27 08:44:45 -05:00
_route = rt ;
2015-10-05 10:17:49 -04:00
2011-11-27 08:44:45 -05:00
_view = new MidiStreamView ( * this ) ;
2012-06-13 16:37:34 -04:00
2011-11-27 08:44:45 -05:00
if ( is_track ( ) ) {
_piano_roll_header = new PianoRollHeader ( * midi_view ( ) ) ;
}
/* This next call will result in our height being set up, so it must come after
2020-04-15 07:58:40 -04:00
* the creation of the piano roll / range scroomer as their visibility is set up
* when our height is .
*/
2011-07-06 20:37:13 -04:00
RouteTimeAxisView : : set_route ( rt ) ;
2022-08-10 23:11:52 -04:00
_view - > apply_color ( Gtkmm2ext : : gdk_color_to_rgba ( color ( ) ) , StreamView : : RegionColor ) ;
2011-12-26 20:42:49 -05:00
2019-07-14 12:39:50 -04:00
_note_range_changed_connection . disconnect ( ) ;
2011-08-14 14:40:57 -04:00
if ( ! gui_property ( " note-range-min " ) . empty ( ) ) {
2013-01-19 00:54:44 -05:00
midi_view ( ) - > apply_note_range ( atoi ( gui_property ( " note-range-min " ) . c_str ( ) ) ,
atoi ( gui_property ( " note-range-max " ) . c_str ( ) ) ,
true ) ;
2011-08-14 14:40:57 -04:00
}
2013-01-19 14:06:21 -05:00
2007-07-06 23:19:04 -04:00
if ( is_midi_track ( ) ) {
_note_mode = midi_track ( ) - > note_mode ( ) ;
}
2006-07-23 08:03:19 -04:00
2014-01-15 05:30:54 -05:00
/* 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 ) ;
}
2014-07-01 14:36:58 -04:00
/* 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 ) ;
}
2023-06-24 18:17:41 -04:00
if ( automation_child ( MidiVelocityAutomation ) = = 0 ) {
create_automation_child ( MidiVelocityAutomation , false ) ;
}
2014-01-15 05:30:54 -05:00
if ( _route - > panner_shell ( ) ) {
_route - > panner_shell ( ) - > Changed . connect ( * this , invalidator ( * this ) , boost : : bind ( & MidiTimeAxisView : : ensure_pan_views , this , false ) , gui_context ( ) ) ;
}
2006-07-23 08:03:19 -04:00
/* map current state of the route */
2014-01-15 05:30:54 -05:00
ensure_pan_views ( false ) ;
2016-02-11 18:25:17 -05:00
update_control_names ( ) ;
2009-11-30 18:16:28 -05:00
processors_changed ( RouteProcessorChange ( ) ) ;
2006-07-23 08:03:19 -04:00
2006-08-14 04:44:14 -04:00
if ( is_track ( ) ) {
2013-01-19 00:54:44 -05:00
_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 ) ) ;
2010-01-07 14:15:33 -05:00
2012-06-13 16:58:12 -04:00
/* Put the scroomer and the keyboard in a VBox with a padding
2020-04-15 07:58:40 -04:00
* label so that they can be reduced in height for stacked - view
* tracks .
*/
2014-08-31 10:15:52 -04:00
2014-09-08 12:43:08 -04:00
HSeparator * separator = manage ( new HSeparator ( ) ) ;
separator - > set_name ( " TrackSeparator " ) ;
separator - > set_size_request ( - 1 , 1 ) ;
separator - > show ( ) ;
2012-06-13 16:58:12 -04:00
VBox * v = manage ( new VBox ) ;
HBox * h = manage ( new HBox ) ;
2014-08-31 10:15:52 -04:00
h - > pack_end ( * _piano_roll_header ) ;
2014-09-08 12:43:08 -04:00
v - > pack_start ( * separator , false , false ) ;
2014-09-08 12:42:41 -04:00
v - > pack_start ( * h , true , true ) ;
2012-06-13 19:28:32 -04:00
v - > show ( ) ;
h - > show ( ) ;
2014-09-08 12:43:08 -04:00
top_hbox . remove ( scroomer_placeholder ) ;
2014-09-08 12:42:41 -04:00
time_axis_hbox . pack_end ( * v , false , false , 0 ) ;
2014-09-08 12:43:08 -04:00
midi_scroomer_size_group - > add_widget ( * v ) ;
2006-07-23 08:03:19 -04:00
2019-07-14 12:39:50 -04:00
/* 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 ) ) ;
2008-02-10 13:16:25 -05:00
2006-07-23 08:03:19 -04:00
/* ask for notifications of any new RegionViews */
2013-01-19 00:54:44 -05:00
_view - > RegionViewAdded . connect (
sigc : : mem_fun ( * this , & MidiTimeAxisView : : region_view_added ) ) ;
2011-06-01 13:00:29 -04:00
2010-09-26 22:04:16 -04:00
if ( ! _editor . have_idled ( ) ) {
/* first idle will do what we need */
} else {
first_idle ( ) ;
}
2007-09-05 22:30:39 -04:00
}
2009-10-14 12:10:01 -04:00
2017-07-15 11:38:28 -04:00
ArdourWidgets : : set_tooltip ( _midnam_model_selector , _ ( " External MIDI Device " ) ) ;
ArdourWidgets : : set_tooltip ( _midnam_custom_device_mode_selector , _ ( " External Device Mode " ) ) ;
2023-08-17 14:19:07 -04:00
ArdourWidgets : : set_tooltip ( _midnam_channel_selector , _ ( " MIDNAM Channel Display " ) ) ;
2012-06-11 18:59:35 -04:00
2016-10-29 13:28:18 -04:00
_midi_controls_box . pack_start ( _midnam_model_selector , false , false , 2 ) ;
_midi_controls_box . pack_start ( _midnam_custom_device_mode_selector , false , false , 2 ) ;
2023-08-17 14:19:07 -04:00
_midi_controls_box . pack_start ( _midnam_channel_selector , false , false , 2 ) ;
2016-10-29 13:28:18 -04:00
2012-10-11 04:13:40 -04:00
_midi_controls_box . set_homogeneous ( false ) ;
2014-09-09 08:39:36 -04:00
_midi_controls_box . set_border_width ( 2 ) ;
2013-01-19 11:05:06 -05:00
2020-04-02 21:42:56 -04:00
/* 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 ( ) ) ;
2013-01-19 05:02:00 -05:00
2008-12-09 03:35:02 -05:00
controls_vbox . pack_start ( _midi_controls_box , false , false ) ;
2009-10-14 12:10:01 -04:00
2013-01-19 01:17:02 -05:00
const string color_mode = gui_property ( " color-mode " ) ;
if ( ! color_mode . empty ( ) ) {
_color_mode = ColorMode ( string_2_enum ( color_mode , _color_mode ) ) ;
2013-03-27 21:50:18 -04:00
if ( _channel_selector & & _color_mode = = ChannelColors ) {
2013-04-04 00:32:52 -04:00
_channel_selector - > set_channel_colors ( NoteBase : : midi_channel_colors ) ;
2008-12-28 20:02:41 -05:00
}
}
2009-10-07 11:41:12 -04:00
2011-07-06 20:37:13 -04:00
set_color_mode ( _color_mode , true , false ) ;
2013-01-19 01:17:02 -05:00
const string note_mode = gui_property ( " note-mode " ) ;
if ( ! note_mode . empty ( ) ) {
_note_mode = NoteMode ( string_2_enum ( note_mode , _note_mode ) ) ;
2009-10-22 12:10:21 -04:00
if ( _percussion_mode_item ) {
2009-10-07 11:41:12 -04:00
_percussion_mode_item - > set_active ( _note_mode = = Percussive ) ;
}
}
2011-07-13 13:13:30 -04:00
2013-01-19 00:54:44 -05:00
/* Look for any GUI object state nodes that represent automation children
* that should exist , and create the children .
2011-07-13 13:13:30 -04:00
*/
2012-01-20 13:02:43 -05:00
2013-01-19 01:17:02 -05:00
const list < string > gui_ids = gui_object_state ( ) . all_ids ( ) ;
2012-01-20 13:02:43 -05:00
for ( list < string > : : const_iterator i = gui_ids . begin ( ) ; i ! = gui_ids . end ( ) ; + + i ) {
2011-07-13 13:13:30 -04:00
PBD : : ID route_id ;
bool has_parameter ;
Evoral : : Parameter parameter ( 0 , 0 , 0 ) ;
2023-08-18 13:45:21 -04:00
bool const p = AutomationTimeAxisView : : parse_state_id ( * i , route_id , has_parameter , parameter ) ;
2011-07-13 13:13:30 -04:00
if ( p & & route_id = = _route - > id ( ) & & has_parameter ) {
2013-01-19 00:54:44 -05:00
const std : : string & visible = gui_object_state ( ) . get_string ( * i , X_ ( " visible " ) ) ;
2016-08-30 08:34:40 -04:00
create_automation_child ( parameter , string_to < bool > ( visible ) ) ;
2011-07-13 13:13:30 -04:00
}
}
2023-08-18 13:45:21 -04:00
2023-08-17 14:19:07 -04:00
//Menu_Helpers::MenuElem elem = Gtk::Menu_Helpers::MenuElem(_("Plugin Provided"),
// sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::model_changed),
// model_name));
for ( int i = 1 ; i < 17 ; i + + ) {
2023-08-18 17:22:51 -04:00
std : : string text = string_compose ( " %1 %2 " , _ ( " Channel " ) , i ) ;
2023-08-18 13:45:21 -04:00
_midnam_channel_selector . append_text_item ( text ) ;
2023-08-17 14:19:07 -04:00
}
_midnam_channel_selector . StateChanged . connect ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : _midnam_channel_changed ) ) ;
if ( gui_property ( X_ ( " midnam-channel " ) ) . empty ( ) ) {
2023-08-18 17:22:51 -04:00
std : : string str = string_compose ( " %1 1 " , _ ( " Channel " ) ) ;
set_gui_property ( X_ ( " midnam-channel " ) , str ) ;
_midnam_channel_selector . set_active ( str ) ;
2023-08-17 14:19:07 -04:00
} else {
2023-08-18 17:22:51 -04:00
_midnam_channel_selector . set_active ( gui_property ( X_ ( " midnam-channel " ) ) ) ;
2023-08-17 14:19:07 -04:00
}
}
void
MidiTimeAxisView : : _midnam_channel_changed ( )
{
set_gui_property ( X_ ( " midnam-channel " ) , _midnam_channel_selector . get_text ( ) ) ;
//std::cout << "midnam_changed(): " << _midnam_channel_selector.get_text() << std::endl;
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2006-07-23 08:03:19 -04:00
}
2010-09-26 22:04:16 -04:00
void
MidiTimeAxisView : : first_idle ( )
{
if ( is_track ( ) ) {
_view - > attach ( ) ;
}
}
2006-07-23 08:03:19 -04:00
MidiTimeAxisView : : ~ MidiTimeAxisView ( )
{
2013-03-27 21:50:18 -04:00
delete _channel_selector ;
2008-02-21 20:45:29 -05:00
delete _piano_roll_header ;
_piano_roll_header = 0 ;
2008-02-10 13:16:25 -05:00
2010-01-07 14:15:33 -05:00
delete controller_menu ;
2013-01-19 00:54:44 -05:00
delete _step_editor ;
2006-07-23 08:03:19 -04:00
}
2010-07-27 11:42:14 -04:00
void
2010-08-15 12:39:51 -04:00
MidiTimeAxisView : : check_step_edit ( )
2010-07-27 11:42:14 -04:00
{
2011-02-12 07:29:20 -05:00
ensure_step_editor ( ) ;
2013-01-19 00:54:44 -05:00
_step_editor - > check_step_edit ( ) ;
2010-07-27 11:42:14 -04:00
}
2020-04-03 08:39:03 -04:00
void
MidiTimeAxisView : : processors_changed ( RouteProcessorChange c )
{
RouteTimeAxisView : : processors_changed ( c ) ;
maybe_trigger_model_change ( ) ;
2023-08-17 14:19:07 -04:00
update_patch_selector ( ) ;
2020-04-03 08:39:03 -04:00
}
2019-12-23 12:26:33 -05:00
void
MidiTimeAxisView : : use_midnam_info ( )
{
2020-04-14 19:50:01 -04:00
/* Rebuild controller menu */
_controller_menu_map . clear ( ) ;
delete controller_menu ;
controller_menu = 0 ;
2019-12-23 12:26:33 -05:00
setup_midnam_patches ( ) ;
2020-04-14 20:38:18 -04:00
/* 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 ;
}
}
2019-12-23 12:26:33 -05:00
}
2020-04-03 08:39:03 -04:00
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 ( ) ;
}
}
}
2016-10-29 13:28:18 -04:00
void
MidiTimeAxisView : : setup_midnam_patches ( )
{
typedef MIDI : : Name : : MidiPatchManager PatchManager ;
PatchManager & patch_manager = PatchManager : : instance ( ) ;
_midnam_model_selector . clear_items ( ) ;
2019-11-12 11:00:50 -05:00
2020-04-01 00:58:00 -04:00
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 ) ;
2019-11-12 11:00:50 -05:00
}
2020-02-06 16:41:20 -05:00
for ( PatchManager : : DeviceNamesByMaker : : const_iterator m = patch_manager . devices_by_manufacturer ( ) . begin ( ) ; m ! = patch_manager . devices_by_manufacturer ( ) . end ( ) ; + + m ) {
2016-10-29 13:28:18 -04:00
Menu * menu = Gtk : : manage ( new Menu ) ;
Menu_Helpers : : MenuList & items = menu - > items ( ) ;
2020-04-03 08:39:03 -04:00
/* Build manufacturer submenu */
2020-02-06 16:41:20 -05:00
for ( MIDI : : Name : : MIDINameDocument : : MasterDeviceNamesList : : const_iterator n = m - > second . begin ( ) ; n ! = m - > second . end ( ) ; + + n ) {
2019-11-12 00:29:05 -05:00
if ( patch_manager . is_custom_model ( n - > first ) ) {
continue ;
}
2016-10-29 13:28:18 -04:00
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 ) ;
}
2019-11-12 00:29:05 -05:00
if ( items . empty ( ) ) {
delete menu ;
continue ;
}
2016-10-29 13:28:18 -04:00
2020-04-03 08:39:03 -04:00
/* Add manufacturer submenu to selector */
2016-10-29 13:28:18 -04:00
_midnam_model_selector . AddMenuElem ( Menu_Helpers : : MenuElem ( m - > first , * menu ) ) ;
}
2020-04-02 21:42:56 -04:00
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
*/
2020-04-01 00:58:00 -04:00
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 ( " " ) ;
2020-04-07 08:16:53 -04:00
} else if ( model . empty ( ) | | ! MIDI : : Name : : MidiPatchManager : : instance ( ) . master_device_by_model ( model ) ) {
/* invalid model, switch to use default */
2020-04-01 00:58:00 -04:00
model_changed ( " " ) ;
2020-04-02 21:42:56 -04:00
} else {
model_changed ( model ) ;
2016-10-29 13:28:18 -04:00
}
2023-08-17 14:19:07 -04:00
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2023-08-17 14:19:07 -04:00
}
void
MidiTimeAxisView : : update_patch_selector ( )
{
typedef MIDI : : Name : : MidiPatchManager PatchManager ;
PatchManager & patch_manager = PatchManager : : instance ( ) ;
if ( _route ) {
std : : shared_ptr < PluginInsert > pi = std : : dynamic_pointer_cast < PluginInsert > ( _route - > the_instrument ( ) ) ;
if ( pi & & pi - > plugin ( ) - > has_midnam ( ) ) {
std : : string model_name = pi - > plugin ( ) - > midnam_model ( ) ;
if ( gui_property ( X_ ( " midnam-model-name " ) ) ! = model_name ) {
/* ensure that "Plugin Provided" is prefixed at the top of the list */
if ( _midnam_model_selector . items ( ) . empty ( ) | | _midnam_model_selector . items ( ) . begin ( ) - > get_label ( ) ! = _ ( " Plugin Provided " ) ) {
setup_midnam_patches ( ) ;
}
}
}
}
if ( patch_manager . all_models ( ) . empty ( ) ) {
_midnam_model_selector . hide ( ) ;
_midnam_custom_device_mode_selector . hide ( ) ;
_midnam_channel_selector . hide ( ) ;
} else {
_midnam_model_selector . show ( ) ;
_midnam_channel_selector . show ( ) ;
if ( _midnam_custom_device_mode_selector . items ( ) . size ( ) > 1 ) {
_midnam_custom_device_mode_selector . show ( ) ;
}
}
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2023-08-17 14:19:07 -04:00
/* 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 ) ;
}
2016-10-29 13:28:18 -04:00
}
2011-06-01 13:00:29 -04:00
void
2020-02-11 15:41:44 -05:00
MidiTimeAxisView : : model_changed ( const std : : string & m )
2008-12-11 03:06:27 -05:00
{
2019-11-12 11:00:50 -05:00
typedef MIDI : : Name : : MidiPatchManager PatchManager ;
PatchManager & patch_manager = PatchManager : : instance ( ) ;
2020-04-01 00:58:00 -04:00
2020-02-11 15:41:44 -05:00
std : : string model ( m ) ;
2020-04-01 00:58:00 -04:00
bool save_model = m ! = " " ;
if ( model . empty ( ) & & ! _route - > instrument_info ( ) . have_custom_plugin_info ( ) ) {
model = DEFAULT_MIDNAM_MODEL ;
}
2020-02-11 15:41:44 -05:00
std : : list < std : : string > device_modes = patch_manager . custom_device_mode_names_by_model ( model ) ;
if ( device_modes . empty ( ) ) {
2020-02-20 02:26:29 -05:00
save_model = false ;
2020-04-01 00:58:00 -04:00
if ( _route - > instrument_info ( ) . have_custom_plugin_info ( ) ) {
model = " " ;
} else {
model = DEFAULT_MIDNAM_MODEL ;
}
2020-02-11 15:41:44 -05:00
device_modes = patch_manager . custom_device_mode_names_by_model ( model ) ;
}
2019-11-12 11:00:50 -05:00
2020-04-01 00:58:00 -04:00
if ( model = = " " ) {
2020-02-06 16:43:41 -05:00
_midnam_model_selector . set_text ( _ ( " Plugin Provided " ) ) ;
2019-11-12 11:00:50 -05:00
} else {
2020-04-01 00:58:00 -04:00
_midnam_model_selector . set_text ( model ) ;
2019-11-12 11:00:50 -05:00
}
2020-02-07 14:19:57 -05:00
2020-04-01 00:58:00 -04:00
if ( save_model ) {
set_gui_property ( X_ ( " midnam-model-name " ) , model ) ;
} else {
remove_gui_property ( X_ ( " midnam-model-name " ) ) ;
}
2009-10-14 12:10:01 -04:00
2020-04-02 21:42:56 -04:00
/* set new mode */
2020-04-07 08:16:53 -04:00
const std : : string current_mode = gui_property ( X_ ( " midnam-custom-device-mode " ) ) ;
2020-04-02 21:42:56 -04:00
std : : string mode ;
2020-04-01 00:58:00 -04:00
if ( find ( device_modes . begin ( ) , device_modes . end ( ) , current_mode ) = = device_modes . end ( ) ) {
if ( device_modes . size ( ) > 0 ) {
2020-04-02 21:42:56 -04:00
mode = device_modes . front ( ) ;
2020-05-03 14:48:06 -04:00
if ( save_model ) {
custom_device_mode_changed ( device_modes . front ( ) ) ;
}
2020-02-11 15:41:44 -05:00
} else {
2020-04-02 21:42:56 -04:00
mode = " " ;
2020-02-07 14:19:27 -05:00
}
2020-04-01 00:58:00 -04:00
} else {
2020-04-02 21:42:56 -04:00
mode = current_mode ;
}
/* set backend state */
_route - > instrument_info ( ) . set_external_instrument ( model , mode ) ;
2020-04-03 08:39:03 -04:00
/* query effective model/mode -- may be plugin provided */
2020-04-02 21:42:56 -04:00
if ( _effective_model = = _route - > instrument_info ( ) . model ( ) & & _effective_mode = = _route - > instrument_info ( ) . mode ( ) ) {
/* no change */
return ;
}
_effective_model = _route - > instrument_info ( ) . model ( ) ;
2020-04-03 08:39:03 -04:00
_effective_mode = _route - > instrument_info ( ) . mode ( ) ;
2020-04-02 21:42:56 -04:00
/* 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 ) ) ) ;
2014-12-12 23:38:41 -05:00
}
if ( device_modes . size ( ) > 1 ) {
_midnam_custom_device_mode_selector . show ( ) ;
} else {
_midnam_custom_device_mode_selector . hide ( ) ;
}
2020-04-02 21:42:56 -04:00
/* set _midnam_custom_device_mode_selector */
custom_device_mode_changed ( mode ) ;
2020-03-31 18:51:01 -04:00
2020-04-02 21:42:56 -04:00
/* Rebuild controller menu */
2013-01-19 01:17:02 -05:00
_controller_menu_map . clear ( ) ;
delete controller_menu ;
controller_menu = 0 ;
2017-09-08 13:37:48 -04:00
2017-09-09 12:25:36 -04:00
if ( patch_change_dialog ( ) ) {
patch_change_dialog ( ) - > refresh ( ) ;
2017-09-08 13:37:48 -04:00
}
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2008-12-11 03:06:27 -05:00
}
2012-06-02 10:53:34 -04:00
void
2014-12-12 23:38:41 -05:00
MidiTimeAxisView : : custom_device_mode_changed ( const std : : string & mode )
2008-12-11 03:06:27 -05:00
{
2014-12-12 23:38:41 -05:00
const std : : string model = gui_property ( X_ ( " midnam-model-name " ) ) ;
2012-10-12 05:25:55 -04:00
set_gui_property ( X_ ( " midnam-custom-device-mode " ) , mode ) ;
2020-02-11 15:41:44 -05:00
_midnam_custom_device_mode_selector . set_text ( mode ) ;
2020-05-03 14:48:06 -04:00
if ( model . empty ( ) & & ! mode . empty ( ) ) {
/* model.empty () && model.empty () -> plugin provided
* otherwise at least a model must be set . */
return ;
}
2020-03-31 18:51:01 -04:00
/* inform the backend, route owned instrument info */
2014-12-12 23:38:41 -05:00
_route - > instrument_info ( ) . set_external_instrument ( model , mode ) ;
2023-08-17 14:19:07 -04:00
2023-08-18 17:22:51 -04:00
_piano_roll_header - > instrument_info_change ( ) ;
2008-12-11 03:06:27 -05:00
}
2007-07-05 03:02:24 -04:00
MidiStreamView *
MidiTimeAxisView : : midi_view ( )
{
return dynamic_cast < MidiStreamView * > ( _view ) ;
}
2020-07-10 12:16:18 -04:00
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 ( ) ;
}
}
2008-09-27 14:07:37 -04:00
void
2022-04-05 22:50:44 -04:00
MidiTimeAxisView : : set_height ( uint32_t h , TrackHeightMode m , bool from_idle )
2008-09-27 14:07:37 -04:00
{
2020-07-10 12:16:18 -04:00
update_midi_controls_visibility ( h ) ;
2011-11-27 08:44:40 -05:00
if ( h > = MIDI_CONTROLS_BOX_MIN_HEIGHT ) {
2013-01-19 00:36:43 -05:00
_midi_controls_box . show ( ) ;
2008-10-04 22:32:05 -04:00
} else {
2008-12-09 03:35:02 -05:00
_midi_controls_box . hide ( ) ;
2008-10-04 22:32:05 -04:00
}
2015-10-05 10:17:49 -04:00
2022-03-28 19:30:29 -04:00
update_scroomer_visbility ( h , layer_display ( ) ) ;
/* 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 .
*/
2022-04-05 22:50:44 -04:00
RouteTimeAxisView : : set_height ( h , m , from_idle ) ;
2022-03-28 19:30:29 -04:00
}
void
MidiTimeAxisView : : update_scroomer_visbility ( uint32_t h , LayerDisplay d )
{
if ( ! is_track ( ) ) {
return ;
}
if ( h > = KEYBOARD_MIN_HEIGHT & & d = = Overlaid ) {
if ( _piano_roll_header ) {
2008-09-27 14:07:37 -04:00
_piano_roll_header - > show ( ) ;
2011-07-07 09:15:53 -04:00
}
2008-09-27 14:07:37 -04:00
} else {
2022-03-28 19:30:29 -04:00
if ( _piano_roll_header ) {
2008-09-27 14:07:37 -04:00
_piano_roll_header - > hide ( ) ;
2011-07-07 09:15:53 -04:00
}
2008-09-27 14:07:37 -04:00
}
2022-03-28 19:30:29 -04:00
}
2011-11-27 08:44:40 -05:00
2022-03-28 19:30:29 -04:00
void
MidiTimeAxisView : : set_layer_display ( LayerDisplay d )
{
LayerDisplay prev_layer_display = layer_display ( ) ;
RouteTimeAxisView : : set_layer_display ( d ) ;
LayerDisplay curr_layer_display = layer_display ( ) ;
if ( curr_layer_display = = prev_layer_display ) {
return ;
}
uint32_t h = current_height ( ) ;
update_scroomer_visbility ( h , curr_layer_display ) ;
2022-04-25 18:25:26 -04:00
/* If visibility changed, trigger a call to Editor::reset_controls_layout_width()
* by forcing a redraw via Editor : : queue_redisplay_track_views ( )
*/
_stripable - > gui_changed ( " visible_tracks " , ( void * ) 0 ) ; /* EMIT SIGNAL */
2008-09-27 14:07:37 -04:00
}
2007-07-14 21:56:11 -04:00
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 " ) ;
2009-10-14 12:10:01 -04:00
2013-01-19 00:54:44 -05:00
range_items . push_back (
MenuElem ( _ ( " Show Full Range " ) ,
2015-10-04 14:51:05 -04:00
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_note_range ) ,
2013-01-19 00:54:44 -05:00
MidiStreamView : : FullRange , true ) ) ) ;
2009-10-14 12:10:01 -04:00
2013-01-19 00:54:44 -05:00
range_items . push_back (
MenuElem ( _ ( " Fit Contents " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_note_range ) ,
MidiStreamView : : ContentsRange , true ) ) ) ;
2007-07-14 21:56:11 -04:00
2011-05-16 18:22:57 -04:00
items . push_back ( MenuElem ( _ ( " Note Range " ) , * range_menu ) ) ;
items . push_back ( MenuElem ( _ ( " Note Mode " ) , * build_note_mode_menu ( ) ) ) ;
2017-09-08 12:09:26 -04:00
items . push_back ( MenuElem ( _ ( " Channel Selector... " ) ,
2013-03-27 21:50:18 -04:00
sigc : : mem_fun ( * this , & MidiTimeAxisView : : toggle_channel_selector ) ) ) ;
2009-09-25 15:00:34 -04:00
2017-09-08 12:09:26 -04:00
items . push_back ( MenuElem ( _ ( " Patch Selector... " ) ,
2017-09-09 12:25:36 -04:00
sigc : : mem_fun ( * this , & RouteUI : : select_midi_patch ) ) ) ;
2016-12-06 12:48:36 -05:00
2021-07-12 21:29:07 -04:00
items . push_back ( CheckMenuElem ( _ ( " Restore Patch " ) ) ) ;
Gtk : : CheckMenuItem * cmi = dynamic_cast < Gtk : : CheckMenuItem * > ( & items . back ( ) ) ;
cmi - > set_active ( midi_track ( ) - > restore_pgm_on_load ( ) ) ;
cmi - > signal_activate ( ) . connect ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : toggle_restore_pgm_on_load ) ) ;
2019-03-07 10:40:16 -05:00
items . push_back ( MenuElem ( _ ( " Color Mode " ) , * build_color_mode_menu ( ) ) ) ;
2015-10-05 10:17:49 -04:00
2011-02-20 19:16:36 -05:00
items . push_back ( SeparatorElem ( ) ) ;
2009-09-25 15:00:34 -04:00
}
2021-07-12 21:29:07 -04:00
void
MidiTimeAxisView : : toggle_restore_pgm_on_load ( )
{
midi_track ( ) - > set_restore_pgm_on_load ( ! midi_track ( ) - > restore_pgm_on_load ( ) ) ;
}
2013-03-27 21:50:18 -04:00
void
MidiTimeAxisView : : toggle_channel_selector ( )
{
if ( ! _channel_selector ) {
_channel_selector = new MidiChannelSelectorWindow ( midi_track ( ) ) ;
if ( _color_mode = = ChannelColors ) {
2013-04-04 00:32:52 -04:00
_channel_selector - > set_channel_colors ( NoteBase : : midi_channel_colors ) ;
2013-03-27 21:50:18 -04:00
} else {
_channel_selector - > set_default_channel_color ( ) ;
}
_channel_selector - > show_all ( ) ;
} else {
_channel_selector - > cycle_visibility ( ) ;
}
}
2006-07-23 08:03:19 -04:00
void
2011-03-07 08:04:36 -05:00
MidiTimeAxisView : : build_automation_action_menu ( bool for_selection )
2006-07-23 08:03:19 -04:00
{
2007-06-27 11:51:50 -04:00
using namespace Menu_Helpers ;
2010-05-16 14:04:47 -04:00
/* If we have a controller menu, we need to detach it before
2020-04-15 07:58:40 -04:00
* 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.
*/
2011-06-01 13:00:29 -04:00
2010-05-16 14:04:47 -04:00
if ( controller_menu ) {
detach_menu ( * controller_menu ) ;
}
2010-06-08 17:48:38 -04:00
_channel_command_menu_map . clear ( ) ;
2011-03-07 08:04:36 -05:00
RouteTimeAxisView : : build_automation_action_menu ( for_selection ) ;
2007-06-27 11:51:50 -04:00
MenuList & automation_items = automation_action_menu - > items ( ) ;
2011-06-01 13:00:29 -04:00
2013-03-27 21:50:18 -04:00
uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2009-10-14 12:10:01 -04:00
2023-06-24 18:17:41 -04:00
automation_items . push_back ( CheckMenuElem ( _ ( " Velocity " ) , sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : toggle_automation_track ) , MidiVelocityAutomation ) ) ) ;
velocity_menu_item = dynamic_cast < Gtk : : CheckMenuItem * > ( & automation_items . back ( ) ) ;
velocity_menu_item - > set_active ( string_to < bool > ( velocity_track - > gui_property ( " visible " ) ) ) ;
2020-04-15 07:58:40 -04:00
if ( selected_channels ! = 0 ) {
2010-01-08 21:36:47 -05:00
automation_items . push_back ( SeparatorElem ( ) ) ;
2023-06-24 18:17:41 -04:00
/* these 2 MIDI "command" types are semantically more like automation
2020-04-15 07:58:40 -04:00
* 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 .
*/
2013-01-19 00:54:44 -05:00
2020-04-15 07:58:40 -04:00
add_channel_command_menu_item ( automation_items , _ ( " Bender " ) , MidiPitchBenderAutomation , 0 ) ;
automation_items . back ( ) . set_sensitive ( ! for_selection | | _editor . get_selection ( ) . tracks . size ( ) = = 1 ) ;
2011-06-01 13:00:29 -04:00
2020-04-15 07:58:40 -04:00
add_channel_command_menu_item ( automation_items , _ ( " Pressure " ) , MidiChannelPressureAutomation , 0 ) ;
automation_items . back ( ) . set_sensitive ( ! for_selection | | _editor . get_selection ( ) . tracks . size ( ) = = 1 ) ;
2011-06-01 13:00:29 -04:00
2020-04-15 07:58:40 -04:00
/* 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 ( ) ;
2010-01-08 21:36:47 -05:00
automation_items . push_back ( MenuElem ( _ ( " Controllers " ) , * controller_menu ) ) ;
2016-08-24 17:38:25 -04:00
2020-04-15 09:37:54 -04:00
add_channel_command_menu_item ( automation_items , _ ( " Polyphonic Pressure " ) , MidiNotePressureAutomation , 0 ) ;
automation_items . back ( ) . set_sensitive ( ! for_selection | | _editor . get_selection ( ) . tracks . size ( ) = = 1 ) ;
2016-08-24 17:38:25 -04:00
2010-01-08 21:36:47 -05:00
} else {
2013-01-19 00:54:44 -05:00
automation_items . push_back (
MenuElem ( string_compose ( " <i>%1</i> " , _ ( " No MIDI Channels selected " ) ) ) ) ;
2011-02-17 11:43:30 -05:00
dynamic_cast < Label * > ( automation_items . back ( ) . get_child ( ) ) - > set_use_markup ( true ) ;
2010-01-08 21:36:47 -05:00
}
}
2010-01-06 16:56:23 -05:00
2010-01-08 21:36:47 -05:00
void
MidiTimeAxisView : : change_all_channel_tracks_visibility ( bool yn , Evoral : : Parameter param )
{
2013-03-27 21:50:18 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
for ( uint8_t chn = 0 ; chn < 16 ; chn + + ) {
if ( selected_channels & ( 0x0001 < < chn ) ) {
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
Evoral : : Parameter fully_qualified_param ( param . type ( ) , chn , param . id ( ) ) ;
2010-05-25 10:50:45 -04:00
Gtk : : CheckMenuItem * menu = automation_child_menu_item ( fully_qualified_param ) ;
2010-01-07 14:15:33 -05:00
2010-05-25 10:50:45 -04:00
if ( menu ) {
menu - > set_active ( yn ) ;
2010-01-08 21:36:47 -05:00
}
}
}
}
void
2013-01-19 00:54:44 -05:00
MidiTimeAxisView : : add_channel_command_menu_item ( Menu_Helpers : : MenuList & items ,
const string & label ,
AutomationType auto_type ,
uint8_t cmd )
2010-01-08 21:36:47 -05:00
{
using namespace Menu_Helpers ;
2013-01-19 00:54:44 -05:00
/* count the number of selected channels because we will build a different menu
2020-04-15 07:58:40 -04:00
* structure if there is more than 1 selected .
2010-01-08 21:36:47 -05:00
*/
2010-01-07 14:15:33 -05:00
2013-03-27 21:50:18 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2010-01-08 21:36:47 -05:00
int chn_cnt = 0 ;
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
for ( uint8_t chn = 0 ; chn < 16 ; chn + + ) {
if ( selected_channels & ( 0x0001 < < chn ) ) {
if ( + + chn_cnt > 1 ) {
break ;
2010-01-07 14:15:33 -05:00
}
}
2010-01-08 21:36:47 -05:00
}
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
if ( chn_cnt > 1 ) {
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
/* multiple channels - create a submenu, with 1 item per channel */
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
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 */
2013-01-19 00:54:44 -05:00
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 ) ) ) ;
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
for ( uint8_t chn = 0 ; chn < 16 ; chn + + ) {
if ( selected_channels & ( 0x0001 < < chn ) ) {
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
/* for each selected channel, add a menu item for this controller */
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
Evoral : : Parameter fully_qualified_param ( auto_type , chn , cmd ) ;
2013-01-19 00:54:44 -05:00
chn_items . push_back (
CheckMenuElem ( string_compose ( _ ( " Channel %1 " ) , chn + 1 ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & RouteTimeAxisView : : toggle_automation_track ) ,
fully_qualified_param ) ) ) ;
2011-06-01 13:00:29 -04:00
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track = automation_child ( fully_qualified_param ) ;
2010-01-08 21:36:47 -05:00
bool visible = false ;
2011-06-01 13:00:29 -04:00
2010-05-25 10:50:45 -04:00
if ( track ) {
if ( track - > marked_for_display ( ) ) {
2010-01-08 21:36:47 -05:00
visible = true ;
}
}
2010-06-08 17:48:38 -04:00
2013-07-11 15:32:31 -04:00
Gtk : : CheckMenuItem * cmi = static_cast < Gtk : : CheckMenuItem * > ( & chn_items . back ( ) ) ;
2010-06-08 17:48:38 -04:00
_channel_command_menu_map [ fully_qualified_param ] = cmi ;
2010-01-08 21:36:47 -05:00
cmi - > set_active ( visible ) ;
}
}
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
/* now create an item in the parent menu that has the per-channel list as a submenu */
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
items . push_back ( MenuElem ( label , * chn_menu ) ) ;
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
} else {
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
/* just one channel - create a single menu item for this command+channel combination*/
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
for ( uint8_t chn = 0 ; chn < 16 ; chn + + ) {
if ( selected_channels & ( 0x0001 < < chn ) ) {
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
Evoral : : Parameter fully_qualified_param ( auto_type , chn , cmd ) ;
2013-01-19 00:54:44 -05:00
items . push_back (
CheckMenuElem ( label ,
sigc : : bind ( sigc : : mem_fun ( * this , & RouteTimeAxisView : : toggle_automation_track ) ,
fully_qualified_param ) ) ) ;
2011-06-01 13:00:29 -04:00
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track = automation_child ( fully_qualified_param ) ;
2010-01-08 21:36:47 -05:00
bool visible = false ;
2011-06-01 13:00:29 -04:00
2010-05-25 10:50:45 -04:00
if ( track ) {
if ( track - > marked_for_display ( ) ) {
2010-01-08 21:36:47 -05:00
visible = true ;
}
}
2011-06-01 13:00:29 -04:00
2013-07-11 15:32:31 -04:00
Gtk : : CheckMenuItem * cmi = static_cast < Gtk : : CheckMenuItem * > ( & items . back ( ) ) ;
2010-06-08 17:48:38 -04:00
_channel_command_menu_map [ fully_qualified_param ] = cmi ;
2010-01-08 21:36:47 -05:00
cmi - > set_active ( visible ) ;
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
/* one channel only */
break ;
}
}
2010-01-07 14:15:33 -05:00
}
}
2013-01-19 05:02:00 -05:00
/** 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 ;
2013-03-27 21:50:18 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2013-01-19 05:02:00 -05:00
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 (
2014-07-14 00:03:04 -04:00
string_compose ( " <b>%1</b>: %2 [%3] " , ctl , name , int ( chn + 1 ) ) ,
2013-01-19 05:02:00 -05:00
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 ) ;
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track = automation_child (
2013-01-19 05:02:00 -05:00
fully_qualified_param ) ;
bool visible = false ;
if ( track ) {
if ( track - > marked_for_display ( ) ) {
visible = true ;
}
}
2013-07-19 04:41:34 -04:00
Gtk : : CheckMenuItem * cmi = static_cast < Gtk : : CheckMenuItem * > ( & ctl_items . back ( ) ) ;
2013-01-19 05:02:00 -05:00
_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 ,
2020-04-14 19:41:17 -04:00
const uint16_t channels ,
2013-01-19 05:02:00 -05:00
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 + + ) {
2020-04-14 19:41:17 -04:00
if ( channels & ( 0x0001 < < chn ) ) {
2013-01-19 05:02:00 -05:00
/* 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 ) ) ) ;
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track = automation_child (
2013-01-19 05:02:00 -05:00
fully_qualified_param ) ;
bool visible = false ;
if ( track ) {
if ( track - > marked_for_display ( ) ) {
visible = true ;
}
}
2013-07-19 04:41:34 -04:00
Gtk : : CheckMenuItem * cmi = static_cast < Gtk : : CheckMenuItem * > ( & chn_items . back ( ) ) ;
2013-01-19 05:02:00 -05:00
_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 ) ;
}
2010-01-07 14:15:33 -05:00
void
MidiTimeAxisView : : build_controller_menu ( )
{
using namespace Menu_Helpers ;
2010-01-08 21:36:47 -05:00
if ( controller_menu ) {
2013-01-19 00:54:44 -05:00
/* it exists and has not been invalidated by a channel mode change */
2010-01-08 21:36:47 -05:00
return ;
}
controller_menu = new Menu ; // explicitly managed by us
2010-01-07 14:15:33 -05:00
MenuList & items ( controller_menu - > items ( ) ) ;
2013-01-19 00:54:44 -05:00
/* create several "top level" menu items for sets of controllers (16 at a
2020-04-14 19:41:17 -04:00
* time ) , and populate each one with a submenu for each controller + channel
* combination covering the currently selected channels for this track
*/
2011-06-01 13:00:29 -04:00
2020-04-01 17:26:13 -04:00
size_t total_ctrls = _route - > instrument_info ( ) . master_controller_count ( ) ;
if ( total_ctrls > 0 ) {
2020-04-14 19:41:17 -04:00
/* Controllers names available in midnam file, generate fancy menu */
2020-04-01 17:26:13 -04:00
using namespace MIDI : : Name ;
2013-01-16 03:24:31 -05:00
2013-01-19 05:02:00 -05:00
unsigned n_items = 0 ;
unsigned n_groups = 0 ;
2013-01-20 03:56:00 -05:00
2019-06-04 17:51:50 -04:00
/* keep track of CC numbers that are added */
uint16_t ctl_start = 1 ;
uint16_t ctl_end = 1 ;
2020-04-01 17:26:13 -04:00
MasterDeviceNames : : ControlNameLists const & ctllist ( _route - > instrument_info ( ) . master_device_names ( ) - > controls ( ) ) ;
2019-06-04 17:51:50 -04:00
2020-04-14 19:41:17 -04:00
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 "
*/
2019-06-04 17:51:50 -04:00
for ( MasterDeviceNames : : ControlNameLists : : const_iterator l = ctllist . begin ( ) ; l ! = ctllist . end ( ) ; + + l ) {
2020-04-14 19:41:17 -04:00
uint16_t channels = _route - > instrument_info ( ) . channels_for_control_list ( l - > first ) ;
bool multi_channel = 0 ! = ( channels & ( channels - 1 ) ) ;
2023-02-16 18:33:28 -05:00
std : : shared_ptr < ControlNameList > name_list = l - > second ;
2013-01-19 05:02:00 -05:00
Menu * ctl_menu = NULL ;
2015-10-05 10:17:49 -04:00
2013-01-20 03:56:00 -05:00
for ( ControlNameList : : Controls : : const_iterator c = name_list - > controls ( ) . begin ( ) ;
2013-01-26 17:08:06 -05:00
c ! = name_list - > controls ( ) . end ( ) ; ) {
2020-04-14 19:41:17 -04:00
2013-01-20 03:56:00 -05:00
const uint16_t ctl = c - > second - > number ( ) ;
2019-06-04 17:51:50 -04:00
/* Skip bank select controllers since they're handled specially */
2013-01-26 17:30:34 -05:00
if ( ctl ! = MIDI_CTL_MSB_BANK & & ctl ! = MIDI_CTL_LSB_BANK ) {
2019-06-04 17:51:50 -04:00
if ( to_top_level ) {
ctl_menu = controller_menu ;
} else if ( ! ctl_menu ) {
2013-01-26 17:30:34 -05:00
/* Create a new submenu */
ctl_menu = manage ( new Menu ) ;
2019-06-04 17:51:50 -04:00
ctl_start = ctl ;
2013-01-26 17:30:34 -05:00
}
2015-10-05 10:17:49 -04:00
2013-01-26 17:30:34 -05:00
MenuList & ctl_items ( ctl_menu - > items ( ) ) ;
2020-04-14 19:41:17 -04:00
if ( multi_channel ) {
add_multi_channel_controller_item ( ctl_items , channels , ctl , c - > second - > name ( ) ) ;
2013-01-26 17:30:34 -05:00
} else {
add_single_channel_controller_item ( ctl_items , ctl , c - > second - > name ( ) ) ;
}
2019-06-04 17:51:50 -04:00
ctl_end = ctl ;
2013-01-19 05:02:00 -05:00
}
2013-01-26 17:08:06 -05:00
+ + c ;
2019-06-04 17:51:50 -04:00
if ( ! ctl_menu | | to_top_level ) {
continue ;
}
if ( + + n_items = = 32 | | ctl < ctl_start | | c = = name_list - > controls ( ) . end ( ) ) {
/* Submenu has 32 items or we're done, or a new name-list started:
* add it to controller menu and reset */
2020-04-14 19:41:17 -04:00
items . push_back ( MenuElem ( string_compose ( " %1 %2-%3 " ,
( per_name_list ? l - > first . c_str ( ) : _ ( " Controllers " ) ) ,
ctl_start , ctl_end ) , * ctl_menu ) ) ;
2013-01-19 05:02:00 -05:00
ctl_menu = NULL ;
n_items = 0 ;
+ + n_groups ;
2010-01-07 14:15:33 -05:00
}
}
}
2013-01-19 05:02:00 -05:00
} else {
/* No controllers names, generate generic numeric menu */
2020-04-14 19:41:17 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
/* count the number of selected channels because we will build a different menu
* structure if there is more than 1 selected .
*/
int chn_cnt = 0 ;
for ( uint8_t chn = 0 ; chn < 16 ; chn + + ) {
if ( selected_channels & ( 0x0001 < < chn ) ) {
if ( + + chn_cnt > 1 ) {
break ;
}
}
}
2019-06-04 17:51:50 -04:00
for ( int i = 0 ; i < 127 ; i + = 32 ) {
2013-01-19 05:02:00 -05:00
Menu * ctl_menu = manage ( new Menu ) ;
MenuList & ctl_items ( ctl_menu - > items ( ) ) ;
2019-06-04 17:51:50 -04:00
for ( int ctl = i ; ctl < i + 32 ; + + ctl ) {
2013-01-19 05:02:00 -05:00
if ( ctl = = MIDI_CTL_MSB_BANK | | ctl = = MIDI_CTL_LSB_BANK ) {
/* Skip bank select controllers since they're handled specially */
continue ;
}
2011-06-01 13:00:29 -04:00
2013-01-19 05:02:00 -05:00
if ( chn_cnt > 1 ) {
add_multi_channel_controller_item (
2020-04-14 19:41:17 -04:00
ctl_items , selected_channels , ctl , string_compose ( _ ( " Controller %1 " ) , ctl ) ) ;
2013-01-19 05:02:00 -05:00
} else {
add_single_channel_controller_item (
ctl_items , ctl , string_compose ( _ ( " Controller %1 " ) , ctl ) ) ;
}
}
2010-01-07 14:15:33 -05:00
2013-01-19 05:02:00 -05:00
/* Add submenu for this block of controllers to controller menu */
2019-06-04 17:51:50 -04:00
switch ( i ) {
case 0 :
case 32 :
/* skip 0x00 and 0x20 (bank-select) */
items . push_back ( MenuElem ( string_compose ( _ ( " Controllers %1-%2 " ) , i + 1 , i + 31 ) , * ctl_menu ) ) ;
break ;
default :
items . push_back ( MenuElem ( string_compose ( _ ( " Controllers %1-%2 " ) , i , i + 31 ) , * ctl_menu ) ) ;
break ;
}
2013-01-19 05:02:00 -05:00
}
2010-01-07 14:15:33 -05:00
}
2010-01-06 16:56:23 -05:00
}
2007-07-06 23:19:04 -04:00
Gtk : : Menu *
2008-12-28 20:02:41 -05:00
MidiTimeAxisView : : build_note_mode_menu ( )
2007-07-06 23:19:04 -04:00
{
using namespace Menu_Helpers ;
Menu * mode_menu = manage ( new Menu ) ;
MenuList & items = mode_menu - > items ( ) ;
mode_menu - > set_name ( " ArdourContextMenu " ) ;
RadioMenuItem : : Group mode_group ;
2013-01-19 00:54:44 -05:00
items . push_back (
RadioMenuElem ( mode_group , _ ( " Sustained " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_note_mode ) ,
Sustained , true ) ) ) ;
2007-07-06 23:19:04 -04:00
_note_mode_item = dynamic_cast < RadioMenuItem * > ( & items . back ( ) ) ;
2007-07-28 03:09:21 -04:00
_note_mode_item - > set_active ( _note_mode = = Sustained ) ;
2007-07-06 23:19:04 -04:00
2013-01-19 00:54:44 -05:00
items . push_back (
RadioMenuElem ( mode_group , _ ( " Percussive " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_note_mode ) ,
Percussive , true ) ) ) ;
2007-07-06 23:19:04 -04:00
_percussion_mode_item = dynamic_cast < RadioMenuItem * > ( & items . back ( ) ) ;
2007-07-28 03:09:21 -04:00
_percussion_mode_item - > set_active ( _note_mode = = Percussive ) ;
2007-07-06 23:19:04 -04:00
return mode_menu ;
}
2008-12-23 20:24:49 -05:00
Gtk : : Menu *
MidiTimeAxisView : : build_color_mode_menu ( )
{
using namespace Menu_Helpers ;
Menu * mode_menu = manage ( new Menu ) ;
MenuList & items = mode_menu - > items ( ) ;
mode_menu - > set_name ( " ArdourContextMenu " ) ;
RadioMenuItem : : Group mode_group ;
2013-01-19 00:54:44 -05:00
items . push_back (
RadioMenuElem ( mode_group , _ ( " Meter Colors " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_color_mode ) ,
MeterColors , false , true , true ) ) ) ;
2008-12-23 20:24:49 -05:00
_meter_color_mode_item = dynamic_cast < RadioMenuItem * > ( & items . back ( ) ) ;
_meter_color_mode_item - > set_active ( _color_mode = = MeterColors ) ;
2013-01-19 00:54:44 -05:00
items . push_back (
RadioMenuElem ( mode_group , _ ( " Channel Colors " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_color_mode ) ,
ChannelColors , false , true , true ) ) ) ;
2008-12-23 20:24:49 -05:00
_channel_color_mode_item = dynamic_cast < RadioMenuItem * > ( & items . back ( ) ) ;
_channel_color_mode_item - > set_active ( _color_mode = = ChannelColors ) ;
2009-10-14 12:10:01 -04:00
2013-01-19 00:54:44 -05:00
items . push_back (
RadioMenuElem ( mode_group , _ ( " Track Color " ) ,
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : set_color_mode ) ,
TrackColor , false , true , true ) ) ) ;
2008-12-23 20:24:49 -05:00
_channel_color_mode_item = dynamic_cast < RadioMenuItem * > ( & items . back ( ) ) ;
_channel_color_mode_item - > set_active ( _color_mode = = TrackColor ) ;
2009-10-14 12:10:01 -04:00
2008-12-23 20:24:49 -05:00
return mode_menu ;
}
2009-10-14 12:10:01 -04:00
2007-07-06 23:19:04 -04:00
void
2012-06-13 13:24:15 -04:00
MidiTimeAxisView : : set_note_mode ( NoteMode mode , bool apply_to_selection )
2007-07-06 23:19:04 -04:00
{
2012-06-13 13:24:15 -04:00
if ( apply_to_selection ) {
2013-01-19 00:54:44 -05:00
_editor . get_selection ( ) . tracks . foreach_midi_time_axis (
boost : : bind ( & MidiTimeAxisView : : set_note_mode , _1 , mode , false ) ) ;
2011-05-16 14:18:13 -04:00
} else {
2012-06-13 13:24:15 -04:00
if ( _note_mode ! = mode | | midi_track ( ) - > note_mode ( ) ! = mode ) {
_note_mode = mode ;
midi_track ( ) - > set_note_mode ( mode ) ;
set_gui_property ( " note-mode " , enum_2_string ( _note_mode ) ) ;
_view - > redisplay_track ( ) ;
}
2011-05-19 17:29:47 -04:00
}
2008-12-23 20:24:49 -05:00
}
2007-07-14 21:56:11 -04:00
void
2012-06-13 13:24:15 -04:00
MidiTimeAxisView : : set_color_mode ( ColorMode mode , bool force , bool redisplay , bool apply_to_selection )
2007-07-14 21:56:11 -04:00
{
2012-06-13 13:24:15 -04:00
if ( apply_to_selection ) {
_editor . get_selection ( ) . tracks . foreach_midi_time_axis (
2013-01-19 00:54:44 -05:00
boost : : bind ( & MidiTimeAxisView : : set_color_mode , _1 , mode , force , redisplay , false ) ) ;
2012-06-13 13:24:15 -04:00
} else {
if ( _color_mode = = mode & & ! force ) {
return ;
}
2015-10-05 10:17:49 -04:00
2013-03-27 21:50:18 -04:00
if ( _channel_selector ) {
if ( mode = = ChannelColors ) {
2013-04-04 18:45:27 -04:00
_channel_selector - > set_channel_colors ( NoteBase : : midi_channel_colors ) ;
2013-03-27 21:50:18 -04:00
} else {
_channel_selector - > set_default_channel_color ( ) ;
}
2012-06-13 13:24:15 -04:00
}
2015-10-05 10:17:49 -04:00
2012-06-13 13:24:15 -04:00
_color_mode = mode ;
set_gui_property ( " color-mode " , enum_2_string ( _color_mode ) ) ;
if ( redisplay ) {
_view - > redisplay_track ( ) ;
}
2012-06-13 11:38:27 -04:00
}
}
void
2012-06-13 13:24:15 -04:00
MidiTimeAxisView : : set_note_range ( MidiStreamView : : VisibleNoteRange range , bool apply_to_selection )
2012-06-13 11:38:27 -04:00
{
2012-06-13 13:24:15 -04:00
if ( apply_to_selection ) {
_editor . get_selection ( ) . tracks . foreach_midi_time_axis (
2013-01-19 00:54:44 -05:00
boost : : bind ( & MidiTimeAxisView : : set_note_range , _1 , range , false ) ) ;
2012-06-13 13:24:15 -04:00
} else {
if ( ! _ignore_signals ) {
midi_view ( ) - > set_note_range ( range ) ;
2012-06-13 11:38:27 -04:00
}
}
2007-07-14 21:56:11 -04:00
}
2008-09-19 13:24:52 -04:00
void
2011-03-07 08:04:46 -05:00
MidiTimeAxisView : : show_all_automation ( bool apply_to_selection )
2008-09-19 13:24:52 -04:00
{
2014-07-14 00:43:36 -04:00
using namespace MIDI : : Name ;
2020-09-07 00:44:47 -04:00
if ( ! _asked_all_automation ) {
ArdourMessageDialog md ( _ ( " Are you sure you want to \n show all MIDI automation lanes? " ) , false , MESSAGE_QUESTION , BUTTONS_YES_NO ) ;
md . set_title ( _ ( " Show All Automation " ) ) ;
Fix typos in gtk2_ardour/ directory
Found via `codespell -q 3 -S *.po,./share/patchfiles,./libs -L ba,buss,busses,doubleclick,hsi,ontop,ro,seh,siz,sur,te,trough,ue`
2022-01-26 12:35:38 -05:00
md . set_secondary_text ( _ ( " There are a total of 16 MIDI channels times 128 Control-Change parameters, not including other MIDI controls. Showing all will add more than 2000 automation lanes which is not generally useful. This will take some time and also slow down the GUI significantly. " ) ) ;
2020-09-07 00:44:47 -04:00
if ( md . run ( ) ! = RESPONSE_YES ) {
return ;
}
}
PBD : : Unwinder < bool > uw ( _asked_all_automation , true ) ;
2011-03-07 08:04:46 -05:00
if ( apply_to_selection ) {
2013-01-19 00:54:44 -05:00
_editor . get_selection ( ) . tracks . foreach_midi_time_axis (
boost : : bind ( & MidiTimeAxisView : : show_all_automation , _1 , false ) ) ;
2011-03-07 08:04:46 -05:00
} else {
2020-09-07 00:44:20 -04:00
no_redraw = true ; // unset in RouteTimeAxisView::show_all_automation
2011-03-07 08:04:46 -05:00
if ( midi_track ( ) ) {
2014-07-14 00:43:36 -04:00
// Show existing automation
2011-03-07 08:04:46 -05:00
const set < Evoral : : Parameter > params = midi_track ( ) - > midi_playlist ( ) - > contained_automation ( ) ;
2011-06-01 13:00:29 -04:00
2011-03-07 08:04:46 -05:00
for ( set < Evoral : : Parameter > : : const_iterator i = params . begin ( ) ; i ! = params . end ( ) ; + + i ) {
create_automation_child ( * i , true ) ;
}
2014-07-14 00:43:36 -04:00
2020-04-01 17:26:13 -04:00
/* Show automation for all controllers named in midnam file */
if ( _route - > instrument_info ( ) . master_controller_count ( ) > 0 ) {
2020-02-11 15:59:05 -05:00
2020-04-01 00:58:00 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2020-02-11 15:59:05 -05:00
2014-07-14 00:43:36 -04:00
for ( uint32_t chn = 0 ; chn < 16 ; + + chn ) {
2020-02-11 15:59:05 -05:00
2014-07-14 00:43:36 -04:00
if ( ( selected_channels & ( 0x0001 < < chn ) ) = = 0 ) {
// Channel not in use
continue ;
}
2023-02-16 18:33:28 -05:00
std : : shared_ptr < ControlNameList > control_names = _route - > instrument_info ( ) . control_name_list ( chn ) ;
2014-07-14 00:43:36 -04:00
if ( ! control_names ) {
continue ;
}
2020-04-01 00:58:00 -04:00
for ( ControlNameList : : Controls : : const_iterator c = control_names - > controls ( ) . begin ( ) ; c ! = control_names - > controls ( ) . end ( ) ; + + c ) {
2014-07-14 00:43:36 -04:00
const uint16_t ctl = c - > second - > number ( ) ;
if ( ctl ! = MIDI_CTL_MSB_BANK & & ctl ! = MIDI_CTL_LSB_BANK ) {
/* Skip bank select controllers since they're handled specially */
const Evoral : : Parameter param ( MidiCCAutomation , chn , ctl ) ;
create_automation_child ( param , true ) ;
}
}
}
}
2008-09-21 12:17:02 -04:00
}
2011-06-01 13:00:29 -04:00
2011-03-07 08:04:46 -05:00
RouteTimeAxisView : : show_all_automation ( ) ;
2008-09-19 13:24:52 -04:00
}
}
2008-02-18 22:24:44 -05:00
void
2011-03-07 08:04:46 -05:00
MidiTimeAxisView : : show_existing_automation ( bool apply_to_selection )
2008-02-18 22:24:44 -05:00
{
2011-03-07 08:04:46 -05:00
if ( apply_to_selection ) {
2013-01-19 00:54:44 -05:00
_editor . get_selection ( ) . tracks . foreach_midi_time_axis (
boost : : bind ( & MidiTimeAxisView : : show_existing_automation , _1 , false ) ) ;
2011-03-07 08:04:46 -05:00
} else {
if ( midi_track ( ) ) {
const set < Evoral : : Parameter > params = midi_track ( ) - > midi_playlist ( ) - > contained_automation ( ) ;
2011-06-01 13:00:29 -04:00
2011-03-07 08:04:46 -05:00
for ( set < Evoral : : Parameter > : : const_iterator i = params . begin ( ) ; i ! = params . end ( ) ; + + i ) {
2011-07-06 20:37:13 -04:00
create_automation_child ( * i , true ) ;
2011-03-07 08:04:46 -05:00
}
2008-09-21 12:17:02 -04:00
}
2011-06-01 13:00:29 -04:00
2011-03-07 08:04:46 -05:00
RouteTimeAxisView : : show_existing_automation ( ) ;
2008-02-18 22:24:44 -05:00
}
}
2010-06-08 17:48:38 -04:00
/** Create an automation track for the given parameter (pitch bend, channel pressure).
2010-01-06 16:56:23 -05:00
*/
2007-06-27 11:51:50 -04:00
void
2008-09-29 18:47:40 -04:00
MidiTimeAxisView : : create_automation_child ( const Evoral : : Parameter & param , bool show )
2007-06-27 11:51:50 -04:00
{
2009-02-15 23:53:01 -05:00
if ( param . type ( ) = = NullAutomation ) {
return ;
}
2011-06-01 13:00:29 -04:00
2010-01-08 21:36:47 -05:00
AutomationTracks : : iterator existing = _automation_tracks . find ( param ) ;
2011-06-11 11:35:34 -04:00
2010-01-08 21:36:47 -05:00
if ( existing ! = _automation_tracks . end ( ) ) {
2011-06-11 11:35:34 -04:00
/* automation track created because we had existing data for
* the processor , but visibility may need to be controlled
* since it will have been set visible by default .
*/
2014-11-17 00:13:53 -05:00
existing - > second - > set_marked_for_display ( show ) ;
if ( ! no_redraw ) {
2011-07-06 20:37:13 -04:00
request_redraw ( ) ;
2011-06-11 11:35:34 -04:00
}
2009-01-21 03:32:23 -05:00
return ;
2010-01-08 21:36:47 -05:00
}
2011-06-01 13:00:29 -04:00
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track ;
std : : shared_ptr < AutomationControl > control ;
2014-08-31 17:52:09 -04:00
2011-06-11 11:35:34 -04:00
switch ( param . type ( ) ) {
2011-06-01 13:00:29 -04:00
2011-06-11 11:35:34 -04:00
case GainAutomation :
create_gain_automation_child ( param , show ) ;
break ;
2014-07-01 14:36:58 -04:00
case MuteAutomation :
create_mute_automation_child ( param , show ) ;
break ;
2011-06-11 11:35:34 -04:00
case PluginAutomation :
/* handled elsewhere */
break ;
2022-12-18 18:43:29 -05:00
case MidiVelocityAutomation :
2023-06-24 18:17:41 -04:00
create_velocity_automation_child ( param , show ) ;
break ;
2011-06-11 11:35:34 -04:00
case MidiCCAutomation :
case MidiPgmChangeAutomation :
case MidiPitchBenderAutomation :
case MidiChannelPressureAutomation :
2019-10-11 19:03:50 -04:00
case MidiNotePressureAutomation :
2011-06-11 11:35:34 -04:00
case MidiSystemExclusiveAutomation :
/* These controllers are region "automation" - they are owned
* by regions ( and their MidiModels ) , not by the track . As a
2014-08-31 17:52:09 -04:00
* result there is no AutomationList / Line for the track , but we create
* a controller for the user to write immediate events , so the editor
* can act as a control surface for the present MIDI controllers .
*
* TODO : Record manipulation of the controller to regions ?
2011-06-11 11:35:34 -04:00
*/
2014-08-31 17:52:09 -04:00
control = _route - > automation_control ( param , true ) ;
2011-06-11 11:35:34 -04:00
track . reset ( new AutomationTimeAxisView (
2013-01-19 00:54:44 -05:00
_session ,
_route ,
2023-02-16 18:33:28 -05:00
control ? _route : std : : shared_ptr < Automatable > ( ) ,
2014-08-31 17:52:09 -04:00
control ,
2013-01-19 00:54:44 -05:00
param ,
_editor ,
* this ,
true ,
parent_canvas ,
2020-04-14 20:38:18 -04:00
/* this calls MidiTrack::describe_parameter()
* - > instrument_info ( ) . get_controller_name ( )
*/
2013-01-19 00:54:44 -05:00
_route - > describe_parameter ( param ) ) ) ;
2011-02-26 18:48:43 -05:00
if ( _view ) {
2022-12-26 22:56:13 -05:00
std : : cerr < < " Adding ghosts of each MIDI region \n " ;
2022-12-18 18:43:29 -05:00
_view - > foreach_regionview ( sigc : : mem_fun ( * track . get ( ) , & TimeAxisView : : add_ghost ) ) ;
2011-02-26 18:48:43 -05:00
}
2011-06-01 13:00:29 -04:00
2010-09-26 22:04:16 -04:00
add_automation_child ( param , track , show ) ;
2017-07-21 09:49:28 -04:00
if ( selected ( ) ) {
reshow_selection ( _editor . get_selection ( ) . time ) ;
}
2011-06-11 11:35:34 -04:00
break ;
2014-01-15 05:30:54 -05:00
case PanWidthAutomation :
case PanElevationAutomation :
case PanAzimuthAutomation :
ensure_pan_views ( show ) ;
2011-06-11 11:35:34 -04:00
break ;
default :
2013-01-19 00:54:44 -05:00
error < < " MidiTimeAxisView: unknown automation child "
< < EventTypeMap : : instance ( ) . to_symbol ( param ) < < endmsg ;
2010-09-26 22:04:16 -04:00
}
2006-07-23 08:03:19 -04:00
}
void
MidiTimeAxisView : : route_active_changed ( )
{
2020-01-21 19:35:18 -05:00
RouteTimeAxisView : : route_active_changed ( ) ;
2016-02-11 18:25:17 -05:00
update_control_names ( ) ;
2020-07-10 12:16:18 -04:00
update_midi_controls_visibility ( height ) ;
2020-01-20 17:03:22 -05:00
if ( ! _route - > active ( ) ) {
controls_table . hide ( ) ;
2020-07-10 12:16:18 -04:00
inactive_table . show ( ) ;
2020-01-20 17:03:22 -05:00
RouteTimeAxisView : : hide_all_automation ( ) ;
} else {
inactive_table . hide ( ) ;
controls_table . show ( ) ;
}
2016-02-11 18:25:17 -05:00
}
2006-07-23 08:03:19 -04:00
2016-02-11 18:25:17 -05:00
void
MidiTimeAxisView : : update_control_names ( )
{
2006-08-14 04:44:14 -04:00
if ( is_track ( ) ) {
2006-07-27 21:08:57 -04:00
if ( _route - > active ( ) ) {
2006-07-23 08:03:19 -04:00
controls_base_selected_name = " MidiTrackControlsBaseSelected " ;
controls_base_unselected_name = " MidiTrackControlsBaseUnselected " ;
} else {
controls_base_selected_name = " MidiTrackControlsBaseInactiveSelected " ;
controls_base_unselected_name = " MidiTrackControlsBaseInactiveUnselected " ;
}
2016-02-11 18:25:17 -05:00
} else { // MIDI bus (which doesn't exist yet..)
2006-07-27 21:08:57 -04:00
if ( _route - > active ( ) ) {
2006-07-23 08:03:19 -04:00
controls_base_selected_name = " BusControlsBaseSelected " ;
controls_base_unselected_name = " BusControlsBaseUnselected " ;
} else {
controls_base_selected_name = " BusControlsBaseInactiveSelected " ;
controls_base_unselected_name = " BusControlsBaseInactiveUnselected " ;
}
}
2016-02-11 18:25:17 -05:00
2016-06-05 19:49:51 -04:00
if ( selected ( ) ) {
2016-02-11 18:25:17 -05:00
controls_ebox . set_name ( controls_base_selected_name ) ;
2017-09-18 14:45:56 -04:00
time_axis_frame . set_name ( controls_base_selected_name ) ;
2016-02-11 18:25:17 -05:00
} else {
controls_ebox . set_name ( controls_base_unselected_name ) ;
2017-09-18 14:45:56 -04:00
time_axis_frame . set_name ( controls_base_unselected_name ) ;
2016-02-11 18:25:17 -05:00
}
2006-07-23 08:03:19 -04:00
}
2008-04-19 06:30:38 -04:00
2012-01-19 21:54:23 -05:00
void
MidiTimeAxisView : : set_note_selection ( uint8_t note )
{
2013-03-27 21:50:18 -04:00
uint16_t chn_mask = midi_track ( ) - > get_playback_channel_mask ( ) ;
2012-01-19 21:54:23 -05:00
2015-03-25 08:31:23 -04:00
_editor . begin_reversible_selection_op ( X_ ( " Set Note Selection " ) ) ;
2015-01-10 12:07:31 -05:00
2019-08-11 22:49:31 -04:00
/* set_note_selection_region_view() will not work with multiple regions,
* as each individual ` foreach ` call will clear prior selection .
* Use clear_midi_notes ( ) and add_note_selection_region_view ( ) instead . */
_editor . get_selection ( ) . clear_midi_notes ( ) ;
2012-01-19 21:54:23 -05:00
if ( _view - > num_selected_regionviews ( ) = = 0 ) {
2013-01-19 00:54:44 -05:00
_view - > foreach_regionview (
2019-08-11 22:49:31 -04:00
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : add_note_selection_region_view ) ,
2013-01-19 00:54:44 -05:00
note , chn_mask ) ) ;
2012-01-19 21:54:23 -05:00
} else {
2013-01-19 00:54:44 -05:00
_view - > foreach_selected_regionview (
2019-08-11 22:49:31 -04:00
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : add_note_selection_region_view ) ,
2013-01-19 00:54:44 -05:00
note , chn_mask ) ) ;
2012-01-19 21:54:23 -05:00
}
2015-01-10 12:07:31 -05:00
_editor . commit_reversible_selection_op ( ) ;
2012-01-19 21:54:23 -05:00
}
2010-01-07 14:15:33 -05:00
void
MidiTimeAxisView : : add_note_selection ( uint8_t note )
{
2013-03-27 21:50:18 -04:00
const uint16_t chn_mask = midi_track ( ) - > get_playback_channel_mask ( ) ;
2010-01-07 14:15:33 -05:00
2015-03-25 08:31:23 -04:00
_editor . begin_reversible_selection_op ( X_ ( " Add Note Selection " ) ) ;
2015-01-10 12:07:31 -05:00
2010-01-07 14:15:33 -05:00
if ( _view - > num_selected_regionviews ( ) = = 0 ) {
2013-01-19 00:54:44 -05:00
_view - > foreach_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : add_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
} else {
2013-01-19 00:54:44 -05:00
_view - > foreach_selected_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : add_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
}
2015-01-10 12:07:31 -05:00
_editor . commit_reversible_selection_op ( ) ;
2010-01-07 14:15:33 -05:00
}
void
MidiTimeAxisView : : extend_note_selection ( uint8_t note )
{
2013-03-27 21:50:18 -04:00
const uint16_t chn_mask = midi_track ( ) - > get_playback_channel_mask ( ) ;
2010-01-07 14:15:33 -05:00
2015-03-25 08:31:23 -04:00
_editor . begin_reversible_selection_op ( X_ ( " Extend Note Selection " ) ) ;
2015-01-10 12:07:31 -05:00
2010-01-07 14:15:33 -05:00
if ( _view - > num_selected_regionviews ( ) = = 0 ) {
2013-01-19 00:54:44 -05:00
_view - > foreach_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : extend_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
} else {
2013-01-19 00:54:44 -05:00
_view - > foreach_selected_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : extend_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
}
2015-01-10 12:07:31 -05:00
_editor . commit_reversible_selection_op ( ) ;
2010-01-07 14:15:33 -05:00
}
void
MidiTimeAxisView : : toggle_note_selection ( uint8_t note )
{
2013-03-27 21:50:18 -04:00
const uint16_t chn_mask = midi_track ( ) - > get_playback_channel_mask ( ) ;
2010-01-07 14:15:33 -05:00
2015-03-25 08:31:23 -04:00
_editor . begin_reversible_selection_op ( X_ ( " Toggle Note Selection " ) ) ;
2015-01-10 12:07:31 -05:00
2010-01-07 14:15:33 -05:00
if ( _view - > num_selected_regionviews ( ) = = 0 ) {
2013-01-19 00:54:44 -05:00
_view - > foreach_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : toggle_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
} else {
2013-01-19 00:54:44 -05:00
_view - > foreach_selected_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : toggle_note_selection_region_view ) ,
note , chn_mask ) ) ;
2010-01-07 14:15:33 -05:00
}
2015-01-10 12:07:31 -05:00
_editor . commit_reversible_selection_op ( ) ;
}
void
2023-02-16 18:33:28 -05:00
MidiTimeAxisView : : get_per_region_note_selection ( list < pair < PBD : : ID , set < std : : shared_ptr < Evoral : : Note < Temporal : : Beats > > > > > & selection )
2015-01-10 12:07:31 -05:00
{
_view - > foreach_regionview (
sigc : : bind ( sigc : : mem_fun ( * this , & MidiTimeAxisView : : get_per_region_note_selection_region_view ) , sigc : : ref ( selection ) ) ) ;
2010-01-07 14:15:33 -05:00
}
void
2012-01-19 21:54:23 -05:00
MidiTimeAxisView : : set_note_selection_region_view ( RegionView * rv , uint8_t note , uint16_t chn_mask )
2010-01-07 14:15:33 -05:00
{
dynamic_cast < MidiRegionView * > ( rv ) - > select_matching_notes ( note , chn_mask , false , false ) ;
}
2012-01-19 21:54:23 -05:00
void
MidiTimeAxisView : : add_note_selection_region_view ( RegionView * rv , uint8_t note , uint16_t chn_mask )
{
dynamic_cast < MidiRegionView * > ( rv ) - > select_matching_notes ( note , chn_mask , true , false ) ;
}
2010-01-07 14:15:33 -05:00
void
MidiTimeAxisView : : extend_note_selection_region_view ( RegionView * rv , uint8_t note , uint16_t chn_mask )
{
dynamic_cast < MidiRegionView * > ( rv ) - > select_matching_notes ( note , chn_mask , true , true ) ;
}
void
MidiTimeAxisView : : toggle_note_selection_region_view ( RegionView * rv , uint8_t note , uint16_t chn_mask )
{
dynamic_cast < MidiRegionView * > ( rv ) - > toggle_matching_notes ( note , chn_mask ) ;
}
2010-01-08 21:36:47 -05:00
2015-01-10 12:07:31 -05:00
void
2023-02-16 18:33:28 -05:00
MidiTimeAxisView : : get_per_region_note_selection_region_view ( RegionView * rv , list < pair < PBD : : ID , std : : set < std : : shared_ptr < Evoral : : Note < Temporal : : Beats > > > > > & selection )
2015-01-10 12:07:31 -05:00
{
2017-09-24 12:03:54 -04:00
Evoral : : Sequence < Temporal : : Beats > : : Notes selected ;
2015-01-10 12:07:31 -05:00
dynamic_cast < MidiRegionView * > ( rv ) - > selection_as_notelist ( selected , false ) ;
2023-02-16 18:33:28 -05:00
std : : set < std : : shared_ptr < Evoral : : Note < Temporal : : Beats > > > notes ;
2015-01-10 12:07:31 -05:00
2017-09-24 12:03:54 -04:00
Evoral : : Sequence < Temporal : : Beats > : : Notes : : iterator sel_it ;
2015-01-10 12:07:31 -05:00
for ( sel_it = selected . begin ( ) ; sel_it ! = selected . end ( ) ; + + sel_it ) {
notes . insert ( * sel_it ) ;
}
if ( ! notes . empty ( ) ) {
selection . push_back ( make_pair ( ( rv ) - > region ( ) - > id ( ) , notes ) ) ;
}
}
2010-01-08 21:36:47 -05:00
void
MidiTimeAxisView : : set_channel_mode ( ChannelMode , uint16_t )
{
2020-04-15 07:58:40 -04:00
/* hide all automation tracks that use the wrong channel(s) and show all those thatcw
* use the right ones . */
2010-01-10 13:11:02 -05:00
2013-03-27 21:50:18 -04:00
const uint16_t selected_channels = midi_track ( ) - > get_playback_channel_mask ( ) ;
2010-01-10 13:11:02 -05:00
bool changed = false ;
no_redraw = true ;
for ( uint32_t ctl = 0 ; ctl < 127 ; + + ctl ) {
for ( uint32_t chn = 0 ; chn < 16 ; + + chn ) {
Evoral : : Parameter fully_qualified_param ( MidiCCAutomation , chn , ctl ) ;
2023-02-16 18:33:28 -05:00
std : : shared_ptr < AutomationTimeAxisView > track = automation_child ( fully_qualified_param ) ;
2010-01-10 13:11:02 -05:00
2010-05-25 10:50:45 -04:00
if ( ! track ) {
2010-01-10 13:11:02 -05:00
continue ;
}
2011-06-01 13:00:29 -04:00
2010-01-10 13:11:02 -05:00
if ( ( selected_channels & ( 0x0001 < < chn ) ) = = 0 ) {
2011-06-01 13:00:29 -04:00
/* channel not in use. hiding it will trigger RouteTimeAxisView::automation_track_hidden()
2020-04-15 07:58:40 -04:00
* which will cause a redraw . We don ' t want one per channel , so block that with no_redraw .
*/
2011-07-06 20:37:13 -04:00
changed = track - > set_marked_for_display ( false ) | | changed ;
2010-01-10 13:11:02 -05:00
} else {
2011-07-06 20:37:13 -04:00
changed = track - > set_marked_for_display ( true ) | | changed ;
2010-01-10 13:11:02 -05:00
}
}
}
no_redraw = false ;
2010-12-28 13:19:40 -05:00
/* TODO: Bender, Pressure */
2010-01-10 13:11:02 -05:00
2011-02-17 11:43:30 -05:00
/* invalidate the controller menu, so that we rebuild it next time */
2010-06-08 17:48:38 -04:00
_controller_menu_map . clear ( ) ;
2010-01-08 21:36:47 -05:00
delete controller_menu ;
controller_menu = 0 ;
2010-01-10 13:11:02 -05:00
if ( changed ) {
2011-07-06 20:37:13 -04:00
request_redraw ( ) ;
2010-01-10 13:11:02 -05:00
}
2010-01-08 21:36:47 -05:00
}
2010-06-08 17:48:38 -04:00
Gtk : : CheckMenuItem *
MidiTimeAxisView : : automation_child_menu_item ( Evoral : : Parameter param )
{
Gtk : : CheckMenuItem * m = RouteTimeAxisView : : automation_child_menu_item ( param ) ;
if ( m ) {
return m ;
}
2023-06-24 18:17:41 -04:00
if ( param . type ( ) = = MidiVelocityAutomation ) {
return velocity_menu_item ;
}
2010-06-08 17:48:38 -04:00
ParameterMenuMap : : iterator i = _controller_menu_map . find ( param ) ;
if ( i ! = _controller_menu_map . end ( ) ) {
return i - > second ;
}
i = _channel_command_menu_map . find ( param ) ;
if ( i ! = _channel_command_menu_map . end ( ) ) {
return i - > second ;
}
return 0 ;
}
2010-08-15 12:39:51 -04:00
2023-02-16 18:33:28 -05:00
std : : shared_ptr < MidiRegion >
2020-10-19 14:37:54 -04:00
MidiTimeAxisView : : add_region ( timepos_t const & f , timecnt_t const & length , bool commit )
2010-08-15 12:39:51 -04:00
{
Editor * real_editor = dynamic_cast < Editor * > ( & _editor ) ;
2020-10-19 14:37:54 -04:00
timepos_t pos ( f ) ;
2017-01-26 08:41:17 -05:00
2015-06-16 19:26:40 -04:00
if ( commit ) {
real_editor - > begin_reversible_command ( Operations : : create_region ) ;
}
2013-01-19 00:54:44 -05:00
playlist ( ) - > clear_changes ( ) ;
2010-08-15 12:39:51 -04:00
2020-10-19 14:37:54 -04:00
real_editor - > snap_to ( pos , Temporal : : RoundNearest ) ;
2011-06-01 13:00:29 -04:00
2023-02-16 18:33:28 -05:00
std : : shared_ptr < Source > src = _session - > create_midi_source_by_stealing_name ( view ( ) - > trackview ( ) . track ( ) ) ;
2011-06-01 13:00:29 -04:00
2020-12-18 15:01:53 -05:00
const Temporal : : timecnt_t start ( Temporal : : BeatTime ) ; /* zero beats */
2023-02-16 18:33:28 -05:00
std : : shared_ptr < Region > region ;
2011-06-01 13:00:29 -04:00
2021-08-28 18:00:53 -04:00
/* Create the (empty) whole-file region that will show up in the source
* list . This is NOT used in any playlists .
*/
{
PropertyList plist ;
plist . add ( ARDOUR : : Properties : : start , start ) ;
plist . add ( ARDOUR : : Properties : : length , length ) ;
plist . add ( ARDOUR : : Properties : : automatic , true ) ;
plist . add ( ARDOUR : : Properties : : whole_file , true ) ;
plist . add ( ARDOUR : : Properties : : name , PBD : : basename_nosuffix ( src - > name ( ) ) ) ;
2022-09-19 17:40:58 -04:00
plist . add ( ARDOUR : : Properties : : opaque , _session - > config . get_draw_opaque_midi_regions ( ) ) ;
2021-08-28 18:00:53 -04:00
region = ( RegionFactory : : create ( src , plist , true ) ) ;
}
/* Now create the region that we will actually use within the playlist */
{
PropertyList plist ;
plist . add ( ARDOUR : : Properties : : name , region - > name ( ) ) ;
region = RegionFactory : : create ( region , plist , false ) ;
}
2020-12-18 15:01:53 -05:00
2020-10-19 14:37:54 -04:00
region - > set_position ( pos ) ;
playlist ( ) - > add_region ( region , pos , 1.0 , false ) ;
2010-08-15 12:39:51 -04:00
_session - > add_command ( new StatefulDiffCommand ( playlist ( ) ) ) ;
2010-08-20 08:01:13 -04:00
if ( commit ) {
real_editor - > commit_reversible_command ( ) ;
}
2010-08-15 12:39:51 -04:00
2023-02-16 18:33:28 -05:00
return std : : dynamic_pointer_cast < MidiRegion > ( region ) ;
2010-08-15 12:39:51 -04:00
}
2011-02-12 07:29:20 -05:00
void
MidiTimeAxisView : : ensure_step_editor ( )
{
if ( ! _step_editor ) {
_step_editor = new StepEditor ( _editor , midi_track ( ) , * this ) ;
}
}
2011-06-01 13:00:29 -04:00
void
2010-08-15 12:39:51 -04:00
MidiTimeAxisView : : start_step_editing ( )
{
2011-02-12 07:29:20 -05:00
ensure_step_editor ( ) ;
2013-01-19 00:54:44 -05:00
_step_editor - > start_step_editing ( ) ;
2010-08-15 12:39:51 -04:00
}
2011-06-01 13:00:29 -04:00
void
2010-08-15 12:39:51 -04:00
MidiTimeAxisView : : stop_step_editing ( )
{
2013-01-19 00:54:44 -05:00
if ( _step_editor ) {
_step_editor - > stop_step_editing ( ) ;
}
2010-08-15 12:39:51 -04:00
}
2011-05-25 11:19:47 -04:00
/** @return channel (counted from 0) to add an event to, based on the current setting
* of the channel selector .
*/
uint8_t
2021-11-18 08:32:09 -05:00
MidiTimeAxisView : : get_preferred_midi_channel ( ) const
2011-05-25 11:19:47 -04:00
{
2021-11-16 13:06:13 -05:00
if ( _editor . draw_channel ( ) ! = Editing : : DRAW_CHAN_AUTO ) {
return _editor . draw_channel ( ) ;
2023-09-14 01:56:45 -04:00
}
if ( _midnam_channel_selector . is_visible ( ) ) {
string chn = gui_property ( X_ ( " midnam-channel " ) ) ;
if ( ! chn . empty ( ) ) {
int midnam_channel ;
sscanf ( chn . c_str ( ) , " %*s %d " , & midnam_channel ) ;
midnam_channel - - ;
return midnam_channel ;
}
2021-11-16 13:06:13 -05:00
}
2013-03-27 21:50:18 -04:00
uint16_t const chn_mask = midi_track ( ) - > get_playback_channel_mask ( ) ;
2011-05-25 11:19:47 -04:00
int chn_cnt = 0 ;
uint8_t channel = 0 ;
/* pick the highest selected channel, unless all channels are selected,
2020-04-15 07:58:40 -04:00
* which is interpreted to mean channel 1 ( zero )
*/
2011-05-25 11:19:47 -04:00
for ( uint16_t i = 0 ; i < 16 ; + + i ) {
if ( chn_mask & ( 1 < < i ) ) {
channel = i ;
chn_cnt + + ;
}
}
if ( chn_cnt = = 16 ) {
channel = 0 ;
}
return channel ;
}
2011-08-14 14:40:57 -04:00
void
MidiTimeAxisView : : note_range_changed ( )
{
set_gui_property ( " note-range-min " , ( int ) midi_view ( ) - > lowest_note ( ) ) ;
set_gui_property ( " note-range-max " , ( int ) midi_view ( ) - > highest_note ( ) ) ;
}
2012-06-02 10:53:34 -04:00
2014-12-16 14:37:40 -05:00
bool
2020-10-19 14:37:54 -04:00
MidiTimeAxisView : : paste ( timepos_t const & pos , const Selection & selection , PasteContext & ctx )
2014-12-16 14:37:40 -05:00
{
if ( ! _editor . internal_editing ( ) ) {
// Non-internal paste, paste regions like any other route
2020-10-19 14:37:54 -04:00
return RouteTimeAxisView : : paste ( pos , selection , ctx ) ;
2014-12-16 14:37:40 -05:00
}
2020-10-19 14:37:54 -04:00
return midi_view ( ) - > paste ( pos , selection , ctx ) ;
2014-12-16 14:37:40 -05:00
}
2020-04-16 14:16:45 -04:00
void
MidiTimeAxisView : : get_regions_with_selected_data ( RegionSelection & rs )
{
midi_view ( ) - > get_regions_with_selected_data ( rs ) ;
}
2023-06-24 18:17:41 -04:00
void
MidiTimeAxisView : : create_velocity_automation_child ( Evoral : : Parameter const & , bool show )
{
std : : shared_ptr < AutomationControl > c = midi_track ( ) - > velocity_control ( ) ;
if ( ! c ) {
error < < " MidiTrack has no velocity automation, unable to add automation track view. " < < endmsg ;
return ;
}
velocity_track . reset ( new AutomationTimeAxisView ( _session ,
_route , midi_track ( ) , c , c - > parameter ( ) ,
_editor ,
* this ,
false ,
parent_canvas ,
midi_track ( ) - > describe_parameter ( c - > parameter ( ) ) ) ) ;
if ( _view ) {
_view - > foreach_regionview ( sigc : : mem_fun ( * velocity_track . get ( ) , & TimeAxisView : : add_ghost ) ) ;
}
add_automation_child ( Evoral : : Parameter ( MidiVelocityAutomation ) , velocity_track , show ) ;
}