add configurable colors to stereo panner, plus keybindings for zero width (0), 1...
[ardour.git] / gtk2_ardour / editor_timefx.cc
index aab6b676585a9ff54743a165e4bc5497bdad9bb0..03094d0a52c75d2b5f89e7a93246c5124ca09abe 100644 (file)
@@ -26,6 +26,7 @@
 #include "pbd/error.h"
 #include "pbd/pthread_utils.h"
 #include "pbd/memento_command.h"
+#include "pbd/stateful_diff_command.h"
 
 #include <gtkmm2ext/utils.h>
 
@@ -40,7 +41,6 @@
 #include "ardour/audioplaylist.h"
 #include "ardour/audio_track.h"
 #include "ardour/audioregion.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/stretch.h"
 #include "ardour/midi_stretch.h"
 #include "ardour/pitch.h"
@@ -58,6 +58,7 @@ using namespace PBD;
 using namespace Gtk;
 using namespace Gtkmm2ext;
 
+/** @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */
 int
 Editor::time_stretch (RegionSelection& regions, float fraction)
 {
@@ -73,18 +74,17 @@ Editor::time_stretch (RegionSelection& regions, float fraction)
                        return -1;
 
                boost::shared_ptr<Playlist> playlist
-                       = rtv->track()->diskstream()->playlist();
+                       = rtv->track()->playlist();
 
            ARDOUR::TimeFXRequest request;
                request.time_fraction = fraction;
                MidiStretch stretch(*_session, request);
                begin_reversible_command ("midi stretch");
                stretch.run(regions.front()->region());
-               XMLNode &before = playlist->get_state();
+                playlist->clear_changes ();
                playlist->replace_region (regions.front()->region(), stretch.results[0],
                                regions.front()->region()->position());
-               XMLNode &after = playlist->get_state();
-               _session->add_command (new MementoCommand<Playlist>(*playlist, &before, &after));
+               _session->add_command (new StatefulDiffCommand (playlist));
                commit_reversible_command ();
        }
 
@@ -97,6 +97,7 @@ Editor::pitch_shift (RegionSelection& regions, float fraction)
        return time_fx (regions, fraction, true);
 }
 
+/** @return -1 in case of error, 1 if operation was cancelled by the user, 0 if everything went ok */
 int
 Editor::time_fx (RegionSelection& regions, float val, bool pitching)
 {
@@ -170,21 +171,42 @@ Editor::time_fx (RegionSelection& regions, float val, bool pitching)
 
        txt = current_timefx->stretch_opts_selector.get_active_text ();
 
-       if (txt == rb_opt_strings[0]) {
-               transients = NoTransients; peaklock = false; longwin = true; shortwin = false;
-       } else if (txt == rb_opt_strings[1]) {
-               transients = NoTransients; peaklock = false; longwin = false; shortwin = false;
-       } else if (txt == rb_opt_strings[2]) {
-               transients = NoTransients; peaklock = true; longwin = false; shortwin = false;
-       } else if (txt == rb_opt_strings[3]) {
-               transients = BandLimitedTransients; peaklock = true; longwin = false; shortwin = false;
-       } else if (txt == rb_opt_strings[5]) {
-               transients = Transients; peaklock = false; longwin = false; shortwin = true;
-       } else {
-               /* default/4 */
-
-               transients = Transients; peaklock = true; longwin = false; shortwin = false;
+       for (int i = 0; i <= 6; i++) {
+               if (txt == rb_opt_strings[i]) {
+                       rb_current_opt = i;
+                       break;
+               }
        }
+       
+       switch (rb_current_opt) {
+               case 0:
+                       transients = NoTransients; peaklock = false; longwin = true; shortwin = false; 
+                       break;
+               case 1:
+                       transients = NoTransients; peaklock = false; longwin = false; shortwin = false; 
+                       break;
+               case 2:
+                       transients = NoTransients; peaklock = true; longwin = false; shortwin = false; 
+                       break;
+               case 3:
+                       transients = BandLimitedTransients; peaklock = true; longwin = false; shortwin = false; 
+                       break;
+               case 5:
+                       transients = Transients; peaklock = false; longwin = false; shortwin = true; 
+                       break;
+               case 6:
+                       transients = NoTransients;
+                       precise = true;
+                       preserve_formants = false;
+                       current_timefx->request.pitch_fraction = 1/val;
+                       shortwin = true;
+                       // peaklock = false;
+                       break;
+               default:
+                       /* default/4 */ 
+                       transients = Transients; peaklock = true; longwin = false; shortwin = false; 
+                       break;
+       };
 
        if (realtime)          options |= RubberBandStretcher::OptionProcessRealTime;
        if (precise)           options |= RubberBandStretcher::OptionStretchPrecise;
@@ -277,7 +299,7 @@ Editor::do_timefx (TimeFXDialog& dialog)
                        continue;
                }
 
-               if ((playlist = t->diskstream()->playlist()) == 0) {
+               if ((playlist = t->playlist()) == 0) {
                        i = tmp;
                        continue;
                }
@@ -315,10 +337,9 @@ Editor::do_timefx (TimeFXDialog& dialog)
                                in_command = true;
                        }
 
-                       XMLNode &before = playlist->get_state();
+                        playlist->clear_changes ();
                        playlist->replace_region (region, new_region, region->position());
-                       XMLNode &after = playlist->get_state();
-                       _session->add_command (new MementoCommand<Playlist>(*playlist, &before, &after));
+                       _session->add_command (new StatefulDiffCommand (playlist));
                }
 
                i = tmp;