#include <sigc++/bind.h>
#include "pbd/error.h"
+#include "pbd/ffs.h"
#include "pbd/stl_delete.h"
#include "pbd/whitespace.h"
#include "pbd/basename.h"
#include "ardour/track.h"
#include "ardour/types.h"
-#include "midi++/names.h"
-
#include "ardour_ui.h"
#include "ardour_button.h"
#include "automation_line.h"
#include "automation_time_axis.h"
-#include "canvas-note-event.h"
-#include "canvas_impl.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 "rgb_macros.h"
#include "selection.h"
#include "step_editor.h"
-#include "simplerect.h"
#include "utils.h"
+#include "note_base.h"
#include "ardour/midi_track.h"
using namespace Editing;
// Minimum height at which a control is displayed
-static const uint32_t MIDI_CONTROLS_BOX_MIN_HEIGHT = 162;
-static const uint32_t KEYBOARD_MIN_HEIGHT = 140;
+static const uint32_t MIDI_CONTROLS_BOX_MIN_HEIGHT = 140;
+static const uint32_t KEYBOARD_MIN_HEIGHT = 130;
-MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session* sess, Canvas& canvas)
+MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
: AxisView(sess) // virtually inherited
, RouteTimeAxisView(ed, sess, canvas)
, _ignore_signals(false)
, _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)
atoi (gui_property ("note-range-max").c_str()),
true);
}
+
midi_view()->NoteRangeChanged.connect (
sigc::mem_fun (*this, &MidiTimeAxisView::note_range_changed));
_view->ContentsHeightChanged.connect (
v->pack_start (*manage (new Label ("")), true, true);
v->show ();
h->show ();
- controls_hbox.pack_start(*v);
+ controls_hbox.pack_start(*v, false, false);
controls_ebox.set_name ("MidiTrackControlsBaseUnselected");
controls_base_selected_name = "MidiTrackControlsBaseSelected";
_view->RegionViewAdded.connect (
sigc::mem_fun(*this, &MidiTimeAxisView::region_view_added));
+ midi_track()->PlaybackChannelModeChanged.connect (*this, invalidator (*this),
+ boost::bind (&MidiTimeAxisView::playback_channel_mode_changed, this),
+ gui_context());
+ midi_track()->PlaybackChannelMaskChanged.connect (*this, invalidator (*this),
+ boost::bind (&MidiTimeAxisView::playback_channel_mode_changed, this),
+ gui_context());
+ midi_track()->CaptureChannelModeChanged.connect (*this, invalidator (*this),
+ boost::bind (&MidiTimeAxisView::capture_channel_mode_changed, this),
+ gui_context());
+ midi_track()->CaptureChannelMaskChanged.connect (*this, invalidator (*this),
+ boost::bind (&MidiTimeAxisView::capture_channel_mode_changed, this),
+ gui_context());
+
+ playback_channel_mode_changed ();
+ capture_channel_mode_changed ();
+
if (!_editor.have_idled()) {
/* first idle will do what we need */
} else {
}
}
-
MIDI::Name::MidiPatchManager& patch_manager = MIDI::Name::MidiPatchManager::instance();
MIDI::Name::MasterDeviceNames::Models::const_iterator m = patch_manager.all_models().begin();
_midnam_model_selector.append_text(m->c_str());
}
+ if (gui_property (X_("midnam-model-name")).empty()) {
+ set_gui_property (X_("midnam-model-name"), "Generic");
+ }
+
+ if (gui_property (X_("midnam-custom-device-mode")).empty()) {
+ boost::shared_ptr<MIDI::Name::MasterDeviceNames> device_names = get_device_names();
+ if (device_names) {
+ set_gui_property (X_("midnam-custom-device-mode"),
+ *device_names->custom_device_mode_names().begin());
+ }
+ }
+
_midnam_model_selector.set_active_text (gui_property (X_("midnam-model-name")));
_midnam_custom_device_mode_selector.set_active_text (gui_property (X_("midnam-custom-device-mode")));
_midi_controls_box.set_homogeneous(false);
_midi_controls_box.set_border_width (10);
- if (!patch_manager.all_models().empty()) {
- _channel_selector.set_border_width(2);
- _channel_selector.show_all ();
+ _channel_status_box.set_homogeneous (false);
+ _channel_status_box.set_spacing (6);
+
+ _channel_selector_button.set_label (_("Chns"));
+ ARDOUR_UI::instance()->set_tip (_channel_selector_button, _("Click to edit channel settings"));
+
+ /* fixed sized labels to prevent silly nonsense (though obviously,
+ * they cause their own too)
+ */
- _midi_controls_box.resize(3, 2);
- _midi_controls_box.attach(_channel_selector, 0, 2, 0, 1);
-
- _midi_controls_box.attach(*manage(new HSeparator()), 0, 2, 1, 2);
+ _playback_channel_status.set_size_request (65, -1);
+ _capture_channel_status.set_size_request (60, -1);
+
+ _channel_status_box.pack_start (_playback_channel_status, false, false);
+ _channel_status_box.pack_start (_capture_channel_status, false, false);
+ _channel_status_box.pack_start (_channel_selector_button, false, false);
+ _channel_status_box.show_all ();
+
+ _channel_selector_button.signal_clicked().connect (sigc::mem_fun (*this, &MidiTimeAxisView::toggle_channel_selector));
+
+ _midi_controls_box.pack_start (_channel_status_box, false, false, 10);
+
+ if (!patch_manager.all_models().empty()) {
_midnam_model_selector.set_size_request(22, 30);
_midnam_model_selector.set_border_width(2);
_midnam_model_selector.show ();
- _midi_controls_box.attach(_midnam_model_selector, 0, 1, 2, 3);
+ _midi_controls_box.pack_start (_midnam_model_selector);
_midnam_custom_device_mode_selector.set_size_request(10, 30);
_midnam_custom_device_mode_selector.set_border_width(2);
_midnam_custom_device_mode_selector.show ();
- _midi_controls_box.attach(_midnam_custom_device_mode_selector, 0, 1, 3, 4);
- } else {
- _midi_controls_box.attach(_channel_selector, 0, 1, 0, 1);
- _channel_selector.show_all ();
- }
+
+ _midi_controls_box.pack_start (_midnam_custom_device_mode_selector);
+ }
model_changed();
custom_device_mode_changed();
_midnam_custom_device_mode_selector.signal_changed().connect(
sigc::mem_fun(*this, &MidiTimeAxisView::custom_device_mode_changed));
-
controls_vbox.pack_start(_midi_controls_box, false, false);
- // restore channel selector settings
- _channel_selector.set_channel_mode(midi_track()->get_channel_mode(),
- midi_track()->get_channel_mask());
- _channel_selector.mode_changed.connect(
- sigc::mem_fun(*midi_track(), &MidiTrack::set_channel_mode));
- _channel_selector.mode_changed.connect(
- sigc::mem_fun(*this, &MidiTimeAxisView::set_channel_mode));
-
const string color_mode = gui_property ("color-mode");
if (!color_mode.empty()) {
_color_mode = ColorMode (string_2_enum(color_mode, _color_mode));
- if (_color_mode == ChannelColors) {
- _channel_selector.set_channel_colors(CanvasNoteEvent::midi_channel_colors);
+ if (_channel_selector && _color_mode == ChannelColors) {
+ _channel_selector->set_channel_colors(NoteBase::midi_channel_colors);
}
}
MidiTimeAxisView::~MidiTimeAxisView ()
{
+ delete _channel_selector;
+
delete _piano_roll_header;
_piano_roll_header = 0;
_midnam_custom_device_mode_selector.clear_items();
- if (device_modes.size() < 2) {
- _midnam_custom_device_mode_selector.hide();
- } else {
- _midnam_custom_device_mode_selector.show();
- for (std::list<std::string>::const_iterator i = device_modes.begin();
- i != device_modes.end(); ++i) {
- _midnam_custom_device_mode_selector.append_text(*i);
- }
+ for (std::list<std::string>::const_iterator i = device_modes.begin();
+ i != device_modes.end(); ++i) {
+ _midnam_custom_device_mode_selector.append_text(*i);
}
_midnam_custom_device_mode_selector.set_active(0);
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)));
+ color_mode_menu = build_color_mode_menu();
+ if (color_mode_menu) {
+ items.push_back (MenuElem (_("Color Mode"), *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)
{
MenuList& automation_items = automation_action_menu->items();
- uint16_t selected_channels = _channel_selector.get_selected_channels();
+ uint16_t selected_channels = midi_track()->get_playback_channel_mask();
if (selected_channels != 0) {
void
MidiTimeAxisView::change_all_channel_tracks_visibility (bool yn, Evoral::Parameter param)
{
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
structure if there is more than 1 selected.
*/
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
int chn_cnt = 0;
for (uint8_t chn = 0; chn < 16; chn++) {
}
}
- CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&chn_items.back());
+ Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&chn_items.back());
_channel_command_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
}
}
}
- CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&items.back());
+ Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&items.back());
_channel_command_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
{
using namespace Menu_Helpers;
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
for (uint8_t chn = 0; chn < 16; chn++) {
if (selected_channels & (0x0001 << chn)) {
}
}
- CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&ctl_items.back());
+ Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&ctl_items.back());
_controller_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
{
using namespace Menu_Helpers;
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
Menu* chn_menu = manage (new Menu);
MenuList& chn_items (chn_menu->items());
}
}
- CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&chn_items.back());
+ Gtk::CheckMenuItem* cmi = static_cast<Gtk::CheckMenuItem*>(&chn_items.back());
_controller_menu_map[fully_qualified_param] = cmi;
cmi->set_active (visible);
}
dynamic_cast<Label*> (ctl_items.back().get_child())->set_use_markup (true);
}
+boost::shared_ptr<MIDI::Name::CustomDeviceMode>
+MidiTimeAxisView::get_device_mode()
+{
+ using namespace MIDI::Name;
+
+ boost::shared_ptr<MasterDeviceNames> device_names = get_device_names();
+ if (!device_names) {
+ return boost::shared_ptr<MIDI::Name::CustomDeviceMode>();
+ }
+
+ return device_names->custom_device_mode_by_name(
+ gui_property (X_("midnam-custom-device-mode")));
+}
+
+boost::shared_ptr<MIDI::Name::MasterDeviceNames>
+MidiTimeAxisView::get_device_names()
+{
+ using namespace MIDI::Name;
+
+ const std::string model = gui_property (X_("midnam-model-name"));
+
+ boost::shared_ptr<MIDINameDocument> midnam = MidiPatchManager::instance()
+ .document_by_model(model);
+ if (midnam) {
+ return midnam->master_device_names(model);
+ } else {
+ return boost::shared_ptr<MasterDeviceNames>();
+ }
+}
+
void
MidiTimeAxisView::build_controller_menu ()
{
combination covering the currently selected channels for this track
*/
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ 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.
}
using namespace MIDI::Name;
- const Glib::ustring model = _midnam_model_selector.get_active_text();
- boost::shared_ptr<MIDINameDocument> midnam = MidiPatchManager::instance()
- .document_by_model(model);
- boost::shared_ptr<MasterDeviceNames> device_names;
+ boost::shared_ptr<MasterDeviceNames> device_names = get_device_names();
- if (midnam) {
- device_names = midnam->master_device_names(model);
- }
-
if (device_names && !device_names->controls().empty()) {
/* Controllers names available in midnam file, generate fancy menu */
unsigned n_items = 0;
unsigned n_groups = 0;
+
+ /* TODO: This is not correct, should look up the currently applicable ControlNameList
+ and only build a menu for that one. */
for (MasterDeviceNames::ControlNameLists::const_iterator l = device_names->controls().begin();
l != device_names->controls().end(); ++l) {
- boost::shared_ptr<ControlNameList> name_list = *l;
+ boost::shared_ptr<ControlNameList> name_list = l->second;
Menu* ctl_menu = NULL;
- for (ControlNameList::Controls::const_iterator c = (*l)->controls().begin();
- c != (*l)->controls().end(); ++c) {
- const int ctl = atoi((*c)->number().c_str());
- if (ctl == MIDI_CTL_MSB_BANK || ctl == MIDI_CTL_LSB_BANK) {
+ for (ControlNameList::Controls::const_iterator c = name_list->controls().begin();
+ c != name_list->controls().end();) {
+ 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 */
- continue;
- }
-
- if (n_items == 0) {
- /* Create a new submenu */
- ctl_menu = manage (new Menu);
- }
+ if (n_items == 0) {
+ /* Create a new submenu */
+ ctl_menu = manage (new Menu);
+ }
- MenuList& ctl_items (ctl_menu->items());
- if (chn_cnt > 1) {
- add_multi_channel_controller_item(ctl_items, ctl, (*c)->name());
- } else {
- add_single_channel_controller_item(ctl_items, ctl, (*c)->name());
+ MenuList& ctl_items (ctl_menu->items());
+ if (chn_cnt > 1) {
+ add_multi_channel_controller_item(ctl_items, ctl, c->second->name());
+ } else {
+ add_single_channel_controller_item(ctl_items, ctl, c->second->name());
+ }
}
-
- if (++n_items == 16 || c == (*l)->controls().end()) {
- /* Submenu has 16 items, add it to controller menu and reset */
+
+ ++c;
+ if (ctl_menu && (++n_items == 16 || c == name_list->controls().end())) {
+ /* Submenu has 16 items or we're done, add it to controller menu and reset */
items.push_back(
MenuElem(string_compose(_("Controllers %1-%2"),
(16 * n_groups), (16 * n_groups) + n_items - 1),
return;
}
- if (mode == ChannelColors) {
- _channel_selector.set_channel_colors(CanvasNoteEvent::midi_channel_colors);
- } else {
- _channel_selector.set_default_channel_color();
+ if (_channel_selector) {
+ if (mode == ChannelColors) {
+ _channel_selector->set_channel_colors(NoteBase::midi_channel_colors);
+ } else {
+ _channel_selector->set_default_channel_color();
+ }
}
_color_mode = mode;
return;
}
- uint16_t chn_mask = _channel_selector.get_selected_channels();
+ uint16_t chn_mask = midi_track()->get_playback_channel_mask();
if (_view->num_selected_regionviews() == 0) {
_view->foreach_regionview (
return;
}
- const uint16_t chn_mask = _channel_selector.get_selected_channels();
+ const uint16_t chn_mask = midi_track()->get_playback_channel_mask();
if (_view->num_selected_regionviews() == 0) {
_view->foreach_regionview (
return;
}
- const uint16_t chn_mask = _channel_selector.get_selected_channels();
+ const uint16_t chn_mask = midi_track()->get_playback_channel_mask();
if (_view->num_selected_regionviews() == 0) {
_view->foreach_regionview (
return;
}
- const uint16_t chn_mask = _channel_selector.get_selected_channels();
+ const uint16_t chn_mask = midi_track()->get_playback_channel_mask();
if (_view->num_selected_regionviews() == 0) {
_view->foreach_regionview (
the right ones.
*/
- const uint16_t selected_channels = _channel_selector.get_selected_channels();
+ const uint16_t selected_channels = midi_track()->get_playback_channel_mask();
bool changed = false;
no_redraw = true;
}
}
-
/** @return channel (counted from 0) to add an event to, based on the current setting
* of the channel selector.
*/
uint8_t
MidiTimeAxisView::get_channel_for_add () const
{
- uint16_t const chn_mask = _channel_selector.get_selected_channels ();
+ uint16_t const chn_mask = midi_track()->get_playback_channel_mask();
int chn_cnt = 0;
uint8_t channel = 0;
{
_range_scroomer->set_size_request (-1, _view->child_height ());
}
+
+void
+MidiTimeAxisView::playback_channel_mode_changed ()
+{
+ switch (midi_track()->get_playback_channel_mode()) {
+ case AllChannels:
+ _playback_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2</i>", _("Play"), _("all")));
+ break;
+ case FilterChannels:
+ _playback_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2</i>", _("Play"), _("some")));
+ break;
+ case ForceChannel:
+ _playback_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2>%3</i>", _("Play"), _("all"), PBD::ffs (midi_track()->get_playback_channel_mask())));
+ break;
+ }
+}
+
+void
+MidiTimeAxisView::capture_channel_mode_changed ()
+{
+ switch (midi_track()->get_capture_channel_mode()) {
+ case AllChannels:
+ _capture_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2</i>", _("Rec"), _("all")));
+ break;
+ case FilterChannels:
+ _capture_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2</i>", _("Rec"), _("some")));
+ break;
+ case ForceChannel:
+ _capture_channel_status.set_markup (string_compose ("<b>%1</b>: <i>%2>%3</i>", _("Rec"), _("all"), PBD::ffs (midi_track()->get_capture_channel_mask())));
+ break;
+ }
+}