13
0

Add region polarity invert to Region menu

This commit is contained in:
Robin Gareus 2022-12-17 13:12:06 +01:00
parent 9819cdb117
commit 0f949bc02b
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 50 additions and 0 deletions

View File

@ -385,6 +385,7 @@
<menuitem action='cut-region-gain'/>
<menuitem action='reset-region-gain'/>
<menuitem action='reset-region-gain-envelopes'/>
<menuitem action='toggle-region-polarity'/>
<menuitem action='toggle-region-gain-envelope-active'/>
</menu>
<menu action='RegionMenuPosition'>
@ -931,6 +932,7 @@
<menuitem action='cut-region-gain'/>
<menuitem action='reset-region-gain'/>
<menuitem action='reset-region-gain-envelopes'/>
<menuitem action='toggle-region-polarity'/>
<menuitem action='toggle-region-gain-envelope-active'/>
</menu>
<menu action='RegionMenuFades'>

View File

@ -2314,6 +2314,7 @@ private:
void set_gain_envelope_visibility ();
void set_region_gain_visibility (RegionView*);
void toggle_gain_envelope_active ();
void toggle_region_polarity ();
void reset_region_gain_envelopes ();
void session_state_saved (std::string);

View File

@ -1911,6 +1911,8 @@ Editor::register_region_actions ()
register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-gain-envelope-active", _("Envelope Active"), sigc::mem_fun (*this, &Editor::toggle_gain_envelope_active));
register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-polarity", _("Invert Polarity"), sigc::mem_fun (*this, &Editor::toggle_region_polarity));
register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "quantize-region", _("Quantize..."), sigc::mem_fun (*this, &Editor::quantize_region));
register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "legatize-region", _("Legatize"), sigc::bind(sigc::mem_fun (*this, &Editor::legatize_region), false));
register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "deinterlace-midi", _("Deinterlace Into Layers"), sigc::mem_fun (*this, &Editor::deinterlace_selected_midi_regions));

View File

@ -6409,6 +6409,41 @@ Editor::set_gain_envelope_visibility ()
}
}
void
Editor::toggle_region_polarity ()
{
if (_ignore_region_action) {
return;
}
RegionSelection rs = get_regions_from_selection_and_entered ();
if (!_session || rs.empty()) {
return;
}
bool in_command = false;
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
if (arv) {
arv->region()->clear_changes ();
gain_t scale_amplitude = arv->audio_region()->scale_amplitude ();
arv->audio_region()->set_scale_amplitude (-1 * scale_amplitude);
if (!in_command) {
begin_reversible_command (_("region polarity invery"));
in_command = true;
}
_session->add_command (new StatefulDiffCommand (arv->region()));
}
}
if (in_command) {
commit_reversible_command ();
}
}
void
Editor::toggle_gain_envelope_active ()
{

View File

@ -1428,6 +1428,8 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
bool have_active_fade_in = false;
bool have_active_fade_out = false;
bool have_transients = false;
bool have_inverted_polarity = false;
bool have_non_inverted_polarity = false;
for (list<RegionView*>::const_iterator i = rs.begin(); i != rs.end(); ++i) {
@ -1509,6 +1511,9 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
} else {
have_inactive_fade_out = true;
}
have_inverted_polarity = ar->scale_amplitude () < 0;
have_non_inverted_polarity = ar->scale_amplitude () >= 0;
}
}
@ -1565,6 +1570,10 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
// Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-gain-envelope-active"))->set_inconsistent ();
}
if (have_inverted_polarity && !have_non_inverted_polarity) {
Glib::RefPtr<ToggleAction>::cast_dynamic (_region_actions->get_action("toggle-region-polarity"))->set_active ();
}
} else {
_region_actions->get_action("loudness-analyze-region")->set_sensitive (false);
@ -1574,6 +1583,7 @@ Editor::sensitize_the_right_region_actions (bool because_canvas_crossing)
_region_actions->get_action("pitch-shift-region")->set_sensitive (false);
_region_actions->get_action("strip-region-silence")->set_sensitive (false);
_region_actions->get_action("show-rhythm-ferret")->set_sensitive (false);
_region_actions->get_action("toggle-region-polarity")->set_sensitive (false);
}