diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 9e9e7efe86..94a07e4fdd 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1809,8 +1809,14 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch, const _patch_changes.push_back (patch_change); } -void -MidiRegionView::get_patch_key_at (Evoral::MusicalTime time, uint8_t channel, MIDI::Name::PatchPrimaryKey& key) +MIDI::Name::PatchPrimaryKey +MidiRegionView::patch_change_to_patch_key (MidiModel::PatchChangePtr p) +{ + return MIDI::Name::PatchPrimaryKey (p->program(), p->bank()); +} + +void +MidiRegionView::get_patch_key_at (double time, uint8_t channel, MIDI::Name::PatchPrimaryKey& key) { MidiModel::PatchChanges::iterator i = _model->patch_change_lower_bound (time); while (i != _model->patch_changes().end() && (*i)->channel() != channel) { @@ -1827,7 +1833,6 @@ MidiRegionView::get_patch_key_at (Evoral::MusicalTime time, uint8_t channel, MID assert (key.is_sane()); } - void MidiRegionView::change_patch_change (CanvasPatchChange& pc, const MIDI::Name::PatchPrimaryKey& new_patch) { @@ -1926,8 +1931,7 @@ void MidiRegionView::previous_patch (CanvasPatchChange& patch) { if (patch.patch()->program() < 127) { - MIDI::Name::PatchPrimaryKey key; - get_patch_key_at (patch.patch()->time(), patch.patch()->channel(), key); + MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch()); key.program_number++; change_patch_change (patch, key); } @@ -1937,8 +1941,7 @@ void MidiRegionView::next_patch (CanvasPatchChange& patch) { if (patch.patch()->program() > 0) { - MIDI::Name::PatchPrimaryKey key; - get_patch_key_at (patch.patch()->time(), patch.patch()->channel(), key); + MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch()); key.program_number--; change_patch_change (patch, key); } @@ -1948,8 +1951,7 @@ void MidiRegionView::previous_bank (CanvasPatchChange& patch) { if (patch.patch()->program() < 127) { - MIDI::Name::PatchPrimaryKey key; - get_patch_key_at (patch.patch()->time(), patch.patch()->channel(), key); + MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch()); if (key.bank_number > 0) { key.bank_number--; change_patch_change (patch, key); @@ -1961,8 +1963,7 @@ void MidiRegionView::next_bank (CanvasPatchChange& patch) { if (patch.patch()->program() > 0) { - MIDI::Name::PatchPrimaryKey key; - get_patch_key_at (patch.patch()->time(), patch.patch()->channel(), key); + MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key (patch.patch()); if (key.bank_number < 127) { key.bank_number++; change_patch_change (patch, key); diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 1b22029151..86600e8b8d 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -127,7 +127,11 @@ public: * @key a reference to an instance of MIDI::Name::PatchPrimaryKey whose fields will * will be set according to the result of the lookup */ - void get_patch_key_at(double time, uint8_t channel, MIDI::Name::PatchPrimaryKey& key); + void get_patch_key_at (double time, uint8_t channel, MIDI::Name::PatchPrimaryKey& key); + + /** Convert a given PatchChange into a PatchPrimaryKey + */ + MIDI::Name::PatchPrimaryKey patch_change_to_patch_key (ARDOUR::MidiModel::PatchChangePtr); /** Change old_patch to new_patch. * @param old_patch the canvas patch change which is to be altered diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index df5d4b1b97..1657e11bfb 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -208,8 +208,8 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) _model_selector.set_active_text (gui_property (X_("midnam-model-name"))); _custom_device_mode_selector.set_active_text (gui_property (X_("midnam-custom-device-mode"))); - ARDOUR_UI::instance()->set_tip (_model_selector, _("external MIDI Device selector")); - ARDOUR_UI::instance()->set_tip (_custom_device_mode_selector, _("external MIDI Device Mode")); + ARDOUR_UI::instance()->set_tip (_model_selector, _("External MIDI Device")); + ARDOUR_UI::instance()->set_tip (_custom_device_mode_selector, _("External Device Mode")); midi_controls_hbox->pack_start(_channel_selector, true, false); if (!patch_manager.all_models().empty()) { diff --git a/libs/ardour/ardour/midi_patch_manager.h b/libs/ardour/ardour/midi_patch_manager.h index 13c034fbc6..32b3ebc61d 100644 --- a/libs/ardour/ardour/midi_patch_manager.h +++ b/libs/ardour/ardour/midi_patch_manager.h @@ -74,7 +74,6 @@ public: if (master_device != 0 && custom_device_mode != "") { return master_device->channel_name_set_by_device_mode_and_channel(custom_device_mode, channel); } else { - std::cerr << "No MD for " << model << " + " << custom_device_mode << std::endl; return boost::shared_ptr(); } } @@ -88,10 +87,8 @@ public: boost::shared_ptr channel_name_set = find_channel_name_set(model, custom_device_mode, channel); if (channel_name_set) { - std::cerr << "found CNS for " << model << " + " << custom_device_mode << std::endl; return channel_name_set->find_patch(patch_key); } else { - std::cerr << "no CNS for " << model << " + " << custom_device_mode << std::endl; return boost::shared_ptr(); } } diff --git a/libs/midi++2/midi++/midnam_patch.h b/libs/midi++2/midi++/midnam_patch.h index 7a570ad3ff..f3ff434a9f 100644 --- a/libs/midi++2/midi++/midnam_patch.h +++ b/libs/midi++2/midi++/midnam_patch.h @@ -198,8 +198,10 @@ public: int set_state (const XMLTree&, const XMLNode&); void set_patch_banks (const PatchBanks&); + void use_patch_name_list (const PatchBank::PatchNameList&); private: + friend std::ostream& operator<< (std::ostream&, const ChannelNameSet&); std::string _name; AvailableForChannels _available_for_channels; PatchBanks _patch_banks; @@ -208,6 +210,8 @@ private: std::string _patch_list_name; }; +std::ostream& operator<< (std::ostream&, const ChannelNameSet&); + class Note { public: @@ -298,18 +302,9 @@ public: const CustomDeviceModeNames& custom_device_mode_names() const { return _custom_device_mode_names; } - boost::shared_ptr custom_device_mode_by_name(std::string mode_name) { - assert(mode_name != ""); - return _custom_device_modes[mode_name]; - } - - boost::shared_ptr channel_name_set_by_device_mode_and_channel(std::string mode, uint8_t channel) { - return _channel_name_sets[custom_device_mode_by_name(mode)->channel_name_set_name_by_channel(channel)]; - } - - boost::shared_ptr find_patch(std::string mode, uint8_t channel, PatchPrimaryKey& key) { - return channel_name_set_by_device_mode_and_channel(mode, channel)->find_patch(key); - } + boost::shared_ptr custom_device_mode_by_name(std::string mode_name); + boost::shared_ptr channel_name_set_by_device_mode_and_channel(std::string mode, uint8_t channel); + boost::shared_ptr find_patch(std::string mode, uint8_t channel, PatchPrimaryKey& key); XMLNode& get_state (void); int set_state (const XMLTree&, const XMLNode&); diff --git a/libs/midi++2/midnam_patch.cc b/libs/midi++2/midnam_patch.cc index fea9c09704..2b32fee42e 100644 --- a/libs/midi++2/midnam_patch.cc +++ b/libs/midi++2/midnam_patch.cc @@ -235,7 +235,7 @@ PatchBank::set_patch_name_list (const PatchNameList& pnl) { _patch_name_list = pnl; _patch_list_name = ""; - + for (PatchNameList::iterator p = _patch_name_list.begin(); p != _patch_name_list.end(); p++) { (*p)->set_bank_number (_number); } @@ -243,6 +243,29 @@ PatchBank::set_patch_name_list (const PatchNameList& pnl) return 0; } +std::ostream& +operator<< (std::ostream& os, const ChannelNameSet& cns) +{ + os << "Channel Name Set: name = " << cns._name << endl + << "Map size " << cns._patch_map.size () << endl + << "List size " << cns._patch_list.size() << endl + << "Patch list name = [" << cns._patch_list_name << ']' << endl + << "Available channels : "; + for (set::iterator x = cns._available_for_channels.begin(); x != cns._available_for_channels.end(); ++x) { + os << (int) (*x) << ' '; + } + os << endl; + + for (ChannelNameSet::PatchBanks::const_iterator pbi = cns._patch_banks.begin(); pbi != cns._patch_banks.end(); ++pbi) { + os << "\tPatch Bank " << (*pbi)->name() << " with " << (*pbi)->patch_name_list().size() << " patches\n"; + for (PatchBank::PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) { + os << "\t\tPatch name " << (*pni)->name() << " prog " << (int) (*pni)->program_number() << " bank " << (*pni)->bank_number() << endl; + } + } + + return os; +} + void ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb) { @@ -265,6 +288,15 @@ ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb) } } +void +ChannelNameSet::use_patch_name_list (const PatchBank::PatchNameList& pnl) +{ + for (PatchBank::PatchNameList::const_iterator p = pnl.begin(); p != pnl.end(); ++p) { + _patch_map[(*p)->patch_primary_key()] = (*p); + _patch_list.push_back ((*p)->patch_primary_key()); + } +} + XMLNode& ChannelNameSet::get_state (void) { @@ -369,6 +401,27 @@ CustomDeviceMode::get_state(void) return *custom_device_mode; } +boost::shared_ptr +MasterDeviceNames::custom_device_mode_by_name(std::string mode_name) +{ + assert(mode_name != ""); + return _custom_device_modes[mode_name]; +} + +boost::shared_ptr +MasterDeviceNames::channel_name_set_by_device_mode_and_channel(std::string mode, uint8_t channel) +{ + boost::shared_ptr cdm = custom_device_mode_by_name(mode); + boost::shared_ptr cns = _channel_name_sets[cdm->channel_name_set_name_by_channel(channel)]; + return cns; +} + +boost::shared_ptr +MasterDeviceNames::find_patch(std::string mode, uint8_t channel, PatchPrimaryKey& key) +{ + return channel_name_set_by_device_mode_and_channel(mode, channel)->find_patch(key); +} + int MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode& a_node) { @@ -448,20 +501,23 @@ MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode& a_node) for (ChannelNameSets::iterator cns = _channel_name_sets.begin(); cns != _channel_name_sets.end(); ++cns) { ChannelNameSet::PatchBanks pbs = cns->second->patch_banks(); + PatchNameLists::iterator p; + for (ChannelNameSet::PatchBanks::iterator pb = pbs.begin(); pb != pbs.end(); ++pb) { std::string pln = (*pb)->patch_list_name(); if (!pln.empty()) { - PatchNameLists::iterator p = _patch_name_lists.find (pln); - if (p != _patch_name_lists.end()) { + if ((p = _patch_name_lists.find (pln)) != _patch_name_lists.end()) { if ((*pb)->set_patch_name_list (p->second)) { return -1; } + cns->second->use_patch_name_list (p->second); } else { error << string_compose ("Patch list name %1 was not found - patch file ignored", pln) << endmsg; return -1; } } } + } return 0;