diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index 42f8fe6d7a..d688e9e629 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -1061,25 +1061,25 @@ AudioRegionView::set_flags (XMLNode* node) XMLProperty *prop; if ((prop = node->property ("waveform-visible")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { _flags |= WaveformVisible; } } if ((prop = node->property ("envelope-visible")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { _flags |= EnvelopeVisible; } } if ((prop = node->property ("waveform-rectified")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { _flags |= WaveformRectified; } } if ((prop = node->property ("waveform-logscaled")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { _flags |= WaveformLogScaled; } } diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 3a343f75b3..5aec06170e 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2337,7 +2337,7 @@ Editor::set_state (const XMLNode& node) } if ((prop = node.property ("internal-edit"))) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); RefPtr act = ActionManager::get_action (X_("MouseMode"), X_("toggle-internal-edit")); if (act) { RefPtr tact = RefPtr::cast_dynamic(act); @@ -2351,7 +2351,7 @@ Editor::set_state (const XMLNode& node) } if ((prop = node.property ("show-waveforms-recording"))) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); _show_waveforms_recording = !yn; RefPtr act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording")); if (act) { @@ -2363,7 +2363,7 @@ Editor::set_state (const XMLNode& node) } if ((prop = node.property ("show-measures"))) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); _show_measures = !yn; RefPtr act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility")); if (act) { @@ -2375,7 +2375,7 @@ Editor::set_state (const XMLNode& node) } if ((prop = node.property ("follow-playhead"))) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); set_follow_playhead (yn); RefPtr act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead")); if (act) { @@ -2391,7 +2391,7 @@ Editor::set_state (const XMLNode& node) } if ((prop = node.property ("xfades-visible"))) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); _xfade_visibility = !yn; // set_xfade_visibility (yn); } @@ -2402,7 +2402,7 @@ Editor::set_state (const XMLNode& node) if (act) { Glib::RefPtr tact = Glib::RefPtr::cast_dynamic(act); - bool yn = (prop->value() == X_("yes")); + bool yn = string_is_affirmative (prop->value()); /* do it twice to force the change */ @@ -2418,7 +2418,7 @@ Editor::set_state (const XMLNode& node) if (act) { Glib::RefPtr tact = Glib::RefPtr::cast_dynamic(act); - bool yn = (prop->value() == X_("yes")); + bool yn = string_is_affirmative (prop->value()); /* do it twice to force the change */ diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index c37d7d68d1..3f1fc6a497 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -455,56 +455,56 @@ Editor::restore_ruler_visibility () if (node) { if ((prop = node->property ("smpte")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_timecode_action->set_active (true); } else { ruler_timecode_action->set_active (false); } } if ((prop = node->property ("bbt")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_bbt_action->set_active (true); } else { ruler_bbt_action->set_active (false); } } if ((prop = node->property ("frames")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_samples_action->set_active (true); } else { ruler_samples_action->set_active (false); } } if ((prop = node->property ("minsec")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_minsec_action->set_active (true); } else { ruler_minsec_action->set_active (false); } } if ((prop = node->property ("tempo")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_tempo_action->set_active (true); } else { ruler_tempo_action->set_active (false); } } if ((prop = node->property ("meter")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_meter_action->set_active (true); } else { ruler_meter_action->set_active (false); } } if ((prop = node->property ("marker")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_marker_action->set_active (true); } else { ruler_marker_action->set_active (false); } } if ((prop = node->property ("rangemarker")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_range_action->set_active (true); } else { ruler_range_action->set_active (false); @@ -512,7 +512,7 @@ Editor::restore_ruler_visibility () } if ((prop = node->property ("transportmarker")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_loop_punch_action->set_active (true); } else { ruler_loop_punch_action->set_active (false); @@ -520,7 +520,7 @@ Editor::restore_ruler_visibility () } if ((prop = node->property ("cdmarker")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { ruler_cd_marker_action->set_active (true); } else { ruler_cd_marker_action->set_active (false); diff --git a/gtk2_ardour/mixer_ui.cc b/gtk2_ardour/mixer_ui.cc index 2e9cfff614..aa4c4119c6 100644 --- a/gtk2_ardour/mixer_ui.cc +++ b/gtk2_ardour/mixer_ui.cc @@ -1329,7 +1329,7 @@ Mixer_UI::set_state (const XMLNode& node) set_window_pos_and_size (); if ((prop = node.property ("narrow-strips"))) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { set_strip_width (Narrow); } else { set_strip_width (Wide); @@ -1337,7 +1337,7 @@ Mixer_UI::set_state (const XMLNode& node) } if ((prop = node.property ("show-mixer"))) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { _visible = true; } } diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index cbd2bc5492..68ca7008c7 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -399,7 +399,7 @@ RouteTimeAxisView::set_state (const XMLNode& node) if ((prop = (*iter)->property ("automation-id")) != 0) { Evoral::Parameter param = ARDOUR::EventTypeMap::instance().new_parameter(prop->value()); - bool show = ((prop = (*iter)->property ("shown")) != 0) && prop->value() == "yes"; + bool show = ((prop = (*iter)->property ("shown")) != 0) && string_is_affirmative (prop->value()); create_automation_child(param, show); } else { warning << "Automation child has no ID" << endmsg; @@ -1965,7 +1965,7 @@ RouteTimeAxisView::add_automation_child(Evoral::Parameter param, boost::shared_p if ((node = track->get_state_node()) != 0) { if ((prop = node->property ("shown")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { hideit = false; } } diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index 2ccc61bb9c..dc6c1b8479 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -39,6 +39,8 @@ class XMLNode; Glib::ustring legalize_for_path (Glib::ustring str); std::ostream& operator<< (std::ostream& o, const ARDOUR::BBT_Time& bbt); XMLNode* find_named_node (const XMLNode& node, std::string name); +std::string bool_as_string (bool); +bool string_is_affirmative (const std::string&); static inline float f_max(float x, float a) { x -= a; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 2c6c9fc0aa..89debf82c7 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -714,7 +714,7 @@ AudioRegion::set_live_state (const XMLNode& node, Change& what_changed, bool sen } if ((prop = child->property ("active")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { set_fade_in_active (true); } else { set_fade_in_active (true); @@ -735,7 +735,7 @@ AudioRegion::set_live_state (const XMLNode& node, Change& what_changed, bool sen } if ((prop = child->property ("active")) != 0) { - if (prop->value() == "yes") { + if (string_is_affirmative (prop->value())) { set_fade_out_active (true); } else { set_fade_out_active (false); diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc index 90d8198ec4..be173e7102 100644 --- a/libs/ardour/control_protocol_manager.cc +++ b/libs/ardour/control_protocol_manager.cc @@ -304,7 +304,7 @@ ControlProtocolManager::set_state (const XMLNode& node) prop = (*citer)->property (X_("active")); - if (prop && prop->value() == X_("yes")) { + if (prop && string_is_affirmative (prop->value())) { if ((prop = (*citer)->property (X_("name"))) != 0) { ControlProtocolInfo* cpi = cpi_by_name (prop->value()); if (cpi) { diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index 86d509ec66..2d46c0c01a 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -743,7 +743,7 @@ Crossfade::set_state (const XMLNode& node) } if ((prop = node.property ("active")) != 0) { - bool x = (prop->value() == "yes"); + bool x = string_is_affirmative (prop->value()); if (x != _active) { _active = x; what_changed = Change (what_changed | ActiveChanged); @@ -753,13 +753,13 @@ Crossfade::set_state (const XMLNode& node) } if ((prop = node.property ("follow-overlap")) != 0) { - _follow_overlap = (prop->value() == "yes"); + _follow_overlap = string_is_affirmative (prop->value()); } else { _follow_overlap = false; } if ((prop = node.property ("fixed")) != 0) { - _fixed = (prop->value() == "yes"); + _fixed = string_is_affirmative (prop->value()); } else { _fixed = false; } diff --git a/libs/ardour/io_processor.cc b/libs/ardour/io_processor.cc index 505d33a1b0..1408cdcafb 100644 --- a/libs/ardour/io_processor.cc +++ b/libs/ardour/io_processor.cc @@ -155,11 +155,11 @@ IOProcessor::set_state (const XMLNode& node) Processor::set_state(node); if ((prop = node.property ("own-input")) != 0) { - _own_input = (prop->value() == "yes"); + _own_input = string_is_affirmative (prop->value()); } if ((prop = node.property ("own-output")) != 0) { - _own_output = (prop->value() == "yes"); + _own_output = string_is_affirmative (prop->value()); } /* don't attempt to set state for a proxied IO that we don't own */ diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index b66d0f3942..c232b9738e 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -402,7 +402,7 @@ Location::set_state (const XMLNode& node) _flags = Flags (string_2_enum (prop->value(), _flags)); if ((prop = node.property ("locked")) != 0) { - _locked = (prop->value() == "yes"); + _locked = string_is_affirmative (prop->value()); } else { _locked = false; } diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc index f43741300a..d23929232a 100644 --- a/libs/ardour/panner.cc +++ b/libs/ardour/panner.cc @@ -168,7 +168,7 @@ StreamPanner::set_state (const XMLNode& node) XMLNodeConstIterator iter; if ((prop = node.property (X_("muted")))) { - set_muted (prop->value() == "yes"); + set_muted (string_is_affirmative (prop->value())); } return 0; @@ -1104,12 +1104,12 @@ Panner::set_state (const XMLNode& node) outputs.clear (); if ((prop = node.property (X_("linked"))) != 0) { - set_linked (prop->value() == "yes"); + set_linked (string_is_affirmative (prop->value())); } if ((prop = node.property (X_("bypassed"))) != 0) { - set_bypassed (prop->value() == "yes"); + set_bypassed (string_is_affirmative (prop->value())); } if ((prop = node.property (X_("link_direction"))) != 0) { diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index cd53f35d95..53d749db82 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -1820,7 +1820,7 @@ Playlist::set_state (const XMLNode& node) } else if (prop->name() == X_("orig_diskstream_id")) { _orig_diskstream_id = prop->value (); } else if (prop->name() == X_("frozen")) { - _frozen = (prop->value() == X_("yes")); + _frozen = string_is_affirmative (prop->value()); } } diff --git a/libs/ardour/processor.cc b/libs/ardour/processor.cc index 04706c0c2d..6f32afc925 100644 --- a/libs/ardour/processor.cc +++ b/libs/ardour/processor.cc @@ -212,7 +212,7 @@ Processor::set_state (const XMLNode& node) } } - if (_active != (prop->value() == "yes")) { + if (_active != string_is_affirmative (prop->value())) { _active = !_active; ActiveChanged (); /* EMIT_SIGNAL */ } diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 1cb7b84bc9..5595ac3972 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1667,25 +1667,25 @@ Route::_set_state (const XMLNode& node, bool /*call_base*/) } if ((prop = node.property ("solo-isolated")) != 0) { - set_solo_isolated (prop->value() == "yes", this); + set_solo_isolated (string_is_affirmative (prop->value()), this); } if ((prop = node.property (X_("phase-invert"))) != 0) { - set_phase_invert (prop->value()=="yes"?true:false); + set_phase_invert (string_is_affirmative (prop->value())); } if ((prop = node.property (X_("denormal-protection"))) != 0) { - set_denormal_protection (prop->value()=="yes"?true:false); + set_denormal_protection (string_is_affirmative (prop->value())); } if ((prop = node.property (X_("active"))) != 0) { - bool yn = (prop->value() == "yes"); + bool yn = string_is_affirmative (prop->value()); _active = !yn; // force switch set_active (yn); } if ((prop = node.property (X_("soloed"))) != 0) { - bool yn = (prop->value()=="yes"); + bool yn = string_is_affirmative (prop->value()); /* XXX force reset of solo status */ diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index a2307901bc..2ee0e456fc 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -107,7 +107,7 @@ TempoSection::TempoSection (const XMLNode& node) throw failed_constructor(); } - set_movable (prop->value() == "yes"); + set_movable (string_is_affirmative (prop->value())); } XMLNode& @@ -183,7 +183,7 @@ MeterSection::MeterSection (const XMLNode& node) throw failed_constructor(); } - set_movable (prop->value() == "yes"); + set_movable (string_is_affirmative (prop->value())); } XMLNode& diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index e12ae2cd89..c8e6b1145f 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -506,6 +506,29 @@ ARDOUR::auto_style_to_string (AutoStyle as) return ""; } +std::string +bool_as_string (bool yn) +{ + return (yn ? "yes" : "no"); +} + +bool +string_is_affirmative (const std::string& str) +{ + /* to be used only with XML data - not intended to handle user input */ + + if (str == "1" || str == "y" || str == "Y") { + return true; + } else { + std::string str_uc; + std::transform(str.begin(), str.end(), str_uc.begin(), ::toupper); + if (str_uc == "YES") { + return true; + } + } + return false; +} + extern "C" { void c_stacktrace() { stacktrace (cerr); } }