be smart, use boost::shared_ptr

This commit is contained in:
Robin Gareus 2014-06-15 04:54:39 +02:00
parent 21ed2d6767
commit 61ab4f0fb0
2 changed files with 84 additions and 83 deletions

View file

@ -1041,23 +1041,23 @@ EngineControl::parameter_changed ()
} }
} }
EngineControl::State* EngineControl::State
EngineControl::get_matching_state ( EngineControl::get_matching_state (
const string& backend, const string& backend,
const string& driver, const string& driver,
const string& device) const string& device)
{ {
for (StateList::iterator i = states.begin(); i != states.end(); ++i) { for (StateList::iterator i = states.begin(); i != states.end(); ++i) {
if ((*i).backend == backend && if ((*i)->backend == backend &&
(*i).driver == driver && (*i)->driver == driver &&
(*i).device == device) { (*i)->device == device) {
return &(*i); return (*i);
} }
} }
return 0; return State();
} }
EngineControl::State* EngineControl::State
EngineControl::get_saved_state_for_currently_displayed_backend_and_device () EngineControl::get_saved_state_for_currently_displayed_backend_and_device ()
{ {
boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend(); boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
@ -1074,44 +1074,44 @@ EngineControl::get_saved_state_for_currently_displayed_backend_and_device ()
device_combo.get_active_text()); device_combo.get_active_text());
} }
EngineControl::State* EngineControl::State
EngineControl::save_state () EngineControl::save_state ()
{ {
if (!_have_control) { if (!_have_control) {
return 0; return State();
} }
State* state = new State; State state (new StateStruct);
store_state (*state); store_state (state);
for (StateList::iterator i = states.begin(); i != states.end();) { for (StateList::iterator i = states.begin(); i != states.end();) {
if ((*i).backend == state->backend && if ((*i)->backend == state->backend &&
(*i).driver == state->driver && (*i)->driver == state->driver &&
(*i).device == state->device) { (*i)->device == state->device) {
i = states.erase(i); i = states.erase(i);
} else { } else {
++i; ++i;
} }
} }
states.push_back (*state); states.push_back (state);
return state; return state;
} }
void void
EngineControl::store_state (State& state) EngineControl::store_state (State state)
{ {
state.backend = get_backend (); state->backend = get_backend ();
state.driver = get_driver (); state->driver = get_driver ();
state.device = get_device_name (); state->device = get_device_name ();
state.sample_rate = get_rate (); state->sample_rate = get_rate ();
state.buffer_size = get_buffer_size (); state->buffer_size = get_buffer_size ();
state.input_latency = get_input_latency (); state->input_latency = get_input_latency ();
state.output_latency = get_output_latency (); state->output_latency = get_output_latency ();
state.input_channels = get_input_channels (); state->input_channels = get_input_channels ();
state.output_channels = get_output_channels (); state->output_channels = get_output_channels ();
state.midi_option = get_midi_option (); state->midi_option = get_midi_option ();
state.midi_devices = _midi_devices; state->midi_devices = _midi_devices;
} }
void void
@ -1121,7 +1121,7 @@ EngineControl::maybe_display_saved_state ()
return; return;
} }
State* state = get_saved_state_for_currently_displayed_backend_and_device (); State state = get_saved_state_for_currently_displayed_backend_and_device ();
if (state) { if (state) {
PBD::Unwinder<uint32_t> protect_ignore_changes (ignore_changes, ignore_changes + 1); PBD::Unwinder<uint32_t> protect_ignore_changes (ignore_changes, ignore_changes + 1);
@ -1157,20 +1157,20 @@ EngineControl::get_state ()
XMLNode* node = new XMLNode ("State"); XMLNode* node = new XMLNode ("State");
node->add_property ("backend", (*i).backend); node->add_property ("backend", (*i)->backend);
node->add_property ("driver", (*i).driver); node->add_property ("driver", (*i)->driver);
node->add_property ("device", (*i).device); node->add_property ("device", (*i)->device);
node->add_property ("sample-rate", (*i).sample_rate); node->add_property ("sample-rate", (*i)->sample_rate);
node->add_property ("buffer-size", (*i).buffer_size); node->add_property ("buffer-size", (*i)->buffer_size);
node->add_property ("input-latency", (*i).input_latency); node->add_property ("input-latency", (*i)->input_latency);
node->add_property ("output-latency", (*i).output_latency); node->add_property ("output-latency", (*i)->output_latency);
node->add_property ("input-channels", (*i).input_channels); node->add_property ("input-channels", (*i)->input_channels);
node->add_property ("output-channels", (*i).output_channels); node->add_property ("output-channels", (*i)->output_channels);
node->add_property ("active", (*i).active ? "yes" : "no"); node->add_property ("active", (*i)->active ? "yes" : "no");
node->add_property ("midi-option", (*i).midi_option); node->add_property ("midi-option", (*i)->midi_option);
XMLNode* midi_devices = new XMLNode ("MIDIDevices"); XMLNode* midi_devices = new XMLNode ("MIDIDevices");
for (std::vector<MidiDeviceSettings>::const_iterator p = (*i).midi_devices.begin(); p != (*i).midi_devices.end(); ++p) { for (std::vector<MidiDeviceSettings>::const_iterator p = (*i)->midi_devices.begin(); p != (*i)->midi_devices.end(); ++p) {
XMLNode* midi_device_stuff = new XMLNode ("MIDIDevice"); XMLNode* midi_device_stuff = new XMLNode ("MIDIDevice");
midi_device_stuff->add_property (X_("name"), (*p)->name); midi_device_stuff->add_property (X_("name"), (*p)->name);
midi_device_stuff->add_property (X_("enabled"), (*p)->enabled); midi_device_stuff->add_property (X_("enabled"), (*p)->enabled);
@ -1217,7 +1217,7 @@ EngineControl::set_state (const XMLNode& root)
cclist = child->children(); cclist = child->children();
for (cciter = cclist.begin(); cciter != cclist.end(); ++cciter) { for (cciter = cclist.begin(); cciter != cclist.end(); ++cciter) {
State state; State state (new StateStruct);
grandchild = *cciter; grandchild = *cciter;
@ -1228,59 +1228,59 @@ EngineControl::set_state (const XMLNode& root)
if ((prop = grandchild->property ("backend")) == 0) { if ((prop = grandchild->property ("backend")) == 0) {
continue; continue;
} }
state.backend = prop->value (); state->backend = prop->value ();
if ((prop = grandchild->property ("driver")) == 0) { if ((prop = grandchild->property ("driver")) == 0) {
continue; continue;
} }
state.driver = prop->value (); state->driver = prop->value ();
if ((prop = grandchild->property ("device")) == 0) { if ((prop = grandchild->property ("device")) == 0) {
continue; continue;
} }
state.device = prop->value (); state->device = prop->value ();
if ((prop = grandchild->property ("sample-rate")) == 0) { if ((prop = grandchild->property ("sample-rate")) == 0) {
continue; continue;
} }
state.sample_rate = atof (prop->value ()); state->sample_rate = atof (prop->value ());
if ((prop = grandchild->property ("buffer-size")) == 0) { if ((prop = grandchild->property ("buffer-size")) == 0) {
continue; continue;
} }
state.buffer_size = atoi (prop->value ()); state->buffer_size = atoi (prop->value ());
if ((prop = grandchild->property ("input-latency")) == 0) { if ((prop = grandchild->property ("input-latency")) == 0) {
continue; continue;
} }
state.input_latency = atoi (prop->value ()); state->input_latency = atoi (prop->value ());
if ((prop = grandchild->property ("output-latency")) == 0) { if ((prop = grandchild->property ("output-latency")) == 0) {
continue; continue;
} }
state.output_latency = atoi (prop->value ()); state->output_latency = atoi (prop->value ());
if ((prop = grandchild->property ("input-channels")) == 0) { if ((prop = grandchild->property ("input-channels")) == 0) {
continue; continue;
} }
state.input_channels = atoi (prop->value ()); state->input_channels = atoi (prop->value ());
if ((prop = grandchild->property ("output-channels")) == 0) { if ((prop = grandchild->property ("output-channels")) == 0) {
continue; continue;
} }
state.output_channels = atoi (prop->value ()); state->output_channels = atoi (prop->value ());
if ((prop = grandchild->property ("active")) == 0) { if ((prop = grandchild->property ("active")) == 0) {
continue; continue;
} }
state.active = string_is_affirmative (prop->value ()); state->active = string_is_affirmative (prop->value ());
if ((prop = grandchild->property ("midi-option")) == 0) { if ((prop = grandchild->property ("midi-option")) == 0) {
continue; continue;
} }
state.midi_option = prop->value (); state->midi_option = prop->value ();
state.midi_devices.clear(); state->midi_devices.clear();
XMLNode* midinode; XMLNode* midinode;
if ((midinode = find_named_node (*grandchild, "MIDIDevices")) != 0) { if ((midinode = find_named_node (*grandchild, "MIDIDevices")) != 0) {
const XMLNodeList mnc = midinode->children(); const XMLNodeList mnc = midinode->children();
@ -1299,7 +1299,7 @@ EngineControl::set_state (const XMLNode& root)
atoi ((*n)->property (X_("input-latency"))->value ()), atoi ((*n)->property (X_("input-latency"))->value ()),
atoi ((*n)->property (X_("output-latency"))->value ()) atoi ((*n)->property (X_("output-latency"))->value ())
)); ));
state.midi_devices.push_back (ptr); state->midi_devices.push_back (ptr);
} }
} }
@ -1308,9 +1308,9 @@ EngineControl::set_state (const XMLNode& root)
* this can be removed again before release * this can be removed again before release
*/ */
for (StateList::iterator i = states.begin(); i != states.end();) { for (StateList::iterator i = states.begin(); i != states.end();) {
if ((*i).backend == state.backend && if ((*i)->backend == state->backend &&
(*i).driver == state.driver && (*i)->driver == state->driver &&
(*i).device == state.device) { (*i)->device == state->device) {
i = states.erase(i); i = states.erase(i);
} else { } else {
++i; ++i;
@ -1326,16 +1326,16 @@ EngineControl::set_state (const XMLNode& root)
for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) { for (StateList::const_iterator i = states.begin(); i != states.end(); ++i) {
if ((*i).active) { if ((*i)->active) {
ignore_changes++; ignore_changes++;
backend_combo.set_active_text ((*i).backend); backend_combo.set_active_text ((*i)->backend);
driver_combo.set_active_text ((*i).driver); driver_combo.set_active_text ((*i)->driver);
device_combo.set_active_text ((*i).device); device_combo.set_active_text ((*i)->device);
sample_rate_combo.set_active_text (rate_as_string ((*i).sample_rate)); sample_rate_combo.set_active_text (rate_as_string ((*i)->sample_rate));
buffer_size_combo.set_active_text (bufsize_as_string ((*i).buffer_size)); buffer_size_combo.set_active_text (bufsize_as_string ((*i)->buffer_size));
input_latency.set_value ((*i).input_latency); input_latency.set_value ((*i)->input_latency);
output_latency.set_value ((*i).output_latency); output_latency.set_value ((*i)->output_latency);
midi_option_combo.set_active_text ((*i).midi_option); midi_option_combo.set_active_text ((*i)->midi_option);
ignore_changes--; ignore_changes--;
break; break;
} }
@ -1601,7 +1601,7 @@ EngineControl::post_push ()
*/ */
if (_have_control) { if (_have_control) {
State* state = get_saved_state_for_currently_displayed_backend_and_device (); State state = get_saved_state_for_currently_displayed_backend_and_device ();
if (!state) { if (!state) {
state = save_state (); state = save_state ();
@ -1611,7 +1611,7 @@ EngineControl::post_push ()
/* all off */ /* all off */
for (StateList::iterator i = states.begin(); i != states.end(); ++i) { for (StateList::iterator i = states.begin(); i != states.end(); ++i) {
(*i).active = false; (*i)->active = false;
} }
/* mark this one active (to be used next time the dialog is /* mark this one active (to be used next time the dialog is

View file

@ -42,14 +42,14 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
public: public:
EngineControl (); EngineControl ();
~EngineControl (); ~EngineControl ();
static bool need_setup (); static bool need_setup ();
XMLNode& get_state (); XMLNode& get_state ();
void set_state (const XMLNode&); void set_state (const XMLNode&);
void set_desired_sample_rate (uint32_t); void set_desired_sample_rate (uint32_t);
private: private:
Gtk::Notebook notebook; Gtk::Notebook notebook;
@ -110,9 +110,9 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
Gtk::Table midi_device_table; Gtk::Table midi_device_table;
/* MIDI ... JACK */ /* MIDI ... JACK */
Gtk::CheckButton aj_button; Gtk::CheckButton aj_button;
uint32_t ignore_changes; uint32_t ignore_changes;
uint32_t _desired_sample_rate; uint32_t _desired_sample_rate;
bool started_at_least_once; bool started_at_least_once;
@ -127,7 +127,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
void setup_midi_tab_for_backend (); void setup_midi_tab_for_backend ();
void setup_midi_tab_for_jack (); void setup_midi_tab_for_jack ();
void refresh_midi_display (std::string focus = ""); void refresh_midi_display (std::string focus = "");
std::string bufsize_as_string (uint32_t); std::string bufsize_as_string (uint32_t);
float get_rate() const; float get_rate() const;
@ -174,7 +174,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
return MidiDeviceSettings(); return MidiDeviceSettings();
} }
struct State { struct StateStruct {
std::string backend; std::string backend;
std::string driver; std::string driver;
std::string device; std::string device;
@ -188,7 +188,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
std::string midi_option; std::string midi_option;
std::vector<MidiDeviceSettings> midi_devices; std::vector<MidiDeviceSettings> midi_devices;
State() StateStruct()
: input_latency (0) : input_latency (0)
, output_latency (0) , output_latency (0)
, input_channels (0) , input_channels (0)
@ -196,18 +196,19 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
, active (false) {} , active (false) {}
}; };
typedef boost::shared_ptr<StateStruct> State;
typedef std::list<State> StateList; typedef std::list<State> StateList;
StateList states; StateList states;
State* get_matching_state (const std::string& backend, State get_matching_state (const std::string& backend,
const std::string& driver, const std::string& driver,
const std::string& device); const std::string& device);
State* get_saved_state_for_currently_displayed_backend_and_device (); State get_saved_state_for_currently_displayed_backend_and_device ();
void maybe_display_saved_state (); void maybe_display_saved_state ();
State* save_state (); State save_state ();
void store_state (State&); void store_state (State);
bool _have_control; bool _have_control;
@ -234,7 +235,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
void disable_latency_tab (); void disable_latency_tab ();
void start_latency_detection (); void start_latency_detection ();
void end_latency_detection (); void end_latency_detection ();
void on_switch_page (GtkNotebookPage*, guint page_num); void on_switch_page (GtkNotebookPage*, guint page_num);
bool on_delete_event (GdkEventAny*); bool on_delete_event (GdkEventAny*);