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>
|
|
|
|
#include <ardour/diskstream.h>
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
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")),
|
|
|
|
antialias_button (_("Skip Anti-aliasing")),
|
|
|
|
cancel_button (_("Cancel")),
|
|
|
|
action_button (_("Stretch/Shrink it"))
|
|
|
|
{
|
|
|
|
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"));
|
|
|
|
|
|
|
|
add (packer);
|
|
|
|
|
|
|
|
packer.set_spacing (5);
|
|
|
|
packer.set_border_width (5);
|
|
|
|
packer.pack_start (upper_button_box);
|
|
|
|
packer.pack_start (progress_bar);
|
|
|
|
packer.pack_start (lower_button_box);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
lower_button_box.set_homogeneous (true);
|
|
|
|
lower_button_box.set_spacing (5);
|
|
|
|
lower_button_box.set_border_width (5);
|
|
|
|
lower_button_box.pack_start (action_button, true, true);
|
|
|
|
lower_button_box.pack_start (cancel_button, true, true);
|
|
|
|
|
|
|
|
action_button.set_name (N_("TimeStretchButton"));
|
|
|
|
cancel_button.set_name (N_("TimeStretchButton"));
|
|
|
|
quick_button.set_name (N_("TimeStretchButton"));
|
|
|
|
antialias_button.set_name (N_("TimeStretchButton"));
|
|
|
|
progress_bar.set_name (N_("TimeStretchProgress"));
|
|
|
|
|
2005-11-27 16:17:41 -05:00
|
|
|
// GTK2FIX
|
|
|
|
// action_button.signal_clicked().connect (bind (mem_fun(*this, &ArdourDialog::stop), 1));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
Editor::TimeStretchDialog::update_progress ()
|
|
|
|
{
|
2005-10-06 00:59:20 -04:00
|
|
|
progress_bar.set_fraction (request.progress/100);
|
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-11-12 17:07:07 -05:00
|
|
|
// GTK2FIX
|
2005-11-27 16:17:41 -05:00
|
|
|
// current_timestretch->first_cancel = current_timestretch->cancel_button.signal_clicked().connect (bind (mem_fun (*current_timestretch, &ArdourDialog::stop), -1));
|
2005-11-12 17:07:07 -05:00
|
|
|
// current_timestretch->first_delete = current_timestretch->signal_delete_event().connect (mem_fun (*current_timestretch, &ArdourDialog::wm_close_event));
|
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();
|
|
|
|
|
2005-09-25 17:19:23 -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)) {
|
2005-11-23 12:21:12 -05:00
|
|
|
// GTK2FIX
|
|
|
|
//current_timestretch->close ();
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
|
|
|
if ((atv = dynamic_cast<AudioTimeAxisView*> (tv)) == 0) {
|
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((at = dynamic_cast<AudioTrack*> (&atv->route())) == 0) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|