+
+ if (_session && Config->get_always_play_range() && !_session->transport_rolling() && !selection->time.empty()) {
+ _session->request_locate (selection->time.start());
+ }
+}
+
+/** Set all region actions to have a given sensitivity */
+void
+Editor::sensitize_all_region_actions (bool s)
+{
+ Glib::ListHandle<Glib::RefPtr<Action> > all = _region_actions->get_actions ();
+
+ for (Glib::ListHandle<Glib::RefPtr<Action> >::iterator i = all.begin(); i != all.end(); ++i) {
+ (*i)->set_sensitive (s);
+ }
+
+ _all_region_actions_sensitized = s;
+}
+
+/** Sensitize region-based actions based on the selection ONLY, ignoring the entered_regionview.
+ * This method should be called just before displaying a Region menu. When a Region menu is not
+ * currently being shown, all region actions are sensitized so that hotkey-triggered actions
+ * on entered_regionviews work without having to check sensitivity every time the selection or
+ * entered_regionview changes.
+ *
+ * This method also sets up toggle action state as appropriate.
+ */
+void
+Editor::sensitize_the_right_region_actions ()
+{
+
+ RegionSelection rs = get_regions_from_selection_and_entered ();
+ sensitize_all_region_actions (!rs.empty ());
+
+ _ignore_region_action = true;
+
+ /* Look through the regions that are selected and make notes about what we have got */
+
+ bool have_audio = false;
+ bool have_multichannel_audio = false;
+ bool have_midi = false;
+ bool have_locked = false;
+ bool have_unlocked = false;
+ bool have_video_locked = false;
+ bool have_video_unlocked = false;
+ bool have_position_lock_style_audio = false;
+ bool have_position_lock_style_music = false;
+ bool have_muted = false;
+ bool have_unmuted = false;
+ bool have_opaque = false;
+ bool have_non_opaque = false;
+ bool have_not_at_natural_position = false;
+ bool have_envelope_active = false;
+ bool have_envelope_inactive = false;
+ bool have_non_unity_scale_amplitude = false;
+ bool have_compound_regions = false;
+ bool have_inactive_fade_in = false;
+ bool have_inactive_fade_out = false;
+ bool have_active_fade_in = false;
+ bool have_active_fade_out = false;
+
+ for (list<RegionView*>::const_iterator i = rs.begin(); i != rs.end(); ++i) {
+
+ boost::shared_ptr<Region> r = (*i)->region ();
+ boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
+
+ if (ar) {
+ have_audio = true;
+ if (ar->n_channels() > 1) {
+ have_multichannel_audio = true;
+ }
+ }
+
+ if (boost::dynamic_pointer_cast<MidiRegion> (r)) {
+ have_midi = true;
+ }
+
+ if (r->is_compound()) {
+ have_compound_regions = true;
+ }
+
+ if (r->locked()) {
+ have_locked = true;
+ } else {
+ have_unlocked = true;
+ }
+
+ if (r->video_locked()) {
+ have_video_locked = true;
+ } else {
+ have_video_unlocked = true;
+ }
+
+ if (r->position_lock_style() == MusicTime) {
+ have_position_lock_style_music = true;
+ } else {
+ have_position_lock_style_audio = true;
+ }
+
+ if (r->muted()) {
+ have_muted = true;
+ } else {
+ have_unmuted = true;
+ }
+
+ if (r->opaque()) {
+ have_opaque = true;
+ } else {
+ have_non_opaque = true;
+ }
+
+ if (!r->at_natural_position()) {
+ have_not_at_natural_position = true;
+ }
+
+ if (ar) {
+ if (ar->envelope_active()) {
+ have_envelope_active = true;
+ } else {
+ have_envelope_inactive = true;
+ }
+
+ if (ar->scale_amplitude() != 1) {
+ have_non_unity_scale_amplitude = true;
+ }
+
+ if (ar->fade_in_active ()) {
+ have_active_fade_in = true;
+ } else {
+ have_inactive_fade_in = true;
+ }
+
+ if (ar->fade_out_active ()) {
+ have_active_fade_out = true;
+ } else {
+ have_inactive_fade_out = true;
+ }
+ }
+ }
+
+ if (rs.size() > 1) {
+ _region_actions->get_action("show-region-list-editor")->set_sensitive (false);
+ _region_actions->get_action("show-region-properties")->set_sensitive (false);
+ _region_actions->get_action("rename-region")->set_sensitive (false);
+ if (have_audio) {
+ /* XXX need to check whether there is than 1 per
+ playlist, because otherwise this makes no sense.
+ */
+ _region_actions->get_action("combine-regions")->set_sensitive (true);
+ } else {
+ _region_actions->get_action("combine-regions")->set_sensitive (false);
+ }
+ } else if (rs.size() == 1) {
+ _region_actions->get_action("add-range-markers-from-region")->set_sensitive (false);
+ _region_actions->get_action("close-region-gaps")->set_sensitive (false);
+ _region_actions->get_action("combine-regions")->set_sensitive (false);
+ }
+
+ if (!have_multichannel_audio) {
+ _region_actions->get_action("split-multichannel-region")->set_sensitive (false);
+ }
+
+ if (!have_midi) {
+ editor_menu_actions->get_action("RegionMenuMIDI")->set_sensitive (false);
+ _region_actions->get_action("show-region-list-editor")->set_sensitive (false);
+ _region_actions->get_action("quantize-region")->set_sensitive (false);
+ _region_actions->get_action("fork-region")->set_sensitive (false);
+ _region_actions->get_action("insert-patch-change-context")->set_sensitive (false);
+ _region_actions->get_action("insert-patch-change")->set_sensitive (false);
+ _region_actions->get_action("transpose-region")->set_sensitive (false);
+ } else {
+ editor_menu_actions->get_action("RegionMenuMIDI")->set_sensitive (true);
+ /* others were already marked sensitive */
+ }
+
+ if (_edit_point == EditAtMouse) {
+ _region_actions->get_action("set-region-sync-position")->set_sensitive (false);
+ _region_actions->get_action("trim-front")->set_sensitive (false);
+ _region_actions->get_action("trim-back")->set_sensitive (false);
+ _region_actions->get_action("split-region")->set_sensitive (false);
+ _region_actions->get_action("place-transient")->set_sensitive (false);
+ }
+
+ if (have_compound_regions) {
+ _region_actions->get_action("uncombine-regions")->set_sensitive (true);
+ } else {
+ _region_actions->get_action("uncombine-regions")->set_sensitive (false);
+ }
+
+ if (have_audio) {
+
+ if (have_envelope_active && !have_envelope_inactive) {
+ Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-gain-envelope-active"))->set_active ();
+ } else if (have_envelope_active && have_envelope_inactive) {
+ // Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-gain-envelope-active"))->set_inconsistent ();
+ }
+
+ } else {
+
+ _region_actions->get_action("analyze-region")->set_sensitive (false);
+ _region_actions->get_action("reset-region-gain-envelopes")->set_sensitive (false);
+ _region_actions->get_action("toggle-region-gain-envelope-active")->set_sensitive (false);
+ _region_actions->get_action("pitch-shift-region")->set_sensitive (false);
+
+ }
+
+ if (!have_non_unity_scale_amplitude || !have_audio) {
+ _region_actions->get_action("reset-region-scale-amplitude")->set_sensitive (false);
+ }
+
+ Glib::RefPtr<ToggleAction> a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-lock"));
+ a->set_active (have_locked && !have_unlocked);
+ if (have_locked && have_unlocked) {
+ // a->set_inconsistent ();
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-video-lock"));
+ a->set_active (have_video_locked && !have_video_unlocked);
+ if (have_video_locked && have_video_unlocked) {
+ // a->set_inconsistent ();
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-lock-style"));
+ a->set_active (have_position_lock_style_music && !have_position_lock_style_audio);
+
+ if (have_position_lock_style_music && have_position_lock_style_audio) {
+ // a->set_inconsistent ();
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-mute"));
+ a->set_active (have_muted && !have_unmuted);
+ if (have_muted && have_unmuted) {
+ // a->set_inconsistent ();
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-opaque-region"));
+ a->set_active (have_opaque && !have_non_opaque);
+ if (have_opaque && have_non_opaque) {
+ // a->set_inconsistent ();
+ }
+
+ if (!have_not_at_natural_position) {
+ _region_actions->get_action("naturalize-region")->set_sensitive (false);
+ }
+
+ /* XXX: should also check that there is a track of the appropriate type for the selected region */
+ if (_edit_point == EditAtMouse || _regions->get_single_selection() == 0 || selection->tracks.empty()) {
+ _region_actions->get_action("insert-region-from-region-list")->set_sensitive (false);
+ } else {
+ _region_actions->get_action("insert-region-from-region-list")->set_sensitive (true);
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-fade-in"));
+ a->set_active (have_active_fade_in && !have_inactive_fade_in);
+ if (have_active_fade_in && have_inactive_fade_in) {
+ // a->set_inconsistent ();
+ }
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-fade-out"));
+ a->set_active (have_active_fade_out && !have_inactive_fade_out);
+
+ if (have_active_fade_out && have_inactive_fade_out) {
+ // a->set_inconsistent ();
+ }
+
+ bool const have_active_fade = have_active_fade_in || have_active_fade_out;
+ bool const have_inactive_fade = have_inactive_fade_in || have_inactive_fade_out;
+
+ a = Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-fades"));
+ a->set_active (have_active_fade && !have_inactive_fade);
+
+ if (have_active_fade && have_inactive_fade) {
+ // a->set_inconsistent ();
+ }
+
+ _ignore_region_action = false;
+
+ _all_region_actions_sensitized = false;