#include <string>
#include <map>
-#include <sndfile.h>
-
#include <pbd/error.h>
#include <pbd/basename.h>
#include <pbd/pthread_utils.h>
#include <ardour/audioregion.h>
#include <ardour/diskstream.h>
#include <ardour/filesource.h>
-#include <ardour/sndfilesource.h>
+#include <ardour/externalsource.h>
#include <ardour/utils.h>
#include <ardour/location.h>
#include <ardour/named_selection.h>
#include "streamview.h"
#include "regionview.h"
#include "rgb_macros.h"
-#include "extra_bind.h"
#include "selection_templates.h"
#include "selection.h"
-#include "library_ui.h"
+#include "sfdb_ui.h"
#include "editing.h"
#include "gtk-custom-hruler.h"
+#include "gui_thread.h"
#include "i18n.h"
}
}
+void
+Editor::set_meter_hold (int32_t cnt)
+{
+ if (session) {
+ session->set_meter_hold (cnt);
+ }
+}
+
+void
+Editor::set_meter_falloff (float val)
+{
+ if (session) {
+ session->set_meter_falloff (val);
+ }
+}
+
+
int
Editor::ensure_cursor (jack_nframes_t *pos)
{
vector<string> choices;
string prompt;
- prompt = compose (_(" This is destructive, will possibly delete audio files\n\
+ prompt = string_compose (_(" This is destructive, will possibly delete audio files\n\
It cannot be undone\n\
Do you really want to destroy %1 ?"),
(selected > 1 ?
choices.push_back (_("No, do nothing."));
Gtkmm2ext::Choice prompter (prompt, choices);
-
- prompter.chosen.connect (Gtk::Main::quit.slot());
- prompter.show_all ();
-
- Gtk::Main::run ();
-
- if (prompter.get_choice() != 0) {
+
+ if (prompter.run() != 0) { /* first choice */
return;
}
if (playhead_cursor->current_frame > distance) {
session->request_locate (playhead_cursor->current_frame - distance);
} else {
- session->request_locate (0);
+ session->goto_start();
}
}
}
void
Editor::move_to_start ()
{
- session->request_locate (0);
+ session->goto_start ();
}
void
point = Start;
break;
default:
- fatal << compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
+ fatal << string_compose (_("build_region_boundary_cache called with snap_type = %1"), snap_type) << endmsg;
/*NOTREACHED*/
return;
}
}
}
- rpos = (jack_nframes_t) floor ( (float) rpos / speed );
+ rpos = track_frame_to_session_frame(rpos, speed);
if (region_boundary_cache.empty() || rpos != region_boundary_cache.back()) {
if (snap_type == SnapToRegionBoundary) {
track_speed = atav->get_diskstream()->speed();
}
- track_frame = (jack_nframes_t) floor ( (float) frame * track_speed );
+ track_frame = session_frame_to_track_frame(frame, track_speed);
if ((r = (*i)->find_next_region (track_frame, point, dir)) == 0) {
continue;
rpos = r->adjust_to_sync (r->first_frame());
break;
}
- // rpos is a "track frame", converting it to "time frame"
- rpos = (jack_nframes_t) floor ( (float) rpos / track_speed );
+ // rpos is a "track frame", converting it to "session frame"
+ rpos = track_frame_to_session_frame(rpos, track_speed);
if (rpos > frame) {
distance = rpos - frame;
}
}
- pos = (jack_nframes_t) floor ( (float) pos / speed );
-
+ pos = track_frame_to_session_frame(pos, speed);
if (cursor == playhead_cursor) {
session->request_locate (pos);
cnt = (int) floor (prefix);
}
- Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
- adj->set_value (adj->get_value() + (cnt * adj->get_page_size()));
+ double vert_value = vertical_adjustment.get_value() + (cnt *
+ vertical_adjustment.get_page_size());
+ if (vert_value > vertical_adjustment.get_upper() - canvas_height) {
+ vert_value = vertical_adjustment.get_upper() - canvas_height;
+ }
+ vertical_adjustment.set_value (vert_value);
}
void
cnt = (int) floor (prefix);
}
- Gtk::Adjustment *adj = track_canvas_scroller.get_vadjustment();
- adj->set_value (adj->get_value() - (cnt * adj->get_page_size()));
+ vertical_adjustment.set_value (vertical_adjustment.get_value() - (cnt * vertical_adjustment.get_page_size()));
}
void
Editor::scroll_tracks_down_line ()
{
- edit_vscrollbar.default_vmotion (0, 10);
+
+ Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
+ double vert_value = adj->get_value() + 20;
+
+ if (vert_value>adj->get_upper() - canvas_height) {
+ vert_value = adj->get_upper() - canvas_height;
+ }
+ adj->set_value (vert_value);
}
void
Editor::scroll_tracks_up_line ()
{
- edit_vscrollbar.default_vmotion (0, -10);
+ Gtk::Adjustment* adj = edit_vscrollbar.get_adjustment();
+ adj->set_value (adj->get_value() - 20);
}
/* ZOOM */
void
Editor::temporal_zoom_step (bool coarser)
{
+ ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::temporal_zoom_step), coarser));
+
double nfpu;
nfpu = frames_per_unit;
// leftmost_after_zoom = min (leftmost_after_zoom, session->current_end_frame());
// begin_reversible_command (_("zoom"));
-// session->add_undo (bind (slot (*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
-// session->add_redo (bind (slot (*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
+// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), current_leftmost, frames_per_unit));
+// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_after_zoom, nfpu));
// commit_reversible_command ();
reposition_and_zoom (leftmost_after_zoom, nfpu);
void
Editor::temporal_zoom_session ()
{
+ ENSURE_GUI_THREAD (mem_fun (*this, &Editor::temporal_zoom_session));
+
if (session) {
- temporal_zoom_by_frame (0, session->current_end_frame(), "zoom to session");
+ temporal_zoom_by_frame (session->current_start_frame(), session->current_end_frame(), "zoom to session");
}
}
void
-Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, string op)
+Editor::temporal_zoom_by_frame (jack_nframes_t start, jack_nframes_t end, const string & op)
{
if (!session) return;
if (new_leftmost > middle) new_leftmost = 0;
// begin_reversible_command (op);
-// session->add_undo (bind (slot (*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
-// session->add_redo (bind (slot (*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
+// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
+// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
// commit_reversible_command ();
reposition_and_zoom (new_leftmost, new_fpu);
if (new_leftmost > frame) new_leftmost = 0;
// begin_reversible_command (_("zoom to frame"));
-// session->add_undo (bind (slot (*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
-// session->add_redo (bind (slot (*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
+// session->add_undo (bind (mem_fun(*this, &Editor::reposition_and_zoom), leftmost_frame, frames_per_unit));
+// session->add_redo (bind (mem_fun(*this, &Editor::reposition_and_zoom), new_leftmost, new_fpu));
// commit_reversible_command ();
reposition_and_zoom (new_leftmost, new_fpu);
}
void
-Editor::select_all_in_track (bool add)
+Editor::add_location_from_selection ()
+{
+ if (selection->time.empty()) {
+ return;
+ }
+
+ if (session == 0 || clicked_trackview == 0) {
+ return;
+ }
+
+ jack_nframes_t start = selection->time[clicked_selection].start;
+ jack_nframes_t end = selection->time[clicked_selection].end;
+
+ Location *location = new Location (start, end, "selection");
+
+ session->begin_reversible_command (_("add marker"));
+ session->add_undo (session->locations()->get_memento());
+ session->locations()->add (location, true);
+ session->add_redo_no_execute (session->locations()->get_memento());
+ session->commit_reversible_command ();
+}
+
+void
+Editor::add_location_from_playhead_cursor ()
+{
+ jack_nframes_t where = session->audible_frame();
+
+ Location *location = new Location (where, where, "mark", Location::IsMark);
+ session->begin_reversible_command (_("add marker"));
+ session->add_undo (session->locations()->get_memento());
+ session->locations()->add (location, true);
+ session->add_redo_no_execute (session->locations()->get_memento());
+ session->commit_reversible_command ();
+}
+
+void
+Editor::add_location_from_audio_region ()
+{
+ if (selection->audio_regions.empty()) {
+ return;
+ }
+
+ AudioRegionView* rv = *(selection->audio_regions.begin());
+ Region& region = rv->region;
+
+ Location *location = new Location (region.position(), region.last_frame(), region.name());
+ session->begin_reversible_command (_("add marker"));
+ session->add_undo (session->locations()->get_memento());
+ session->locations()->add (location, true);
+ session->add_redo_no_execute (session->locations()->get_memento());
+ session->commit_reversible_command ();
+}
+
+void
+Editor::select_all_in_track (Selection::Operation op)
{
list<Selectable *> touched;
clicked_trackview->get_selectables (0, max_frames, 0, DBL_MAX, touched);
- if (add) {
+ switch (op) {
+ case Selection::Toggle:
selection->add (touched);
- } else {
+ break;
+ case Selection::Set:
selection->set (touched);
+ break;
+ case Selection::Extend:
+ /* not defined yet */
+ break;
}
}
void
-Editor::select_all (bool add)
+Editor::select_all (Selection::Operation op)
{
list<Selectable *> touched;
}
(*iter)->get_selectables (0, max_frames, 0, DBL_MAX, touched);
}
-
- if (add) {
+ begin_reversible_command (_("select all"));
+ switch (op) {
+ case Selection::Toggle:
selection->add (touched);
- } else {
+ break;
+ case Selection::Set:
selection->set (touched);
+ break;
+ case Selection::Extend:
+ /* not defined yet */
+ break;
}
-
+ commit_reversible_command ();
}
void
}
bool
-Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, bool add)
+Editor::select_all_within (jack_nframes_t start, jack_nframes_t end, double top, double bot, Selection::Operation op)
{
list<Selectable *> touched;
}
(*iter)->get_selectables (start, end, top, bot, touched);
}
-
- if (add) {
+ begin_reversible_command (_("select all within"));
+ switch (op) {
+ case Selection::Toggle:
selection->add (touched);
- } else {
+ break;
+ case Selection::Set:
selection->set (touched);
+ break;
+ case Selection::Extend:
+ /* not defined yet */
+ break;
}
-
+ commit_reversible_command ();
return !touched.empty();
}
+void
+Editor::set_selection_from_audio_region ()
+{
+ if (selection->audio_regions.empty()) {
+ return;
+ }
+
+ AudioRegionView* rv = *(selection->audio_regions.begin());
+ Region& region = rv->region;
+
+ begin_reversible_command (_("set selection from region"));
+ selection->set (0, region.position(), region.last_frame());
+ commit_reversible_command ();
+
+ set_mouse_mode (Editing::MouseRange, false);
+}
+
void
Editor::set_selection_from_punch()
{
if ((location = session->locations()->auto_loop_location()) == 0) {
return;
}
-
set_selection_from_range (*location);
}
void
-Editor::set_selection_from_range (Location& range)
+Editor::set_selection_from_range (Location& loc)
{
- if (clicked_trackview == 0) {
+ begin_reversible_command (_("set selection from range"));
+ selection->set (0, loc.start(), loc.end());
+ commit_reversible_command ();
+
+ set_mouse_mode (Editing::MouseRange, false);
+}
+
+void
+Editor::select_all_selectables_using_time_selection ()
+{
+ list<Selectable *> touched;
+
+ if (selection->time.empty()) {
+ return;
+ }
+
+ jack_nframes_t start = selection->time[clicked_selection].start;
+ jack_nframes_t end = selection->time[clicked_selection].end;
+
+ if (end - start < 1) {
+ return;
+ }
+
+ for (TrackViewList::iterator iter = selection->tracks.begin(); iter != selection->tracks.end(); ++iter) {
+ if ((*iter)->hidden()) {
+ continue;
+ }
+ (*iter)->get_selectables (start, end - 1, 0, DBL_MAX, touched);
+ }
+
+ begin_reversible_command (_("select all from range"));
+ selection->set (touched);
+ commit_reversible_command ();
+}
+
+
+void
+Editor::select_all_selectables_using_punch()
+{
+ Location* location = session->locations()->auto_punch_location();
+ list<Selectable *> touched;
+
+ if (location == 0 || (location->end() - location->start() <= 1)) {
+ return;
+ }
+
+ for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+ if ((*iter)->hidden()) {
+ continue;
+ }
+ (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
+ }
+ begin_reversible_command (_("select all from punch"));
+ selection->set (touched);
+ commit_reversible_command ();
+
+}
+
+void
+Editor::select_all_selectables_using_loop()
+{
+ Location* location = session->locations()->auto_loop_location();
+ list<Selectable *> touched;
+
+ if (location == 0 || (location->end() - location->start() <= 1)) {
+ return;
+ }
+
+ for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+ if ((*iter)->hidden()) {
+ continue;
+ }
+ (*iter)->get_selectables (location->start(), location->end() - 1, 0, DBL_MAX, touched);
+ }
+ begin_reversible_command (_("select all from loop"));
+ selection->set (touched);
+ commit_reversible_command ();
+
+}
+
+void
+Editor::select_all_selectables_using_cursor (Cursor *cursor, bool after)
+{
+ jack_nframes_t start;
+ jack_nframes_t end;
+ list<Selectable *> touched;
+
+ if (after) {
+ begin_reversible_command (_("select all after cursor"));
+ start = cursor->current_frame ;
+ end = session->current_end_frame();
+ } else {
+ if (cursor->current_frame > 0) {
+ begin_reversible_command (_("select all before cursor"));
+ start = 0;
+ end = cursor->current_frame - 1;
+ } else {
+ return;
+ }
+ }
+
+ for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+ if ((*iter)->hidden()) {
+ continue;
+ }
+ (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
+ }
+ selection->set (touched);
+ commit_reversible_command ();
+}
+
+void
+Editor::select_all_selectables_between_cursors (Cursor *cursor, Cursor *other_cursor)
+{
+ jack_nframes_t start;
+ jack_nframes_t end;
+ list<Selectable *> touched;
+ bool other_cursor_is_first = cursor->current_frame > other_cursor->current_frame;
+
+ if (cursor->current_frame == other_cursor->current_frame) {
return;
}
+
+ begin_reversible_command (_("select all between cursors"));
+ if (other_cursor_is_first) {
+ start = other_cursor->current_frame;
+ end = cursor->current_frame - 1;
+
+ } else {
+ start = cursor->current_frame;
+ end = other_cursor->current_frame - 1;
+ }
- begin_reversible_command (_("set selection from range"));
- selection->set (0, range.start(), range.end());
+ for (TrackViewList::iterator iter = track_views.begin(); iter != track_views.end(); ++iter) {
+ if ((*iter)->hidden()) {
+ continue;
+ }
+ (*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
+ }
+ selection->set (touched);
commit_reversible_command ();
}
if (location) {
session->request_locate (location->start(), session->transport_rolling());
} else {
- session->request_locate (0);
+ session->goto_start ();
}
}
/* INSERT/REPLACE */
void
-Editor::insert_region_list_drag (AudioRegion& region)
+Editor::insert_region_list_drag (AudioRegion& region, int x, int y)
{
- gint x, y;
double wx, wy;
double cx, cy;
TimeAxisView *tv;
AudioTimeAxisView *atv = 0;
Playlist *playlist;
- track_canvas->get_pointer (x, y);
+ track_canvas.window_to_world (x, y, wx, wy);
+ wx += horizontal_adjustment.get_value();
+ wy += vertical_adjustment.get_value();
- gtk_canvas_window_to_world (GTK_CANVAS(track_gtk_canvas), x, y, &wx, &wy);
-
GdkEvent event;
event.type = GDK_BUTTON_RELEASE;
event.button.x = wx;
return;
}
- Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
+ Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
- if (selected.empty()) {
+ if (selected->count_selected_rows() != 1) {
return;
}
- Region* region = reinterpret_cast<Region *> (selected.front().get_data ());
+ TreeModel::iterator i = region_list_display.get_selection()->get_selected();
+ Region* region = (*i)[region_list_columns.region];
begin_reversible_command (_("insert region"));
session->add_undo (playlist->get_memento());
void
Editor::play_from_start ()
{
- session->request_locate (0, true);
+ session->request_locate (session->current_start_frame(), true);
}
void
}
}
-void
-Editor::toggle_loop_playback ()
-{
- if (session) {
- session->request_auto_loop (true);
- }
-}
-
void
Editor::loop_selected_region ()
{
region_renamed = false;
- entry.activate.connect (bind (slot (*this, &Editor::rename_region_finished), true));
- ok_button.signal_clicked().connect (bind (slot (*this, &Editor::rename_region_finished), true));
- cancel_button.signal_clicked().connect (bind (slot (*this, &Editor::rename_region_finished), false));
+ entry.signal_activate().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
+ ok_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), true));
+ cancel_button.signal_clicked().connect (bind (mem_fun(*this, &Editor::rename_region_finished), false));
/* recurse */
dialog.show_all ();
- ARDOUR_UI::instance()->allow_focus (true);
Main::run ();
- ARDOUR_UI::instance()->allow_focus (false);
if (region_renamed) {
(*selection->audio_regions.begin())->region.set_name (entry.get_text());
void
Editor::build_interthread_progress_window ()
{
- interthread_progress_window = new ArdourDialog (X_("interthread progress"));
+ interthread_progress_window = new ArdourDialog (X_("interthread progress"), true);
- interthread_progress_bar.set_orientation (GTK_PROGRESS_LEFT_TO_RIGHT);
+ interthread_progress_bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
- interthread_progress_vbox.set_border_width (10);
- interthread_progress_vbox.set_spacing (5);
- interthread_progress_vbox.pack_start (interthread_progress_label, false, false);
- interthread_progress_vbox.pack_start (interthread_progress_bar,false, false);
- interthread_progress_vbox.pack_start (interthread_cancel_button,false, false);
+ interthread_progress_window->get_vbox()->pack_start (interthread_progress_label, false, false);
+ interthread_progress_window->get_vbox()->pack_start (interthread_progress_bar,false, false);
+
+ // GTK2FIX: this button needs a modifiable label
+
+ Button* b = interthread_progress_window->add_button (Stock::CANCEL, RESPONSE_CANCEL);
+ b->signal_clicked().connect (mem_fun(*this, &Editor::interthread_cancel_clicked));
interthread_cancel_button.add (interthread_cancel_label);
- interthread_cancel_button.signal_clicked().connect (slot (*this, &Editor::interthread_cancel_clicked));
-
- interthread_progress_window->set_modal (true);
interthread_progress_window->set_default_size (200, 100);
- interthread_progress_window->add (interthread_progress_vbox);
}
void
}
}
-void *
-Editor::_import_thread (void *arg)
+void
+Editor::region_from_selection ()
{
- PBD::ThreadCreated (pthread_self(), X_("Import"));
+ if (clicked_trackview == 0) {
+ return;
+ }
- Editor *ed = (Editor *) arg;
- return ed->import_thread ();
-}
+ if (selection->time.empty()) {
+ return;
+ }
-void *
-Editor::import_thread ()
-{
- session->import_audiofile (import_status);
- return 0;
-}
+ jack_nframes_t start = selection->time[clicked_selection].start;
+ jack_nframes_t end = selection->time[clicked_selection].end;
-gint
-Editor::import_progress_timeout (void *arg)
-{
- interthread_progress_label.set_text (import_status.doing_what);
+ jack_nframes_t selection_cnt = end - start + 1;
+
+ for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
- if (import_status.freeze) {
- interthread_cancel_button.set_sensitive(false);
- } else {
- interthread_cancel_button.set_sensitive(true);
- }
+ AudioRegion *region;
+ AudioRegion *current;
+ Region* current_r;
+ Playlist *pl;
- if (import_status.doing_what == "building peak files") {
- interthread_progress_bar.set_activity_mode (true);
- return FALSE;
- } else {
- interthread_progress_bar.set_percentage (import_status.progress);
- }
+ jack_nframes_t internal_start;
+ string new_name;
- return !(import_status.done || import_status.cancel);
-}
+ if ((pl = (*i)->playlist()) == 0) {
+ continue;
+ }
+
+ if ((current_r = pl->top_region_at (start)) == 0) {
+ continue;
+ }
+
+ if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
+ internal_start = start - current->position();
+ session->region_name (new_name, current->name(), true);
+ region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
+ }
+ }
+}
void
-Editor::import_audio (bool as_tracks)
+Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
{
- if (session == 0) {
- warning << _("You can't import an audiofile until you have a session loaded.") << endmsg;
- return;
- }
-
- SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
- sigc::connection c;
- string str;
-
- if (as_tracks) {
- c = sfdb.Action.connect (bind (slot (*this, &Editor::do_import), true));
- str =_("Import selected as tracks");
- } else {
- c = sfdb.Action.connect (bind (slot (*this, &Editor::do_import), false));
- str = _("Import selected to region list");
- }
-
- sfdb.run (str, true);
- c.disconnect ();
-}
-
-void
-Editor::catch_new_audio_region (AudioRegion* ar)
-{
- last_audio_region = ar;
-}
-
-void
-Editor::do_import (vector<string> paths, bool split, bool as_tracks)
-{
- sigc::connection c;
-
- /* SFDB sets "multichan" to true to indicate "split channels"
- so reverse the setting to match the way libardour
- interprets it.
- */
-
- import_status.multichan = !split;
-
- if (interthread_progress_window == 0) {
- build_interthread_progress_window ();
- }
-
- interthread_progress_window->set_title (_("ardour: audio import in progress"));
- interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
- interthread_progress_window->show_all ();
- interthread_progress_bar.set_percentage (0.0f);
- interthread_cancel_label.set_text (_("Cancel Import"));
- current_interthread_info = &import_status;
-
- c = session->AudioRegionAdded.connect (slot (*this, &Editor::catch_new_audio_region));
-
- for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i ) {
-
- interthread_progress_window->set_title (compose (_("ardour: importing %1"), (*i)));
-
- import_status.pathname = (*i);
- import_status.done = false;
- import_status.cancel = false;
- import_status.freeze = false;
- import_status.done = 0.0;
-
- interthread_progress_connection =
- Gtk::Main::timeout.connect (bind (slot (*this, &Editor::import_progress_timeout), (gpointer) 0), 100);
-
- last_audio_region = 0;
-
- pthread_create_and_store ("import", &import_status.thread, 0, _import_thread, this);
- pthread_detach (import_status.thread);
-
- while (!(import_status.done || import_status.cancel)) {
- gtk_main_iteration ();
- }
-
- import_status.done = true;
- interthread_progress_connection.disconnect ();
-
- if (as_tracks && last_audio_region != 0) {
- uint32_t channels = last_audio_region->n_channels();
-
- AudioTrack* at = session->new_audio_track (channels, channels);
- AudioRegion* copy = new AudioRegion (*last_audio_region);
- at->disk_stream().playlist()->add_region (*copy, 0);
- }
- }
-
- c.disconnect ();
- interthread_progress_window->hide_all ();
-}
-
-int
-Editor::reject_because_rate_differs (string path, SF_INFO& finfo, string action, bool multiple_pending)
-{
- if (!session) {
- return 1;
- }
-
- if (finfo.samplerate != (int) session->frame_rate()) {
- vector<string> choices;
-
- choices.push_back (compose (_("%1 it anyway"), action));
-
- if (multiple_pending) {
- /* XXX assumptions about sentence structure
- here for translators. Sorry.
- */
- choices.push_back (compose (_("Don't %1 it"), action));
- choices.push_back (compose (_("%1 all without questions"), action));
- choices.push_back (_("Cancel entire import"));
- } else {
- choices.push_back (_("Cancel"));
- }
-
- Gtkmm2ext::Choice rate_choice (
- compose (_("%1\nThis audiofile's sample rate doesn't match the session sample rate!"), path),
- choices);
-
- rate_choice.chosen.connect (Main::quit.slot());
- rate_choice.show_all ();
-
- Main::run ();
-
- switch (rate_choice.get_choice()) {
- case 0: /* do it anyway */
- return 0;
- case 1: /* don't import this one */
- return 1;
- case 2: /* do the rest without asking */
- return -1;
- case 3: /* stop a multi-file import */
- default:
- return -2;
- }
- }
-
- return 0;
-}
-
-void
-Editor::embed_audio ()
-{
- if (session == 0) {
- warning << _("You can't embed an audiofile until you have a session loaded.") << endmsg;
- return;
- }
-
- SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
- sigc::connection c = sfdb.Action.connect (slot (*this, &Editor::do_embed_sndfiles));
-
- sfdb.run (_("Add to External Region list"), true);
-
- c.disconnect ();
-}
-
-void
-Editor::do_embed_sndfiles (vector<string> paths, bool split)
-{
- bool multiple_files = paths.size() > 1;
- bool check_sample_rate = true;
-
- for (vector<string>::iterator i = paths.begin(); i != paths.end(); ++i) {
- embed_sndfile (*i, split, multiple_files, check_sample_rate);
- }
-
- session->save_state ("");
-}
-
-void
-Editor::embed_sndfile (string path, bool split, bool multiple_files, bool& check_sample_rate)
-{
- SndFileSource *source = 0; /* keep g++ quiet */
- AudioRegion::SourceList sources;
- string idspec;
- string linked_path;
- SNDFILE *sf;
- SF_INFO finfo;
-
- /* lets see if we can link it into the session */
-
- linked_path = session->sound_dir();
- linked_path += PBD::basename (path);
-
- if (link (path.c_str(), linked_path.c_str()) == 0) {
-
- /* there are many reasons why link(2) might have failed.
- but if it succeeds, we now have a link in the
- session sound dir that will protect against
- unlinking of the original path. nice.
- */
-
- path = linked_path;
- }
-
- memset (&finfo, 0, sizeof(finfo));
-
- /* note that we temporarily truncated _id at the colon */
-
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << compose(_("Editor: cannot open file \"%1\" (%2)"), selection, errbuf) << endmsg;
- return;
- }
- sf_close (sf);
- sf = 0;
-
- if (check_sample_rate) {
- switch (reject_because_rate_differs (path, finfo, "Embed", multiple_files)) {
- case 0:
- break;
- case 1:
- return;
- case -1:
- check_sample_rate = false;
- break;
-
- case -2:
- default:
- return;
- }
- }
-
- track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
- ARDOUR_UI::instance()->flush_pending ();
-
- /* make the proper number of channels in the region */
-
- for (int n=0; n < finfo.channels; ++n)
- {
- idspec = path;
- idspec += compose(":%1", n);
-
- try {
- source = new SndFileSource (idspec.c_str());
- sources.push_back(source);
- }
-
- catch (failed_constructor& err) {
- error << compose(_("could not open %1"), path) << endmsg;
- goto out;
- }
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- if (sources.size() > 0) {
-
- string region_name = PBD::basename_nosuffix (path);
- region_name += "-0";
-
- /* The created region isn't dropped. It emits a signal
- that is picked up by the session.
- */
-
- new AudioRegion (sources, 0, sources[0]->length(), region_name, 0,
- Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-
- /* make sure we can see it in the list */
-
- Gtk::CTree_Helpers::RowList::iterator external_node;
- external_node = region_list_display.rows().begin();
- ++external_node; /* its the second node, always */
- external_node->expand_recursive ();
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- out:
- track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
-}
-
-void
-Editor::insert_sndfile (bool as_tracks)
-{
- SoundFileSelector& sfdb (ARDOUR_UI::instance()->get_sfdb_window());
- sigc::connection c;
- string str;
-
- if (as_tracks) {
-
- c = sfdb.Action.connect (slot (*this, &Editor::insert_paths_as_new_tracks));
- str = _("Insert selected as new tracks");
-
- } else {
-
- jack_nframes_t pos;
-
- if (clicked_audio_trackview == 0) {
- return;
- }
-
- if (ensure_cursor (&pos)) {
- return;
- }
-
- c = sfdb.Action.connect (bind (slot (*this, &Editor::do_insert_sndfile), pos));
- str = _("Insert selected");
- }
-
- sfdb.run (str, false);
- c.disconnect ();
-}
-
-void
-Editor::insert_paths_as_new_tracks (vector<string> paths, bool split)
-{
- SNDFILE *sf;
- SF_INFO finfo;
- bool multiple_files;
- bool check_sample_rate = true;
-
- multiple_files = paths.size() > 1;
-
- for (vector<string>::iterator p = paths.begin(); p != paths.end(); ++p) {
-
- memset (&finfo, 0, sizeof(finfo));
-
- if ((sf = sf_open ((*p).c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << compose(_("Editor: cannot open file \"%1\" (%2)"), (*p), errbuf) << endmsg;
- continue;
- }
-
- sf_close (sf);
- sf = 0;
-
- /* add a new track */
-
- if (check_sample_rate) {
- switch (reject_because_rate_differs (*p, finfo, "Insert", multiple_files)) {
- case 0:
- break;
- case 1:
- continue;
- case -1:
- check_sample_rate = false;
- break;
-
- case -2:
- return;
- }
- }
-
- uint32_t input_chan = finfo.channels;
- uint32_t output_chan;
-
- if (session->get_output_auto_connect() & Session::AutoConnectMaster) {
- output_chan = (session->master_out() ? session->master_out()->n_inputs() : input_chan);
- } else {
- output_chan = input_chan;
- }
-
- (void) session->new_audio_track (input_chan, output_chan);
-
-
- /* get the last (most recently added) track view */
-
- AudioTimeAxisView* tv;
-
- if ((tv = dynamic_cast<AudioTimeAxisView*>(track_views.back())) == 0) {
- fatal << _("programming error: ")
- << X_("last trackview after new_audio_track is not an audio track!")
- << endmsg;
- /*NOTREACHED*/
- }
-
- jack_nframes_t pos = 0;
- insert_sndfile_into (*p, true, tv, pos, false);
- }
-}
-
-void
-Editor::do_insert_sndfile (vector<string> paths, bool split, jack_nframes_t pos)
-{
- for (vector<string>::iterator x = paths.begin(); x != paths.end(); ++x) {
- insert_sndfile_into (*x, !split, clicked_audio_trackview, pos);
- }
-}
-
-void
-Editor::insert_sndfile_into (string path, bool multi, AudioTimeAxisView* tv, jack_nframes_t& pos, bool prompt)
-{
- SndFileSource *source = 0; /* keep g++ quiet */
- AudioRegion::SourceList sources;
- string idspec;
- SNDFILE *sf;
- SF_INFO finfo;
-
- memset (&finfo, 0, sizeof(finfo));
-
- /* note that we temporarily truncated _id at the colon */
-
- if ((sf = sf_open (path.c_str(), SFM_READ, &finfo)) == 0) {
- char errbuf[256];
- sf_error_str (0, errbuf, sizeof (errbuf) - 1);
- error << compose(_("Editor: cannot open file \"%1\" (%2)"), path, errbuf) << endmsg;
- return;
- }
- sf_close (sf);
- sf = 0;
-
- if (prompt && (reject_because_rate_differs (path, finfo, "Insert", false) != 0)) {
- return;
- }
-
- track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
- ARDOUR_UI::instance()->flush_pending ();
-
- /* make the proper number of channels in the region */
-
- for (int n=0; n < finfo.channels; ++n)
- {
- idspec = path;
- idspec += compose(":%1", n);
-
- try {
- source = new SndFileSource (idspec.c_str());
- sources.push_back(source);
- }
-
- catch (failed_constructor& err) {
- error << compose(_("could not open %1"), path) << endmsg;
- goto out;
- }
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- if (sources.size() > 0) {
-
- string region_name = region_name_from_path (PBD::basename (path));
-
- AudioRegion *region = new AudioRegion (sources, 0, sources[0]->length(), region_name,
- 0, /* irrelevant these days */
- Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External));
-
- begin_reversible_command (_("insert sndfile"));
- session->add_undo (tv->playlist()->get_memento());
- tv->playlist()->add_region (*region, pos);
- session->add_redo_no_execute (tv->playlist()->get_memento());
- commit_reversible_command ();
-
- pos += sources[0]->length();
-
- ARDOUR_UI::instance()->flush_pending ();
- }
-
- out:
- track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
- return;
-}
-
-void
-Editor::region_from_selection ()
-{
- if (clicked_trackview == 0) {
- return;
- }
-
- if (selection->time.empty()) {
- return;
- }
-
- jack_nframes_t start = selection->time[clicked_selection].start;
- jack_nframes_t end = selection->time[clicked_selection].end;
-
- jack_nframes_t selection_cnt = end - start + 1;
-
- for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
-
- AudioRegion *region;
- AudioRegion *current;
- Region* current_r;
- Playlist *pl;
-
- jack_nframes_t internal_start;
- string new_name;
-
- if ((pl = (*i)->playlist()) == 0) {
- continue;
- }
-
- if ((current_r = pl->top_region_at (start)) == 0) {
- continue;
- }
-
- if ((current = dynamic_cast<AudioRegion*> (current_r)) != 0) {
- internal_start = start - current->position();
- session->region_name (new_name, current->name(), true);
- region = new AudioRegion (*current, internal_start, selection_cnt, new_name);
- }
- }
-}
-
-void
-Editor::create_region_from_selection (vector<AudioRegion *>& new_regions)
-{
- if (selection->time.empty() || selection->tracks.empty()) {
+ if (selection->time.empty() || selection->tracks.empty()) {
return;
}
if (doing_undo) commit_reversible_command ();
}
+void
+Editor::separate_regions_using_location (Location& loc)
+{
+ bool doing_undo = false;
+
+ if (loc.is_mark()) {
+ return;
+ }
+
+ Playlist *playlist;
+
+ /* XXX i'm unsure as to whether this should operate on selected tracks only
+ or the entire enchillada. uncomment the below line to correct the behaviour
+ (currently set for all tracks)
+ */
+
+ for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+ //for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+
+ AudioTimeAxisView* atv;
+
+ if ((atv = dynamic_cast<AudioTimeAxisView*> ((*i))) != 0) {
+
+ if (atv->is_audio_track()) {
+
+ if ((playlist = atv->playlist()) != 0) {
+ if (!doing_undo) {
+ begin_reversible_command (_("separate"));
+ doing_undo = true;
+ }
+ if (doing_undo) session->add_undo ((playlist)->get_memento());
+
+ /* XXX need to consider musical time selections here at some point */
+
+ double speed = atv->get_diskstream()->speed();
+
+
+ playlist->partition ((jack_nframes_t)(loc.start() * speed), (jack_nframes_t)(loc.end() * speed), true);
+ if (doing_undo) session->add_redo_no_execute (playlist->get_memento());
+ }
+ }
+ }
+ }
+
+ if (doing_undo) commit_reversible_command ();
+}
+
void
Editor::crop_region_to_selection ()
{
Region *region;
- Gtk::CTree_Helpers::SelectionList& selected = region_list_display.selection();
-
- if (selected.empty()) {
+ Glib::RefPtr<TreeSelection> selected = region_list_display.get_selection();
+
+ if (selected->count_selected_rows() != 1) {
return;
}
- region = reinterpret_cast<Region *> (selected.front().get_data());
+ TreeModel::iterator i = region_list_display.get_selection()->get_selected();
+ region = (*i)[region_list_columns.region];
jack_nframes_t start = selection->time[clicked_selection].start;
jack_nframes_t end = selection->time[clicked_selection].end;
commit_reversible_command ();
}
-
+
+void
+Editor::set_a_regions_sync_position (Region& region, jack_nframes_t position)
+{
+
+ if (!region.covers (position)) {
+ error << _("Programming error. that region doesn't cover that position") << __FILE__ << " +" << __LINE__ << endmsg;
+ return;
+ }
+ begin_reversible_command (_("set region sync position"));
+ session->add_undo (region.playlist()->get_memento());
+ region.set_sync_position (position);
+ session->add_redo_no_execute (region.playlist()->get_memento());
+ commit_reversible_command ();
+}
+
void
Editor::set_region_sync_from_edit_cursor ()
{
}
Region& region (clicked_regionview->region);
-
begin_reversible_command (_("set sync from edit cursor"));
session->add_undo (region.playlist()->get_memento());
region.set_sync_position (edit_cursor->current_frame);
begin_reversible_command (_("trim to edit"));
session->add_undo (region.playlist()->get_memento());
- region.trim_end ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
+ region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
session->add_redo_no_execute (region.playlist()->get_memento());
commit_reversible_command ();
}
begin_reversible_command (_("trim to edit"));
session->add_undo (region.playlist()->get_memento());
- region.trim_front ( (jack_nframes_t) floor( (float)edit_cursor->current_frame * speed), this);
+ region.trim_front ( session_frame_to_track_frame(edit_cursor->current_frame, speed), this);
session->add_redo_no_execute (region.playlist()->get_memento());
commit_reversible_command ();
}
gint
Editor::freeze_progress_timeout (void *arg)
{
- interthread_progress_bar.set_percentage (current_interthread_info->progress);
+ interthread_progress_bar.set_fraction (current_interthread_info->progress/100);
return !(current_interthread_info->done || current_interthread_info->cancel);
}
interthread_progress_window->set_title (_("ardour: freeze"));
interthread_progress_window->set_position (Gtk::WIN_POS_MOUSE);
interthread_progress_window->show_all ();
- interthread_progress_bar.set_percentage (0.0f);
+ interthread_progress_bar.set_fraction (0.0f);
interthread_progress_label.set_text ("");
interthread_cancel_label.set_text (_("Cancel Freeze"));
current_interthread_info = &itt;
interthread_progress_connection =
- Gtk::Main::timeout.connect (bind (slot (*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
+ Glib::signal_timeout().connect (bind (mem_fun(*this, &Editor::freeze_progress_timeout), (gpointer) 0), 100);
itt.done = false;
itt.cancel = false;
pthread_create (&itt.thread, 0, _freeze_thread, this);
- track_canvas_scroller.get_window().set_cursor (GDK_WATCH);
+ track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH));
while (!itt.done && !itt.cancel) {
gtk_main_iteration ();
interthread_progress_connection.disconnect ();
interthread_progress_window->hide_all ();
current_interthread_info = 0;
- track_canvas_scroller.get_window().set_cursor (current_canvas_cursor);
+ track_canvas.get_window()->set_cursor (*current_canvas_cursor);
}
void
void
Editor::cut_copy_regions (CutCopyOp op)
{
- typedef map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
+ typedef std::map<AudioPlaylist*,AudioPlaylist*> PlaylistMapping;
PlaylistMapping pmap;
jack_nframes_t first_position = max_frames;
set<Playlist*> freezelist;
void
Editor::mouse_paste ()
{
- gint x, y;
+ int x, y;
double wx, wy;
- track_canvas->get_pointer (x, y);
- gtk_canvas_window_to_world (GTK_CANVAS(track_gtk_canvas), x, y, &wx, &wy);
-
+ track_canvas.get_pointer (x, y);
+ track_canvas.window_to_world (x, y, wx, wy);
+ wx += horizontal_adjustment.get_value();
+ wy += vertical_adjustment.get_value();
+
GdkEvent event;
event.type = GDK_BUTTON_RELEASE;
event.button.x = wx;
void
Editor::paste_named_selection (float times)
{
- Gtk::CList_Helpers::SelectionList& selected = named_selection_display.selection();
- TrackSelection::iterator i;
+ TrackSelection::iterator t;
+
+ Glib::RefPtr<TreeSelection> selected = named_selection_display.get_selection();
- if (selected.empty() || selection->tracks.empty()) {
+ if (selected->count_selected_rows() != 1 || selection->tracks.empty()) {
return;
}
- NamedSelection* ns = static_cast<NamedSelection*> (selected.front()->get_data ());
+ TreeModel::iterator i = selected->get_selected();
+ NamedSelection* ns = (*i)[named_selection_columns.selection];
+
list<Playlist*>::iterator chunk;
list<Playlist*>::iterator tmp;
begin_reversible_command (_("paste chunk"));
- for (i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+ for (t = selection->tracks.begin(); t != selection->tracks.end(); ++t) {
AudioTimeAxisView* atv;
Playlist* pl;
AudioPlaylist* apl;
- if ((atv = dynamic_cast<AudioTimeAxisView*> (*i)) == 0) {
+ if ((atv = dynamic_cast<AudioTimeAxisView*> (*t)) == 0) {
continue;
}
Editor::duplicate_some_regions (AudioRegionSelection& regions, float times)
{
Playlist *playlist;
-
+ AudioRegionSelection sel = regions; // clear (below) will clear the argument list
+
begin_reversible_command (_("duplicate region"));
- for (AudioRegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) {
+ selection->clear_audio_regions ();
+
+ for (AudioRegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) {
Region& r ((*i)->region);
+
+ TimeAxisView& tv = (*i)->get_time_axis_view();
+ AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (&tv);
+ sigc::connection c = atv->view->AudioRegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view));
playlist = (*i)->region.playlist();
session->add_undo (playlist->get_memento());
playlist->duplicate (r, r.last_frame(), times);
session->add_redo_no_execute (playlist->get_memento());
+ c.disconnect ();
+
+ if (latest_regionview) {
+ selection->add (latest_regionview);
+ }
}
+
commit_reversible_command ();
}
commit_reversible_command ();
}
-void
-Editor::toggle_xfades_active ()
-{
- if (session) {
- session->set_crossfades_active (!session->get_crossfades_active());
- }
-}
-
-void
-Editor::toggle_follow_playhead ()
-{
- set_follow_playhead (!_follow_playhead);
-}
-
-void
-Editor::set_xfade_visibility (bool yn)
-{
-
-}
-
-void
-Editor::toggle_xfade_visibility ()
-{
- set_xfade_visibility (!xfade_visibility());
-}
-
void
Editor::remove_last_capture ()
{
choices.push_back (_("Yes, destroy it."));
choices.push_back (_("No, do nothing."));
-
+
Gtkmm2ext::Choice prompter (prompt, choices);
-
- prompter.chosen.connect (Gtk::Main::quit.slot());
- prompter.show_all ();
-
- Gtk::Main::run ();
-
- if (prompter.get_choice() == 0) {
+
+ if (prompter.run () == 0) {
session->remove_last_capture ();
}
+
} else {
session->remove_last_capture();
}
begin_reversible_command (_("normalize"));
- track_canvas_scroller.get_window().set_cursor (wait_cursor);
+ track_canvas.get_window()->set_cursor (*wait_cursor);
gdk_flush ();
for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ++r) {
}
commit_reversible_command ();
- gdk_window_set_cursor (track_canvas_scroller.get_window(), current_canvas_cursor);
+ track_canvas.get_window()->set_cursor (*current_canvas_cursor);
}
begin_reversible_command (command);
- track_canvas_scroller.get_window().set_cursor (wait_cursor);
+ track_canvas.get_window()->set_cursor (*wait_cursor);
gdk_flush ();
for (AudioRegionSelection::iterator r = selection->audio_regions.begin(); r != selection->audio_regions.end(); ) {
selection->audio_regions.clear ();
out:
- gdk_window_set_cursor (track_canvas_scroller.get_window(), current_canvas_cursor);
+ track_canvas.get_window()->set_cursor (*current_canvas_cursor);
}
void