Factor out instrument selector.

This commit is contained in:
David Robillard 2014-12-24 18:39:15 -05:00
parent 49b7a46805
commit 10ad55fcf5
6 changed files with 161 additions and 77 deletions

View File

@ -659,6 +659,10 @@
RelativePath="..\gtk2_ardour\insert_time_dialog.cc"
>
</File>
<File
RelativePath="..\gtk2_ardour\instrument_selector.cc"
>
</File>
<File
RelativePath="..\gtk2_ardour\interthread_progress_window.cc"
>

View File

@ -57,7 +57,6 @@ AddRouteDialog::AddRouteDialog ()
, configuration_label (_("Configuration:"))
, mode_label (_("Track mode:"))
, instrument_label (_("Instrument:"))
, reasonable_synth_id(0)
{
set_name ("AddRouteDialog");
set_modal (true);
@ -81,12 +80,6 @@ AddRouteDialog::AddRouteDialog ()
track_bus_combo.append_text (_("Busses"));
track_bus_combo.set_active (0);
build_instrument_list ();
instrument_combo.set_model (instrument_list);
instrument_combo.pack_start (instrument_list_columns.name);
instrument_combo.set_active (reasonable_synth_id);
instrument_combo.set_button_sensitivity (Gtk::SENSITIVITY_AUTO);
VBox* vbox = manage (new VBox);
Gtk::Label* l;
@ -561,61 +554,8 @@ AddRouteDialog::route_separator (const Glib::RefPtr<Gtk::TreeModel> &, const Gtk
return route_group_combo.get_active_text () == "separator";
}
void
AddRouteDialog::build_instrument_list ()
{
PluginInfoList all_plugs;
PluginManager& manager (PluginManager::instance());
TreeModel::Row row;
all_plugs.insert (all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
#ifdef WINDOWS_VST_SUPPORT
all_plugs.insert (all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
#endif
#ifdef LXVST_SUPPORT
all_plugs.insert (all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
#endif
#ifdef AUDIOUNIT_SUPPORT
all_plugs.insert (all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
#endif
#ifdef LV2_SUPPORT
all_plugs.insert (all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
#endif
instrument_list = ListStore::create (instrument_list_columns);
row = *(instrument_list->append());
row[instrument_list_columns.info_ptr] = PluginInfoPtr ();
row[instrument_list_columns.name] = _("-none-");
uint32_t n = 1;
for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
if (manager.get_status (*i) == PluginManager::Hidden) continue;
if ((*i)->is_instrument()) {
row = *(instrument_list->append());
row[instrument_list_columns.name] = (*i)->name;
row[instrument_list_columns.info_ptr] = *i;
if ((*i)->unique_id == "https://community.ardour.org/node/7596") {
reasonable_synth_id = n;
}
n++;
}
}
}
PluginInfoPtr
AddRouteDialog::requested_instrument ()
{
TreeModel::iterator iter = instrument_combo.get_active ();
TreeModel::Row row;
if (iter) {
row = (*iter);
return row[instrument_list_columns.info_ptr];
}
return PluginInfoPtr();
return instrument_combo.selected_instrument();
}

View File

@ -39,6 +39,7 @@
#include "ardour/template_utils.h"
#include "ardour_dialog.h"
#include "instrument_selector.h"
class Editor;
@ -78,7 +79,7 @@ class AddRouteDialog : public ArdourDialog
Gtk::Label instrument_label;
Gtk::ComboBoxText mode_combo;
Gtk::ComboBoxText route_group_combo;
Gtk::ComboBox instrument_combo;
InstrumentSelector instrument_combo;
std::vector<ARDOUR::TemplateInfo> route_templates;
@ -108,21 +109,6 @@ class AddRouteDialog : public ArdourDialog
static std::vector<std::string> channel_combo_strings;
static std::vector<std::string> bus_mode_strings;
struct InstrumentListColumns : public Gtk::TreeModel::ColumnRecord {
InstrumentListColumns () {
add (name);
add (info_ptr);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<ARDOUR::PluginInfoPtr> info_ptr;
};
Glib::RefPtr<Gtk::ListStore> instrument_list;
InstrumentListColumns instrument_list_columns;
void build_instrument_list ();
uint32_t reasonable_synth_id;
};
#endif /* __gtk_ardour_add_route_dialog_h__ */

View File

@ -0,0 +1,92 @@
/*
Copyright (C) 2003-2014 Paul Davis
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "ardour/plugin_manager.h"
#include "instrument_selector.h"
#include "i18n.h"
using namespace Gtk;
using namespace ARDOUR;
InstrumentSelector::InstrumentSelector()
: _reasonable_synth_id(0)
{
build_instrument_list();
set_model(_instrument_list);
pack_start(_instrument_list_columns.name);
set_active(_reasonable_synth_id);
set_button_sensitivity(Gtk::SENSITIVITY_AUTO);
}
void
InstrumentSelector::build_instrument_list()
{
PluginManager& manager = PluginManager::instance();
PluginInfoList all_plugs;
all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
#ifdef WINDOWS_VST_SUPPORT
all_plugs.insert(all_plugs.end(), manager.windows_vst_plugin_info().begin(), manager.windows_vst_plugin_info().end());
#endif
#ifdef LXVST_SUPPORT
all_plugs.insert(all_plugs.end(), manager.lxvst_plugin_info().begin(), manager.lxvst_plugin_info().end());
#endif
#ifdef AUDIOUNIT_SUPPORT
all_plugs.insert(all_plugs.end(), manager.au_plugin_info().begin(), manager.au_plugin_info().end());
#endif
#ifdef LV2_SUPPORT
all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
#endif
_instrument_list = ListStore::create(_instrument_list_columns);
TreeModel::Row row = *(_instrument_list->append());
row[_instrument_list_columns.info_ptr] = PluginInfoPtr();
row[_instrument_list_columns.name] = _("-none-");
uint32_t n = 1;
for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
if (manager.get_status(*i) == PluginManager::Hidden) {
continue;
}
if ((*i)->is_instrument()) {
row = *(_instrument_list->append());
row[_instrument_list_columns.name] = (*i)->name;
row[_instrument_list_columns.info_ptr] = *i;
if ((*i)->unique_id == "https://community.ardour.org/node/7596") {
_reasonable_synth_id = n;
}
n++;
}
}
}
PluginInfoPtr
InstrumentSelector::selected_instrument()
{
TreeModel::iterator iter = get_active();
if (!iter) {
return PluginInfoPtr();
}
const TreeModel::Row& row = (*iter);
return row[_instrument_list_columns.info_ptr];
}

View File

@ -0,0 +1,61 @@
/*
Copyright (C) 2000-2014 Paul Davis
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __gtk_ardour_instrument_selector_h__
#define __gtk_ardour_instrument_selector_h__
#include <string>
#include <gtkmm/combobox.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/liststore.h>
#include "ardour/plugin.h"
#include "ardour/types.h"
#include "ardour/template_utils.h"
#include "ardour_dialog.h"
class Editor;
class InstrumentSelector : public Gtk::ComboBox
{
public:
InstrumentSelector();
ARDOUR::PluginInfoPtr selected_instrument();
private:
struct InstrumentListColumns : public Gtk::TreeModel::ColumnRecord {
InstrumentListColumns() {
add(name);
add(info_ptr);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<ARDOUR::PluginInfoPtr> info_ptr;
};
void build_instrument_list();
Glib::RefPtr<Gtk::ListStore> _instrument_list;
InstrumentListColumns _instrument_list_columns;
uint32_t _reasonable_synth_id;
};
#endif /* __gtk_ardour_instrument_selector_h__ */

View File

@ -109,6 +109,7 @@ gtk2_ardour_sources = [
'gtk_pianokeyboard.c',
'gui_object.cc',
'insert_time_dialog.cc',
'instrument_selector.cc',
'interthread_progress_window.cc',
'io_selector.cc',
'hit.cc',