2005-09-25 14:42:24 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <pbd/error.h>
|
|
|
|
#include <pbd/pthread_utils.h>
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
#include "audio_time_axis.h"
|
|
|
|
#include "regionview.h"
|
|
|
|
#include "region_selection.h"
|
|
|
|
|
|
|
|
#include <ardour/session.h>
|
|
|
|
#include <ardour/region.h>
|
|
|
|
#include <ardour/audioplaylist.h>
|
|
|
|
#include <ardour/audio_track.h>
|
|
|
|
#include <ardour/audioregion.h>
|
2006-06-14 17:17:32 -04:00
|
|
|
#include <ardour/audio_diskstream.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 16:33:00 -04:00
|
|
|
using namespace sigc;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
|
|
|
|
Editor::TimeStretchDialog::TimeStretchDialog (Editor& e)
|
|
|
|
: ArdourDialog ("time stretch dialog"),
|
|
|
|
editor (e),
|
|
|
|
quick_button (_("Quick but Ugly")),
|
2006-05-19 22:57:38 -04:00
|
|
|
antialias_button (_("Skip Anti-aliasing"))
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
set_modal (true);
|
2005-09-25 16:33:00 -04:00
|
|
|
set_position (Gtk::WIN_POS_MOUSE);
|
2005-09-25 14:42:24 -04:00
|
|
|
set_title (_("ardour: timestretch"));
|
|
|
|
set_name (N_("TimeStretchDialog"));
|
|
|
|
|
2006-04-30 15:37:48 -04:00
|
|
|
get_vbox()->set_spacing (5);
|
|
|
|
get_vbox()->set_border_width (5);
|
|
|
|
get_vbox()->pack_start (upper_button_box);
|
|
|
|
get_vbox()->pack_start (progress_bar);
|
2006-05-19 22:57:38 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
upper_button_box.set_homogeneous (true);
|
|
|
|
upper_button_box.set_spacing (5);
|
|
|
|
upper_button_box.set_border_width (5);
|
|
|
|
upper_button_box.pack_start (quick_button, true, true);
|
|
|
|
upper_button_box.pack_start (antialias_button, true, true);
|
|
|
|
|
2006-05-19 22:57:38 -04:00
|
|
|
action_button = add_button (_("Stretch/Shrink it"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
cancel_button = add_button (_("Cancel"), Gtk::RESPONSE_CANCEL);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
quick_button.set_name (N_("TimeStretchButton"));
|
|
|
|
antialias_button.set_name (N_("TimeStretchButton"));
|
|
|
|
progress_bar.set_name (N_("TimeStretchProgress"));
|
|
|
|
|
2006-05-19 22:57:38 -04:00
|
|
|
show_all_children ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
Editor::TimeStretchDialog::update_progress ()
|
|
|
|
{
|
2006-05-19 22:57:38 -04:00
|
|
|
progress_bar.set_fraction (request.progress);
|
2005-09-25 14:42:24 -04:00
|
|
|
return request.running;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Editor::TimeStretchDialog::cancel_timestretch_in_progress ()
|
|
|
|
{
|
|
|
|
status = -2;
|
|
|
|
request.running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
Editor::TimeStretchDialog::delete_timestretch_in_progress (GdkEventAny* ev)
|
|
|
|
{
|
|
|
|
status = -2;
|
|
|
|
request.running = false;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Editor::run_timestretch (AudioRegionSelection& regions, float fraction)
|
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
if (current_timestretch == 0) {
|
|
|
|
current_timestretch = new TimeStretchDialog (*this);
|
|
|
|
}
|
|
|
|
|
2005-10-06 00:59:20 -04:00
|
|
|
current_timestretch->progress_bar.set_fraction (0.0f);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-27 16:17:41 -05:00
|
|
|
switch (current_timestretch->run ()) {
|
|
|
|
case RESPONSE_ACCEPT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
current_timestretch->hide ();
|
|
|
|
return 1;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
current_timestretch->status = 0;
|
|
|
|
current_timestretch->regions = regions;
|
|
|
|
current_timestretch->request.fraction = fraction;
|
|
|
|
current_timestretch->request.quick_seek = current_timestretch->quick_button.get_active();
|
|
|
|
current_timestretch->request.antialias = !current_timestretch->antialias_button.get_active();
|
|
|
|
current_timestretch->request.progress = 0.0f;
|
|
|
|
current_timestretch->request.running = true;
|
|
|
|
|
|
|
|
/* re-connect the cancel button and delete events */
|
|
|
|
|
|
|
|
current_timestretch->first_cancel.disconnect();
|
|
|
|
current_timestretch->first_delete.disconnect();
|
|
|
|
|
2006-05-19 22:57:38 -04:00
|
|
|
current_timestretch->cancel_button->signal_clicked().connect (mem_fun (current_timestretch, &TimeStretchDialog::cancel_timestretch_in_progress));
|
2005-09-26 14:24:59 -04:00
|
|
|
current_timestretch->signal_delete_event().connect (mem_fun (current_timestretch, &TimeStretchDialog::delete_timestretch_in_progress));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (pthread_create_and_store ("timestretch", &thread, 0, timestretch_thread, current_timestretch)) {
|
2006-05-19 22:57:38 -04:00
|
|
|
current_timestretch->hide ();
|
2005-09-25 14:42:24 -04:00
|
|
|
error << _("timestretch cannot be started - thread creation error") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_detach (thread);
|
|
|
|
|
2005-10-06 00:59:20 -04:00
|
|
|
sigc::connection c = Glib::signal_timeout().connect (mem_fun (current_timestretch, &TimeStretchDialog::update_progress), 100);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
while (current_timestretch->request.running) {
|
|
|
|
gtk_main_iteration ();
|
|
|
|
}
|
|
|
|
|
|
|
|
c.disconnect ();
|
2005-11-12 17:07:07 -05:00
|
|
|
|
2005-11-27 16:17:41 -05:00
|
|
|
current_timestretch->hide ();
|
2005-09-25 14:42:24 -04:00
|
|
|
return current_timestretch->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Editor::do_timestretch (TimeStretchDialog& dialog)
|
|
|
|
{
|
|
|
|
AudioTrack* at;
|
|
|
|
Playlist* playlist;
|
|
|
|
AudioRegion* new_region;
|
|
|
|
|
2006-05-19 22:57:38 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
for (AudioRegionSelection::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ) {
|
|
|
|
|
|
|
|
AudioRegion& aregion ((*i)->region);
|
|
|
|
TimeAxisView* tv = &(*i)->get_time_axis_view();
|
|
|
|
AudioTimeAxisView* atv;
|
|
|
|
AudioRegionSelection::iterator tmp;
|
|
|
|
|
2006-05-19 22:57:38 -04:00
|
|
|
cerr << "stretch " << aregion.name() << endl;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
|
|
|
if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) == 0) {
|
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:52:14 -04:00
|
|
|
if ((at = atv->audio_track()) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((playlist = at->disk_stream().playlist()) == 0) {
|
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.request.region = &aregion;
|
|
|
|
|
|
|
|
if (!dialog.request.running) {
|
|
|
|
/* we were cancelled */
|
|
|
|
dialog.status = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((new_region = session->tempoize_region (dialog.request)) == 0) {
|
|
|
|
dialog.status = -1;
|
|
|
|
dialog.request.running = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session->add_undo (playlist->get_memento());
|
|
|
|
playlist->replace_region (aregion, *new_region, aregion.position());
|
|
|
|
session->add_redo_no_execute (playlist->get_memento());
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.status = 0;
|
|
|
|
dialog.request.running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
Editor::timestretch_thread (void *arg)
|
|
|
|
{
|
|
|
|
PBD::ThreadCreated (pthread_self(), X_("TimeFX"));
|
|
|
|
|
|
|
|
TimeStretchDialog* tsd = static_cast<TimeStretchDialog*>(arg);
|
|
|
|
|
|
|
|
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
|
|
|
|
|
|
|
|
tsd->editor.do_timestretch (*tsd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|