X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fcrossfade_edit.cc;h=aaea3a224274666a2b0af6fc984853503b2cc444;hb=8c5cff60912c7e0a7256f635641399500d8d00d9;hp=4f0bbb702b22d4028fa42f65dedc513b476d7287;hpb=64dc5427e4f5339a16a018692dd94f476c53cae9;p=ardour.git diff --git a/gtk2_ardour/crossfade_edit.cc b/gtk2_ardour/crossfade_edit.cc index 4f0bbb702b..aaea3a2242 100644 --- a/gtk2_ardour/crossfade_edit.cc +++ b/gtk2_ardour/crossfade_edit.cc @@ -27,6 +27,7 @@ #include +#include "pbd/memento_command.h" #include "ardour/automation_list.h" #include "evoral/Curve.hpp" #include "ardour/crossfade.h" @@ -36,6 +37,7 @@ #include "ardour/audiosource.h" #include "ardour/region_factory.h" #include "ardour/profile.h" +#include "ardour/crossfade_binder.h" #include @@ -54,7 +56,6 @@ using namespace std; using namespace ARDOUR; using namespace PBD; using namespace Gtk; -using namespace sigc; using namespace Editing; using Gtkmm2ext::Keyboard; @@ -73,10 +74,9 @@ CrossfadeEditor::Half::Half () { } -CrossfadeEditor::CrossfadeEditor (Session& s, boost::shared_ptr xf, double my, double mxy) - : ArdourDialog (_("ardour: x-fade edit")), +CrossfadeEditor::CrossfadeEditor (Session* s, boost::shared_ptr xf, double my, double mxy) + : ArdourDialog (_("Edit Crossfade")), xfade (xf), - session (s), clear_button (_("Clear")), revert_button (_("Reset")), audition_both_button (_("Fade")), @@ -95,11 +95,15 @@ CrossfadeEditor::CrossfadeEditor (Session& s, boost::shared_ptr xf, d fade_out_table (3, 3), select_in_button (_("Fade In")), - select_out_button (_("Fade Out")) + select_out_button (_("Fade Out")), + + _peaks_ready_connection (0) + { - set_wmclass (X_("ardour_automationedit"), "Ardour"); + set_session (s); + + set_wmclass (X_("ardour_automationedit"), PROGRAM_NAME); set_name ("CrossfadeEditWindow"); - set_position (Gtk::WIN_POS_MOUSE); add_accel_group (ActionManager::ui_manager->get_accel_group()); @@ -291,9 +295,9 @@ CrossfadeEditor::CrossfadeEditor (Session& s, boost::shared_ptr xf, d curve_select_clicked (In); - xfade->StateChanged.connect (sigc::mem_fun(*this, &CrossfadeEditor::xfade_changed)); + xfade->PropertyChanged.connect (state_connection, invalidator (*this), boost::bind (&CrossfadeEditor::xfade_changed, this, _1), gui_context()); - session.AuditionActive.connect (sigc::mem_fun(*this, &CrossfadeEditor::audition_state_changed)); + _session->AuditionActive.connect (_session_connections, invalidator (*this), boost::bind (&CrossfadeEditor::audition_state_changed, this, _1), gui_context()); show_all_children(); } @@ -308,6 +312,8 @@ CrossfadeEditor::~CrossfadeEditor() for (list::iterator i = fade[Out].points.begin(); i != fade[Out].points.end(); ++i) { delete *i; } + + delete _peaks_ready_connection; } void @@ -413,15 +419,16 @@ CrossfadeEditor::point_event (GdkEvent* event, Point* point) if (point_grabbed) { double new_x, new_y; - /* can't drag first or last points horizontally */ + /* can't drag first or last points horizontally or vertically */ if (point == fade[current].points.front() || point == fade[current].points.back()) { new_x = point->x; + new_y = point->y; } else { new_x = (event->motion.x - canvas_border)/effective_width(); + new_y = 1.0 - ((event->motion.y - canvas_border)/effective_height()); } - new_y = 1.0 - ((event->motion.y - canvas_border)/effective_height()); point->move_to (x_coordinate (new_x), y_coordinate (new_y), new_x, new_y); redraw (); @@ -497,6 +504,18 @@ CrossfadeEditor::add_control_point (double x, double y) void CrossfadeEditor::Point::move_to (double nx, double ny, double xfract, double yfract) { + if ( xfract < 0.0 ) { + xfract = 0.0; + } else if ( xfract > 1.0 ) { + xfract = 1.0; + } + + if ( yfract < 0.0 ) { + yfract = 0.0; + } else if ( yfract > 1.0 ) { + yfract = 1.0; + } + const double half_size = rint(size/2.0); double x1 = nx - half_size; double x2 = nx + half_size; @@ -624,7 +643,7 @@ CrossfadeEditor::canvas_allocation (Gtk::Allocation& /*alloc*/) void -CrossfadeEditor::xfade_changed (Change) +CrossfadeEditor::xfade_changed (const PropertyChange&) { set (xfade->fade_in(), In); set (xfade->fade_out(), Out); @@ -637,7 +656,7 @@ CrossfadeEditor::redraw () return; } - nframes_t len = xfade->length (); + framecnt_t len = xfade->length (); fade[current].normative_curve.clear (); fade[current].gain_curve.clear (); @@ -766,7 +785,20 @@ CrossfadeEditor::apply_preset (Preset *preset) void CrossfadeEditor::apply () { + _session->begin_reversible_command (_("Edit crossfade")); + + XMLNode& before = xfade->get_state (); + _apply_to (xfade); + + _session->add_command ( + new MementoCommand ( + new ARDOUR::CrossfadeBinder (_session->playlists, xfade->id ()), + &before, &xfade->get_state () + ) + ); + + _session->commit_reversible_command (); } void @@ -783,8 +815,6 @@ CrossfadeEditor::_apply_to (boost::shared_ptr xf) double firstx = (*in.begin())->when; double endx = (*the_end)->when; - double miny = in.get_min_y (); - double maxy = in.get_max_y (); in.freeze (); in.clear (); @@ -792,7 +822,7 @@ CrossfadeEditor::_apply_to (boost::shared_ptr xf) for (list::iterator i = fade[In].points.begin(); i != fade[In].points.end(); ++i) { double when = firstx + ((*i)->x * (endx - firstx)); - double value = (*i)->y; // miny + ((*i)->y * (maxy - miny)); + double value = (*i)->y; in.add (when, value); } @@ -803,8 +833,6 @@ CrossfadeEditor::_apply_to (boost::shared_ptr xf) firstx = (*out.begin())->when; endx = (*the_end)->when; - miny = out.get_min_y (); - maxy = out.get_max_y (); out.freeze (); out.clear (); @@ -812,7 +840,7 @@ CrossfadeEditor::_apply_to (boost::shared_ptr xf) for (list::iterator i = fade[Out].points.begin(); i != fade[Out].points.end(); ++i) { double when = firstx + ((*i)->x * (endx - firstx)); - double value = (*i)->y; // miny + ((*i)->y * (maxy - miny)); + double value = (*i)->y; out.add (when, value); } @@ -847,7 +875,7 @@ CrossfadeEditor::reset () set (xfade->fade_in(), In); set (xfade->fade_out(), Out); - curve_select_clicked (current); + curve_select_clicked (current); } void @@ -860,7 +888,7 @@ CrossfadeEditor::build_presets () /* FADE IN */ - p = new Preset ("Linear (-6dB)", "crossfade-in-linear"); + p = new Preset ("Linear (-6dB)", "fadein-linear"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.000000, 0.000000)); p->push_back (PresetPoint (0.166667, 0.166366)); @@ -871,7 +899,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1.000000, 1.000000)); fade_in_presets->push_back (p); - p = new Preset ("S(1)-curve", "crossfade-in-S1"); + p = new Preset ("S(1)-curve", "fadein-S1"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.1, 0.01)); p->push_back (PresetPoint (0.2, 0.03)); @@ -880,7 +908,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 1)); fade_in_presets->push_back (p); - p = new Preset ("S(2)-curve", "crossfade-in-S2"); + p = new Preset ("S(2)-curve", "fadein-S2"); p->push_back (PresetPoint (0.0, 0.0)); p->push_back (PresetPoint (0.055, 0.222)); p->push_back (PresetPoint (0.163, 0.35)); @@ -889,7 +917,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1.0, 1.0)); fade_in_presets->push_back (p); - p = new Preset ("Constant Power (-3dB)", "crossfade-in-constant-power"); + p = new Preset ("Constant power (-3dB)", "fadein-constant-power"); p->push_back (PresetPoint (0.000000, 0.000000)); p->push_back (PresetPoint (0.166667, 0.282192)); @@ -903,7 +931,7 @@ CrossfadeEditor::build_presets () if (!Profile->get_sae()) { - p = new Preset ("Short cut", "crossfade-in-short-cut"); + p = new Preset ("Short cut", "fadein-short-cut"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.389401, 0.0333333)); p->push_back (PresetPoint (0.629032, 0.0861111)); @@ -913,7 +941,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 1)); fade_in_presets->push_back (p); - p = new Preset ("Slow cut", "crossfade-in-slow-cut"); + p = new Preset ("Slow cut", "fadein-slow-cut"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.304147, 0.0694444)); p->push_back (PresetPoint (0.529954, 0.152778)); @@ -923,7 +951,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 1)); fade_in_presets->push_back (p); - p = new Preset ("Fast cut", "crossfade-in-fast-cut"); + p = new Preset ("Fast cut", "fadein-fast-cut"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.0737327, 0.308333)); p->push_back (PresetPoint (0.246544, 0.658333)); @@ -933,7 +961,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 1)); fade_in_presets->push_back (p); - p = new Preset ("Long cut", "crossfade-in-long-cut"); + p = new Preset ("Long cut", "fadein-long-cut"); p->push_back (PresetPoint (0, 0)); p->push_back (PresetPoint (0.0207373, 0.197222)); p->push_back (PresetPoint (0.0645161, 0.525)); @@ -948,7 +976,7 @@ CrossfadeEditor::build_presets () /* FADE OUT */ // p = new Preset ("regout.xpm"); - p = new Preset ("Linear (-6dB cut)", "crossfade-out-linear"); + p = new Preset ("Linear (-6dB cut)", "fadeout-linear"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.000000, 1.000000)); p->push_back (PresetPoint (0.166667, 0.833033)); @@ -959,7 +987,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1.000000, 0.000000)); fade_out_presets->push_back (p); - p = new Preset ("S(1)-Curve", "crossfade-out-S1"); + p = new Preset ("S(1)-Curve", "fadeout-S1"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.1, 0.99)); p->push_back (PresetPoint (0.2, 0.97)); @@ -968,7 +996,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 0)); fade_out_presets->push_back (p); - p = new Preset ("S(2)-Curve", "crossfade-out-S2"); + p = new Preset ("S(2)-Curve", "fadeout-S2"); p->push_back (PresetPoint (0.0, 1.0)); p->push_back (PresetPoint (0.163, 0.678)); p->push_back (PresetPoint (0.055, 0.783)); @@ -978,7 +1006,7 @@ CrossfadeEditor::build_presets () fade_out_presets->push_back (p); // p = new Preset ("linout.xpm"); - p = new Preset ("Constant Power (-3dB cut)", "crossfade-out-constant-power"); + p = new Preset ("Constant power (-3dB cut)", "fadeout-constant-power"); p->push_back (PresetPoint (0.000000, 1.000000)); p->push_back (PresetPoint (0.166667, 0.948859)); p->push_back (PresetPoint (0.333333, 0.851507)); @@ -990,7 +1018,7 @@ CrossfadeEditor::build_presets () if (!Profile->get_sae()) { // p = new Preset ("hiout.xpm"); - p = new Preset ("Short cut", "crossfade-out-short-cut"); + p = new Preset ("Short cut", "fadeout-short-cut"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.305556, 1)); p->push_back (PresetPoint (0.548611, 0.991736)); @@ -1000,7 +1028,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 0)); fade_out_presets->push_back (p); - p = new Preset ("Slow cut", "crossfade-out-slow-cut"); + p = new Preset ("Slow cut", "fadeout-slow-cut"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.228111, 0.988889)); p->push_back (PresetPoint (0.347926, 0.972222)); @@ -1010,7 +1038,7 @@ CrossfadeEditor::build_presets () p->push_back (PresetPoint (1, 0)); fade_out_presets->push_back (p); - p = new Preset ("Fast cut", "crossfade-out-fast-cut"); + p = new Preset ("Fast cut", "fadeout-fast-cut"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.080645, 0.730556)); p->push_back (PresetPoint (0.277778, 0.289256)); @@ -1020,7 +1048,7 @@ CrossfadeEditor::build_presets () fade_out_presets->push_back (p); // p = new Preset ("loout.xpm"); - p = new Preset ("Long cut", "crossfade-out-long-cut"); + p = new Preset ("Long cut", "fadeout-long-cut"); p->push_back (PresetPoint (0, 1)); p->push_back (PresetPoint (0.023041, 0.697222)); p->push_back (PresetPoint (0.0553, 0.483333)); @@ -1126,11 +1154,14 @@ CrossfadeEditor::make_waves (boost::shared_ptr region, WhichFade wh ht = canvas->get_allocation().get_height() / (double) nchans; spu = xfade->length() / (double) effective_width(); + delete _peaks_ready_connection; + _peaks_ready_connection = 0; + for (uint32_t n = 0; n < nchans; ++n) { gdouble yoff = n * ht; - if (region->audio_source(n)->peaks_ready (sigc::bind (sigc::mem_fun(*this, &CrossfadeEditor::peaks_ready), region, which), peaks_ready_connection)) { + if (region->audio_source(n)->peaks_ready (boost::bind (&CrossfadeEditor::peaks_ready, this, boost::weak_ptr(region), which), &_peaks_ready_connection, gui_context())) { WaveView* waveview = new WaveView (*(canvas->root())); waveview->property_data_src() = region.get(); @@ -1164,34 +1195,42 @@ CrossfadeEditor::make_waves (boost::shared_ptr region, WhichFade wh } void -CrossfadeEditor::peaks_ready (boost::shared_ptr r, WhichFade which) +CrossfadeEditor::peaks_ready (boost::weak_ptr wr, WhichFade which) { + boost::shared_ptr r (wr.lock()); + + if (!r) { + return; + } + /* this should never be called, because the peak files for an xfade will be ready by the time we want them. but our API forces us to provide this, so .. */ - peaks_ready_connection.disconnect (); + delete _peaks_ready_connection; + _peaks_ready_connection = 0; + make_waves (r, which); } void CrossfadeEditor::audition (Audition which) { - AudioPlaylist& pl (session.the_auditioner()->prepare_playlist()); - nframes_t preroll; - nframes_t postroll; - nframes_t left_start_offset; - nframes_t right_length; - nframes_t left_length; + AudioPlaylist& pl (_session->the_auditioner()->prepare_playlist()); + framecnt_t preroll; + framecnt_t postroll; + framecnt_t left_start_offset; + framecnt_t right_length; + framecnt_t left_length; if (which != Right && preroll_button.get_active()) { - preroll = session.frame_rate() * 2; //2 second hardcoded preroll for now + preroll = _session->frame_rate() * 2; //2 second hardcoded preroll for now } else { preroll = 0; } if (which != Left && postroll_button.get_active()) { - postroll = session.frame_rate() * 2; //2 second hardcoded postroll for now + postroll = _session->frame_rate() * 2; //2 second hardcoded postroll for now } else { postroll = 0; } @@ -1214,30 +1253,46 @@ CrossfadeEditor::audition (Audition which) right_length = xfade->in()->length(); } - boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade->out(), left_start_offset, left_length, "xfade out", - 0, Region::DefaultFlags, false))); - boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade->in(), 0, right_length, "xfade in", - 0, Region::DefaultFlags, false))); + PropertyList left_plist; + PropertyList right_plist; - //apply a 20ms declicking fade at the start and end of auditioning - left->set_fade_in_active(true); - left->set_fade_in_length(session.frame_rate() / 50); - right->set_fade_out_active(true); - right->set_fade_out_length(session.frame_rate() / 50); - pl.add_region (left, 0); - pl.add_region (right, 1 + preroll); + left_plist.add (ARDOUR::Properties::start, left_start_offset); + left_plist.add (ARDOUR::Properties::length, left_length); + left_plist.add (ARDOUR::Properties::name, string ("xfade out")); + left_plist.add (ARDOUR::Properties::layer, 0); + left_plist.add (ARDOUR::Properties::fade_in_active, true); + + right_plist.add (ARDOUR::Properties::start, 0); + right_plist.add (ARDOUR::Properties::length, right_length); + right_plist.add (ARDOUR::Properties::name, string("xfade in")); + right_plist.add (ARDOUR::Properties::layer, 0); + right_plist.add (ARDOUR::Properties::fade_out_active, true); if (which == Left) { - right->set_scale_amplitude (0.0); + right_plist.add (ARDOUR::Properties::scale_amplitude, 0.0f); } else if (which == Right) { - left->set_scale_amplitude (0.0); + left_plist.add (ARDOUR::Properties::scale_amplitude, 0.0f); } + boost::shared_ptr left (boost::dynamic_pointer_cast + (RegionFactory::create (xfade->out(), left_plist, false))); + boost::shared_ptr right (boost::dynamic_pointer_cast + (RegionFactory::create (xfade->in(), right_plist, false))); + + // apply a 20ms declicking fade at the start and end of auditioning + // XXX this should really be a property + + left->set_fade_in_length (_session->frame_rate() / 50); + right->set_fade_out_length (_session->frame_rate() / 50); + + pl.add_region (left, 0); + pl.add_region (right, 1 + preroll); + /* there is only one ... */ pl.foreach_crossfade (sigc::mem_fun (*this, &CrossfadeEditor::setup)); - session.audition_playlist (); + _session->audition_playlist (); } void @@ -1249,10 +1304,17 @@ CrossfadeEditor::audition_both () void CrossfadeEditor::audition_left_dry () { - boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade->out(), xfade->out()->length() - xfade->length(), xfade->length(), "xfade left", - 0, Region::DefaultFlags, false))); + PropertyList plist; + + plist.add (ARDOUR::Properties::start, xfade->out()->length() - xfade->length()); + plist.add (ARDOUR::Properties::length, xfade->length()); + plist.add (ARDOUR::Properties::name, string("xfade left")); + plist.add (ARDOUR::Properties::layer, 0); - session.audition_region (left); + boost::shared_ptr left (boost::dynamic_pointer_cast + (RegionFactory::create (xfade->out(), plist, false))); + + _session->audition_region (left); } void @@ -1264,9 +1326,17 @@ CrossfadeEditor::audition_left () void CrossfadeEditor::audition_right_dry () { - boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade->in(), 0, xfade->length(), "xfade in", - 0, Region::DefaultFlags, false))); - session.audition_region (right); + PropertyList plist; + + plist.add (ARDOUR::Properties::start, 0); + plist.add (ARDOUR::Properties::length, xfade->length()); + plist.add (ARDOUR::Properties::name, string ("xfade right")); + plist.add (ARDOUR::Properties::layer, 0); + + boost::shared_ptr right (boost::dynamic_pointer_cast + (RegionFactory::create (xfade->in(), plist, false))); + + _session->audition_region (right); } void @@ -1278,7 +1348,7 @@ CrossfadeEditor::audition_right () void CrossfadeEditor::cancel_audition () { - session.cancel_audition (); + _session->cancel_audition (); } void @@ -1286,7 +1356,7 @@ CrossfadeEditor::audition_toggled () { bool x; - if ((x = audition_both_button.get_active ()) != session.is_auditioning()) { + if ((x = audition_both_button.get_active ()) != _session->is_auditioning()) { if (x) { audition_both (); @@ -1301,7 +1371,7 @@ CrossfadeEditor::audition_right_toggled () { bool x; - if ((x = audition_right_button.get_active ()) != session.is_auditioning()) { + if ((x = audition_right_button.get_active ()) != _session->is_auditioning()) { if (x) { audition_right (); @@ -1316,7 +1386,7 @@ CrossfadeEditor::audition_right_dry_toggled () { bool x; - if ((x = audition_right_dry_button.get_active ()) != session.is_auditioning()) { + if ((x = audition_right_dry_button.get_active ()) != _session->is_auditioning()) { if (x) { audition_right_dry (); @@ -1331,7 +1401,7 @@ CrossfadeEditor::audition_left_toggled () { bool x; - if ((x = audition_left_button.get_active ()) != session.is_auditioning()) { + if ((x = audition_left_button.get_active ()) != _session->is_auditioning()) { if (x) { audition_left (); @@ -1346,7 +1416,7 @@ CrossfadeEditor::audition_left_dry_toggled () { bool x; - if ((x = audition_left_dry_button.get_active ()) != session.is_auditioning()) { + if ((x = audition_left_dry_button.get_active ()) != _session->is_auditioning()) { if (x) { audition_left_dry (); @@ -1383,7 +1453,7 @@ CrossfadeEditor::on_key_release_event (GdkEventKey* ev) break; case GDK_space: - if (session.is_auditioning()) { + if (_session->is_auditioning()) { cancel_audition (); } else { audition_both_button.set_active (!audition_both_button.get_active());