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>
|
2006-07-28 23:17:11 -04:00
|
|
|
#include <pbd/memento_command.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
#include "audio_time_axis.h"
|
2006-08-03 22:18:45 -04:00
|
|
|
#include "audio_region_view.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#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-22 19:40:55 -04:00
|
|
|
#include <ardour/audio_diskstream.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2006-06-22 19:40:55 -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
|
2006-08-03 22:18:45 -04:00
|
|
|
Editor::run_timestretch (RegionSelection& regions, float fraction)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2006-08-03 22:18:45 -04:00
|
|
|
Track* t;
|
2005-09-25 14:42:24 -04:00
|
|
|
Playlist* playlist;
|
2006-08-24 21:07:15 -04:00
|
|
|
boost::shared_ptr<Region> new_region;
|
2006-05-19 22:57:38 -04:00
|
|
|
|
2006-08-03 22:18:45 -04:00
|
|
|
for (RegionSelection::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ) {
|
|
|
|
AudioRegionView* arv = dynamic_cast<AudioRegionView*>(*i);
|
|
|
|
if (!arv)
|
|
|
|
continue;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-08-24 21:07:15 -04:00
|
|
|
boost::shared_ptr<AudioRegion> region (arv->audio_region());
|
2006-08-03 22:18:45 -04:00
|
|
|
TimeAxisView* tv = &(arv->get_time_axis_view());
|
|
|
|
RouteTimeAxisView* rtv;
|
|
|
|
RegionSelection::iterator tmp;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
|
|
|
|
2006-08-03 22:18:45 -04:00
|
|
|
if ((rtv = dynamic_cast<RouteTimeAxisView*> (tv)) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-08-03 22:18:45 -04:00
|
|
|
if ((t = dynamic_cast<Track*> (rtv->route().get())) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-08-15 21:19:06 -04:00
|
|
|
if ((playlist = t->diskstream()->playlist()) == 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
i = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-08-24 21:07:15 -04:00
|
|
|
dialog.request.region = region;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-07-24 21:50:20 -04:00
|
|
|
XMLNode &before = playlist->get_state();
|
2006-08-24 21:07:15 -04:00
|
|
|
playlist->replace_region (region, new_region, region->position());
|
2006-07-24 21:50:20 -04:00
|
|
|
XMLNode &after = playlist->get_state();
|
2006-08-12 17:49:20 -04:00
|
|
|
session->add_command (new MementoCommand<Playlist>(*playlist, &before, &after));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.status = 0;
|
|
|
|
dialog.request.running = false;
|
2006-08-24 21:07:15 -04:00
|
|
|
dialog.request.region.reset ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|