2006-03-22 12:03:00 -05:00
/*
2009-10-14 12:10:01 -04:00
Copyright ( C ) 2000 - 2006 Paul Davis
2006-03-22 12:03:00 -05:00
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 0213 9 , USA .
*/
2007-04-12 19:20:37 -04:00
# include <sys/types.h>
# include <sys/stat.h>
2007-10-11 18:07:47 -04:00
# include <sys/time.h>
2007-04-12 19:20:37 -04:00
# include <errno.h>
# include <unistd.h>
2008-03-17 16:54:03 -04:00
# include <algorithm>
2007-04-12 19:20:37 -04:00
2007-10-11 18:07:47 -04:00
# include <sndfile.h>
2009-02-25 13:26:51 -05:00
# include "pbd/pthread_utils.h"
# include "pbd/basename.h"
# include "pbd/shortpath.h"
2010-03-02 13:05:26 -05:00
# include "pbd/stateful_diff_command.h"
2006-03-22 12:03:00 -05:00
# include <gtkmm2ext/choice.h>
2009-02-25 13:26:51 -05:00
# include "ardour/audio_track.h"
# include "ardour/audiofilesource.h"
2012-05-24 02:09:29 -04:00
# include "ardour/audioregion.h"
# include "ardour/midi_region.h"
# include "ardour/midi_track.h"
# include "ardour/operations.h"
2009-02-25 13:26:51 -05:00
# include "ardour/region_factory.h"
2010-05-19 19:36:18 -04:00
# include "ardour/smf_source.h"
2012-05-24 02:09:29 -04:00
# include "ardour/source_factory.h"
# include "ardour/utils.h"
2009-02-25 13:26:51 -05:00
# include "pbd/memento_command.h"
2006-03-22 12:03:00 -05:00
# include "ardour_ui.h"
2014-12-20 01:11:28 -05:00
# include "cursor_context.h"
2006-03-22 12:03:00 -05:00
# include "editor.h"
# include "sfdb_ui.h"
# include "editing.h"
# include "audio_time_axis.h"
2008-02-18 14:45:52 -05:00
# include "midi_time_axis.h"
2008-09-26 04:29:30 -04:00
# include "session_import_dialog.h"
2008-12-12 09:43:24 -05:00
# include "gui_thread.h"
2010-04-14 18:16:46 -04:00
# include "interthread_progress_window.h"
2010-11-16 09:53:16 -05:00
# include "mouse_cursors.h"
# include "editor_cursors.h"
2006-03-22 12:03:00 -05:00
# include "i18n.h"
using namespace std ;
using namespace ARDOUR ;
Large nasty commit in the form of a 5000 line patch chock-full of completely
unecessary changes. (Sorry, doing a "sprint" based thing, this is the end of the first one)
Achieved MIDI track and bus creation, associated Jack port and diskstream creation, and minimal GUI stuff for creating them. Should be set to start work on actually recording and playing midi to/from disk now.
Relevant (significant) changes:
- Creation of a Buffer class. Base class is type agnostic so things can point to a buffer but not care what kind it is (otherwise it'd be a template). Derived into AudioBuffer and MidiBuffer, with a type tag because checking type is necessary in parts of the code where dynamic_cast wouldn't be wise. Originally I considered this a hack, but passing around a type proved to be a very good solution to all the other problems (below). There is a 1:1 mapping between jack port data types and ardour Buffer types (with a conversion function), but that's easily removed if it ever becomes necessary. Having the type scoped in the Buffer class is maybe not the best spot for it, but whatever (this is proof of concept kinda stuff right now...)
- IO now has a "default" port type (passed to the constructor and stored as a member), used by ensure_io (and similar) to create n ports. IO::register_***_port has a type argument that defaults to the default type if not passed. Rationale: previous IO API is identical, no changes needed to existing code, but path is paved for multiple port types in one IO, which we will need for eg synth plugin inserts, among other things. This is not quite ideal (best would be to only have the two port register functions and have them take a type), but the alternative is a lot of work (namely destroying the 'ensure' functions and everything that uses them) for very little gain. (I am convinced after quite a few tries at the whiteboard that subclassing IO in any way is not a feasible option, look at it's inheritance diagram in Doxygen and you can see why)
- AudioEngine::register_audio_input_port is now register_input_port and takes a type argument. Ditto for output.
- (Most significant change) AudioDiskstream abstracted into Distream, and sibling MidiDiskstream created. Very much still a work in progress, but Diskstream is there to switch references over to (most already are), which is the important part. It is still unclear what the MIDI diskstream's relation to channels is, but I'm pretty sure they will be single channel only (so SMF Type 0) since noone can come up with a reason otherwise.
- MidiTrack creation. Same thing as AudioTrack but with a different default type basically. No big deal here.
- Random cleanups and variable renamings etc. because I have OCD and can't help myself. :)
Known broken: Loading of sessions containing MIDI tracks.
git-svn-id: svn://localhost/ardour2/branches/midi@641 d708f5d6-7413-0410-9779-e7cbd77b26cf
2006-06-26 12:01:34 -04:00
using namespace PBD ;
2006-03-22 12:03:00 -05:00
using namespace Gtk ;
2007-03-19 03:07:38 -04:00
using namespace Gtkmm2ext ;
2006-03-22 12:03:00 -05:00
using namespace Editing ;
2010-09-14 12:51:02 -04:00
using std : : string ;
2006-03-22 12:03:00 -05:00
/* Functions supporting the incorporation of external (non-captured) audio material into ardour */
void
2007-10-11 18:07:47 -04:00
Editor : : add_external_audio_action ( ImportMode mode_hint )
2006-03-22 12:03:00 -05:00
{
2009-12-17 13:24:23 -05:00
if ( _session = = 0 ) {
2008-09-10 11:03:30 -04:00
MessageDialog msg ( _ ( " You can't import or embed an audiofile until you have a session loaded. " ) ) ;
2007-10-11 18:07:47 -04:00
msg . run ( ) ;
return ;
}
2011-06-01 13:00:29 -04:00
2007-10-11 18:07:47 -04:00
if ( sfbrowser = = 0 ) {
2012-12-23 15:34:43 -05:00
sfbrowser = new SoundFileOmega ( _ ( " Add Existing Media " ) , _session , 0 , true , mode_hint ) ;
2007-10-11 18:07:47 -04:00
} else {
sfbrowser - > set_mode ( mode_hint ) ;
2006-03-22 12:03:00 -05:00
}
2007-10-11 18:07:47 -04:00
external_audio_dialog ( ) ;
2006-03-22 12:03:00 -05:00
}
void
2007-10-11 18:07:47 -04:00
Editor : : external_audio_dialog ( )
2006-03-22 12:03:00 -05:00
{
2010-09-14 11:45:21 -04:00
vector < string > paths ;
2011-07-26 13:22:10 -04:00
uint32_t audio_track_cnt ;
uint32_t midi_track_cnt ;
2007-10-11 18:07:47 -04:00
2009-12-17 13:24:23 -05:00
if ( _session = = 0 ) {
2008-09-10 11:03:30 -04:00
MessageDialog msg ( _ ( " You can't import or embed an audiofile until you have a session loaded. " ) ) ;
2006-03-22 12:03:00 -05:00
msg . run ( ) ;
return ;
}
2009-10-14 12:10:01 -04:00
2011-07-26 13:22:10 -04:00
audio_track_cnt = 0 ;
midi_track_cnt = 0 ;
2006-03-22 12:03:00 -05:00
2007-10-11 18:07:47 -04:00
for ( TrackSelection : : iterator x = selection - > tracks . begin ( ) ; x ! = selection - > tracks . end ( ) ; + + x ) {
2009-07-09 13:58:13 -04:00
AudioTimeAxisView * atv = dynamic_cast < AudioTimeAxisView * > ( * x ) ;
2009-10-14 12:10:01 -04:00
2011-07-26 13:22:10 -04:00
if ( atv ) {
if ( atv - > is_audio_track ( ) ) {
audio_track_cnt + + ;
}
} else {
MidiTimeAxisView * mtv = dynamic_cast < MidiTimeAxisView * > ( * x ) ;
if ( mtv ) {
if ( mtv - > is_midi_track ( ) ) {
midi_track_cnt + + ;
}
}
2007-10-11 18:07:47 -04:00
}
}
if ( sfbrowser = = 0 ) {
2012-12-23 15:34:43 -05:00
sfbrowser = new SoundFileOmega ( _ ( " Add Existing Media " ) , _session , audio_track_cnt , midi_track_cnt , true ) ;
2007-10-11 18:07:47 -04:00
} else {
2011-07-26 13:22:10 -04:00
sfbrowser - > reset ( audio_track_cnt , midi_track_cnt ) ;
2007-10-11 18:07:47 -04:00
}
sfbrowser - > show_all ( ) ;
2008-02-16 17:43:18 -05:00
}
2008-09-26 04:29:30 -04:00
void
Editor : : session_import_dialog ( )
{
2009-12-17 13:24:23 -05:00
SessionImportDialog dialog ( _session ) ;
2008-09-26 04:29:30 -04:00
ensure_float ( dialog ) ;
dialog . run ( ) ;
}
2008-02-16 17:43:18 -05:00
typedef std : : map < PBD : : ID , boost : : shared_ptr < ARDOUR : : Source > > SourceMap ;
/**
2012-06-09 11:04:11 -04:00
* Updating is still disabled , see note in libs / ardour / import . cc Session : : import_files ( )
2008-02-16 17:43:18 -05:00
*
* all_or_nothing :
* true = show " Update " , " Import " and " Skip "
* false = show " Import " , and " Cancel "
*
* Returns :
* 0 To update an existing source of the same name
* 1 To import / embed the file normally ( make sure the new name will be unique )
* 2 If the user wants to skip this file
* */
int
Editor : : check_whether_and_how_to_import ( string path , bool all_or_nothing )
{
string wave_name ( Glib : : path_get_basename ( path ) ) ;
2010-11-09 17:18:52 -05:00
bool already_exists = false ;
2010-11-25 15:37:39 -05:00
uint32_t existing ;
2008-02-16 17:43:18 -05:00
2010-11-25 15:37:39 -05:00
if ( ( existing = _session - > count_sources_by_origin ( path ) ) > 0 ) {
already_exists = true ;
}
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
int function = 1 ;
2010-11-09 17:18:52 -05:00
if ( already_exists ) {
2008-02-16 17:43:18 -05:00
string message ;
if ( all_or_nothing ) {
// updating is still disabled
//message = string_compose(_("The session already contains a source file named %1. Do you want to update that file (and thus all regions using the file) or import this file as a new file?"),wave_name);
2009-08-01 20:32:51 -04:00
message = string_compose ( _ ( " The session already contains a source file named %1. Do you want to import %1 as a new file, or skip it? " ) , wave_name ) ;
2008-02-16 17:43:18 -05:00
} else {
2009-08-01 20:32:51 -04:00
message = string_compose ( _ ( " The session already contains a source file named %1. Do you want to import %2 as a new source, or skip it? " ) , wave_name , wave_name ) ;
2008-02-16 17:43:18 -05:00
}
2008-09-17 17:48:57 -04:00
MessageDialog dialog ( message , false , Gtk : : MESSAGE_QUESTION , Gtk : : BUTTONS_NONE , true ) ;
2008-02-16 17:43:18 -05:00
if ( all_or_nothing ) {
// disabled
//dialog.add_button("Update", 0);
dialog . add_button ( " Import " , 1 ) ;
dialog . add_button ( " Skip " , 2 ) ;
} else {
dialog . add_button ( " Import " , 1 ) ;
dialog . add_button ( " Cancel " , 2 ) ;
}
2009-10-14 12:10:01 -04:00
2008-02-16 17:43:18 -05:00
//dialog.add_button("Skip all", 4); // All or rest?
dialog . show ( ) ;
function = dialog . run ( ) ;
dialog . hide ( ) ;
2006-03-22 12:03:00 -05:00
}
2008-02-16 17:43:18 -05:00
return function ;
2006-03-22 12:03:00 -05:00
}
2007-10-11 18:07:47 -04:00
boost : : shared_ptr < AudioTrack >
Editor : : get_nth_selected_audio_track ( int nth ) const
2006-03-22 12:03:00 -05:00
{
2009-07-09 13:58:13 -04:00
AudioTimeAxisView * atv ;
2007-10-11 18:07:47 -04:00
TrackSelection : : iterator x ;
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
for ( x = selection - > tracks . begin ( ) ; nth > 0 & & x ! = selection - > tracks . end ( ) ; + + x ) {
2006-03-22 12:03:00 -05:00
2009-07-09 13:58:13 -04:00
atv = dynamic_cast < AudioTimeAxisView * > ( * x ) ;
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
if ( ! atv ) {
continue ;
} else if ( atv - > is_audio_track ( ) ) {
- - nth ;
}
2006-03-22 12:03:00 -05:00
}
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
if ( x = = selection - > tracks . end ( ) ) {
2009-07-09 13:58:13 -04:00
atv = dynamic_cast < AudioTimeAxisView * > ( selection - > tracks . back ( ) ) ;
2007-10-11 18:07:47 -04:00
} else {
2009-07-09 13:58:13 -04:00
atv = dynamic_cast < AudioTimeAxisView * > ( * x ) ;
2007-10-11 18:07:47 -04:00
}
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
if ( ! atv | | ! atv - > is_audio_track ( ) ) {
return boost : : shared_ptr < AudioTrack > ( ) ;
}
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
return atv - > audio_track ( ) ;
2009-10-14 12:10:01 -04:00
}
2006-03-22 12:03:00 -05:00
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < MidiTrack >
Editor : : get_nth_selected_midi_track ( int nth ) const
{
2009-07-09 13:58:13 -04:00
MidiTimeAxisView * mtv ;
2008-02-18 14:45:52 -05:00
TrackSelection : : iterator x ;
2009-10-14 12:10:01 -04:00
2008-02-18 14:45:52 -05:00
for ( x = selection - > tracks . begin ( ) ; nth > 0 & & x ! = selection - > tracks . end ( ) ; + + x ) {
2009-07-09 13:58:13 -04:00
mtv = dynamic_cast < MidiTimeAxisView * > ( * x ) ;
2009-10-14 12:10:01 -04:00
2008-02-18 14:45:52 -05:00
if ( ! mtv ) {
continue ;
} else if ( mtv - > is_midi_track ( ) ) {
- - nth ;
}
}
2009-10-14 12:10:01 -04:00
2008-02-18 14:45:52 -05:00
if ( x = = selection - > tracks . end ( ) ) {
2009-07-09 13:58:13 -04:00
mtv = dynamic_cast < MidiTimeAxisView * > ( selection - > tracks . back ( ) ) ;
2008-02-18 14:45:52 -05:00
} else {
2009-07-09 13:58:13 -04:00
mtv = dynamic_cast < MidiTimeAxisView * > ( * x ) ;
2008-02-18 14:45:52 -05:00
}
2009-10-14 12:10:01 -04:00
2008-02-18 14:45:52 -05:00
if ( ! mtv | | ! mtv - > is_midi_track ( ) ) {
return boost : : shared_ptr < MidiTrack > ( ) ;
}
2009-10-14 12:10:01 -04:00
2008-02-18 14:45:52 -05:00
return mtv - > midi_track ( ) ;
2009-10-14 12:10:01 -04:00
}
2008-02-18 14:45:52 -05:00
2007-10-11 18:07:47 -04:00
void
2013-07-23 11:28:45 -04:00
Editor : : do_import ( vector < string > paths , ImportDisposition disposition , ImportMode mode , SrcQuality quality , framepos_t & pos )
2007-10-11 18:07:47 -04:00
{
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < Track > track ;
2010-09-14 11:45:21 -04:00
vector < string > to_import ;
2007-10-11 18:07:47 -04:00
int nth = 0 ;
2010-11-25 15:37:39 -05:00
bool use_timestamp = ( pos = = - 1 ) ;
2007-01-09 18:24:54 -05:00
2010-04-09 21:35:11 -04:00
current_interthread_info = & import_status ;
import_status . current = 1 ;
import_status . total = paths . size ( ) ;
2010-09-29 18:59:39 -04:00
import_status . all_done = false ;
2010-04-09 21:35:11 -04:00
2010-04-14 18:16:46 -04:00
ImportProgressWindow ipw ( & import_status , _ ( " Import " ) , _ ( " Cancel Import " ) ) ;
2010-04-09 21:35:11 -04:00
2010-09-29 19:02:32 -04:00
bool ok = true ;
2013-07-23 11:28:45 -04:00
if ( disposition = = Editing : : ImportMergeFiles ) {
2008-12-12 09:43:24 -05:00
2008-02-16 17:43:18 -05:00
/* create 1 region from all paths, add to 1 track,
ignore " track "
*/
2008-12-12 09:43:24 -05:00
2008-02-16 17:43:18 -05:00
bool cancel = false ;
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator a = paths . begin ( ) ; a ! = paths . end ( ) ; + + a ) {
2008-02-16 17:43:18 -05:00
int check = check_whether_and_how_to_import ( * a , false ) ;
if ( check = = 2 ) {
cancel = true ;
break ;
2007-10-11 18:07:47 -04:00
}
2008-02-16 17:43:18 -05:00
}
2007-01-28 12:44:13 -05:00
2010-09-29 19:02:32 -04:00
if ( cancel ) {
ok = false ;
} else {
2010-11-25 15:37:39 -05:00
ipw . show ( ) ;
2013-07-23 11:28:45 -04:00
ok = ( import_sndfiles ( paths , disposition , mode , quality , pos , 1 , 1 , track , false ) = = 0 ) ;
2007-10-11 18:07:47 -04:00
}
2007-01-09 18:24:54 -05:00
2008-02-16 17:43:18 -05:00
} else {
2008-12-12 09:43:24 -05:00
2010-11-25 15:37:39 -05:00
bool replace = false ;
2006-03-22 17:18:08 -05:00
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator a = paths . begin ( ) ; a ! = paths . end ( ) ; + + a ) {
2009-10-14 12:10:01 -04:00
2010-11-25 15:37:39 -05:00
const int check = check_whether_and_how_to_import ( * a , true ) ;
2011-06-01 13:00:29 -04:00
2010-03-04 18:03:04 -05:00
switch ( check ) {
case 2 :
// user said skip
continue ;
case 0 :
fatal < < " Updating existing sources should be disabled! " < < endmsg ;
2014-11-14 04:47:43 -05:00
abort ( ) ; /* NOTREACHED*/
2010-03-04 18:03:04 -05:00
break ;
case 1 :
replace = false ;
break ;
default :
fatal < < " Illegal return " < < check < < " from check_whether_and_how_to_import()! " < < endmsg ;
2014-11-14 04:47:43 -05:00
abort ( ) ; /* NOTREACHED*/
2009-08-01 20:32:26 -04:00
}
2009-10-14 12:10:01 -04:00
2010-11-25 15:37:39 -05:00
/* have to reset this for every file we handle */
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
if ( use_timestamp ) {
pos = - 1 ;
}
2010-08-12 15:43:36 -04:00
2010-11-25 15:37:39 -05:00
ipw . show ( ) ;
2011-06-01 13:00:29 -04:00
2013-07-23 11:28:45 -04:00
switch ( disposition ) {
2010-11-25 15:37:39 -05:00
case Editing : : ImportDistinctFiles :
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
to_import . clear ( ) ;
to_import . push_back ( * a ) ;
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
if ( mode = = Editing : : ImportToTrack ) {
track = get_nth_selected_audio_track ( nth + + ) ;
}
2011-06-01 13:00:29 -04:00
2013-07-23 11:28:45 -04:00
ok = ( import_sndfiles ( to_import , disposition , mode , quality , pos , 1 , - 1 , track , replace ) = = 0 ) ;
2010-11-25 15:37:39 -05:00
break ;
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
case Editing : : ImportDistinctChannels :
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
to_import . clear ( ) ;
to_import . push_back ( * a ) ;
2011-06-01 13:00:29 -04:00
2013-07-23 11:28:45 -04:00
ok = ( import_sndfiles ( to_import , disposition , mode , quality , pos , - 1 , - 1 , track , replace ) = = 0 ) ;
2010-11-25 15:37:39 -05:00
break ;
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
case Editing : : ImportSerializeFiles :
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
to_import . clear ( ) ;
to_import . push_back ( * a ) ;
2010-03-04 18:03:04 -05:00
2013-07-23 11:28:45 -04:00
ok = ( import_sndfiles ( to_import , disposition , mode , quality , pos , 1 , 1 , track , replace ) = = 0 ) ;
2010-11-25 15:37:39 -05:00
break ;
2010-03-04 18:03:04 -05:00
2010-11-25 15:37:39 -05:00
case Editing : : ImportMergeFiles :
// Not entered, handled in earlier if() branch
break ;
}
}
2007-10-11 18:07:47 -04:00
}
2010-09-29 18:59:39 -04:00
2010-09-29 19:02:32 -04:00
if ( ok ) {
_session - > save_state ( " " ) ;
}
2010-09-29 18:59:39 -04:00
import_status . all_done = true ;
2007-10-11 18:07:47 -04:00
}
2007-01-09 18:24:54 -05:00
2007-10-11 18:07:47 -04:00
void
2013-07-23 11:28:45 -04:00
Editor : : do_embed ( vector < string > paths , ImportDisposition import_as , ImportMode mode , framepos_t & pos )
2007-10-11 18:07:47 -04:00
{
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < Track > track ;
2007-10-11 18:07:47 -04:00
bool check_sample_rate = true ;
bool ok = false ;
2010-09-14 11:45:21 -04:00
vector < string > to_embed ;
2007-10-11 18:07:47 -04:00
bool multi = paths . size ( ) > 1 ;
int nth = 0 ;
2011-06-16 11:18:01 -04:00
bool use_timestamp = ( pos = = - 1 ) ;
2007-01-09 18:24:54 -05:00
2013-07-23 11:28:45 -04:00
switch ( import_as ) {
2007-10-11 18:07:47 -04:00
case Editing : : ImportDistinctFiles :
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator a = paths . begin ( ) ; a ! = paths . end ( ) ; + + a ) {
2007-01-09 18:24:54 -05:00
2011-06-16 11:18:01 -04:00
/* have to reset this for every file we handle */
if ( use_timestamp ) {
pos = - 1 ;
}
2007-10-11 18:07:47 -04:00
to_embed . clear ( ) ;
to_embed . push_back ( * a ) ;
2007-01-09 18:24:54 -05:00
2007-10-11 18:07:47 -04:00
if ( mode = = Editing : : ImportToTrack ) {
track = get_nth_selected_audio_track ( nth + + ) ;
}
2007-01-09 18:24:54 -05:00
2013-07-23 11:28:45 -04:00
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , import_as , mode , pos , 1 , - 1 , track ) < - 1 ) {
2007-10-11 18:07:47 -04:00
goto out ;
}
}
break ;
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
case Editing : : ImportDistinctChannels :
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator a = paths . begin ( ) ; a ! = paths . end ( ) ; + + a ) {
2007-01-09 18:24:54 -05:00
2011-06-16 11:18:01 -04:00
/* have to reset this for every file we handle */
if ( use_timestamp ) {
pos = - 1 ;
}
2007-10-11 18:07:47 -04:00
to_embed . clear ( ) ;
to_embed . push_back ( * a ) ;
2013-07-23 11:28:45 -04:00
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , import_as , mode , pos , - 1 , - 1 , track ) < - 1 ) {
2007-10-11 18:07:47 -04:00
goto out ;
2007-01-09 18:24:54 -05:00
}
2007-10-11 18:07:47 -04:00
}
break ;
2007-01-09 18:24:54 -05:00
2007-10-11 18:07:47 -04:00
case Editing : : ImportMergeFiles :
2013-07-23 11:28:45 -04:00
if ( embed_sndfiles ( paths , multi , check_sample_rate , import_as , mode , pos , 1 , 1 , track ) < - 1 ) {
2007-10-11 18:07:47 -04:00
goto out ;
}
2010-11-25 15:37:39 -05:00
break ;
2007-10-11 18:07:47 -04:00
case Editing : : ImportSerializeFiles :
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator a = paths . begin ( ) ; a ! = paths . end ( ) ; + + a ) {
2007-10-11 18:07:47 -04:00
2011-06-16 11:18:01 -04:00
/* have to reset this for every file we handle */
if ( use_timestamp ) {
pos = - 1 ;
}
2007-10-11 18:07:47 -04:00
to_embed . clear ( ) ;
to_embed . push_back ( * a ) ;
2013-07-23 11:28:45 -04:00
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , import_as , mode , pos , 1 , 1 , track ) < - 1 ) {
2007-10-11 18:07:47 -04:00
goto out ;
2007-01-09 18:24:54 -05:00
}
}
2007-10-11 18:07:47 -04:00
break ;
2007-01-09 18:24:54 -05:00
}
2007-10-11 18:07:47 -04:00
ok = true ;
2009-10-14 12:10:01 -04:00
out :
2007-10-11 18:07:47 -04:00
if ( ok ) {
2009-12-17 13:24:23 -05:00
_session - > save_state ( " " ) ;
2006-03-22 17:18:08 -05:00
}
2006-03-22 12:03:00 -05:00
}
2006-03-22 17:18:08 -05:00
int
2013-07-23 11:28:45 -04:00
Editor : : import_sndfiles ( vector < string > paths , ImportDisposition disposition , ImportMode mode , SrcQuality quality , framepos_t & pos ,
2010-04-09 21:35:11 -04:00
int target_regions , int target_tracks , boost : : shared_ptr < Track > & track , bool replace )
2006-03-22 12:03:00 -05:00
{
2007-01-09 18:24:54 -05:00
import_status . paths = paths ;
2006-03-22 12:03:00 -05:00
import_status . done = false ;
import_status . cancel = false ;
import_status . freeze = false ;
2007-10-11 18:07:47 -04:00
import_status . quality = quality ;
2008-02-16 17:43:18 -05:00
import_status . replace_existing_source = replace ;
2008-12-12 09:43:24 -05:00
import_status . mode = mode ;
import_status . pos = pos ;
import_status . target_tracks = target_tracks ;
import_status . target_regions = target_regions ;
import_status . track = track ;
import_status . replace = replace ;
2011-06-01 13:00:29 -04:00
2014-12-20 01:11:28 -05:00
CursorContext : : Handle cursor_ctx = CursorContext : : create ( * this , _cursors - > wait ) ;
2008-12-12 09:43:24 -05:00
gdk_flush ( ) ;
2006-03-22 12:03:00 -05:00
2012-06-09 11:04:11 -04:00
/* start import thread for this spec. this will ultimately call Session::import_files()
2008-12-12 09:43:24 -05:00
which , if successful , will add the files as regions to the region list . its up to us
( the GUI ) to direct additional steps after that .
2006-03-22 12:03:00 -05:00
*/
2008-12-12 09:43:24 -05:00
2009-12-08 22:05:14 -05:00
pthread_create_and_store ( " import " , & import_status . thread , _import_thread , this ) ;
2006-03-22 12:03:00 -05:00
pthread_detach ( import_status . thread ) ;
2009-10-14 12:10:01 -04:00
2008-12-12 09:43:24 -05:00
while ( ! import_status . done & & ! import_status . cancel ) {
2006-03-22 12:03:00 -05:00
gtk_main_iteration ( ) ;
}
2007-03-18 02:07:08 -04:00
2006-03-22 12:03:00 -05:00
import_status . done = true ;
2009-10-14 12:10:01 -04:00
2010-09-29 19:02:32 -04:00
int result = - 1 ;
2008-12-12 09:43:24 -05:00
if ( ! import_status . cancel & & ! import_status . sources . empty ( ) ) {
2010-09-29 19:02:32 -04:00
result = add_sources (
import_status . paths ,
import_status . sources ,
import_status . pos ,
2013-07-23 11:28:45 -04:00
disposition ,
2010-09-29 19:02:32 -04:00
import_status . mode ,
import_status . target_regions ,
import_status . target_tracks ,
track , false
) ;
2009-10-14 12:10:01 -04:00
2008-12-12 09:43:24 -05:00
/* update position from results */
2009-10-14 12:10:01 -04:00
2008-12-12 09:43:24 -05:00
pos = import_status . pos ;
2007-10-11 18:07:47 -04:00
}
2014-12-10 15:44:50 -05:00
import_status . sources . clear ( ) ;
2010-09-29 19:02:32 -04:00
return result ;
2006-03-22 12:03:00 -05:00
}
2006-03-22 17:18:08 -05:00
int
2010-09-14 11:45:21 -04:00
Editor : : embed_sndfiles ( vector < string > paths , bool multifile ,
2013-07-23 11:28:45 -04:00
bool & check_sample_rate , ImportDisposition disposition , ImportMode mode ,
framepos_t & pos , int target_regions , int target_tracks ,
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < Track > & track )
2006-03-22 12:03:00 -05:00
{
2006-08-29 17:21:48 -04:00
boost : : shared_ptr < AudioFileSource > source ;
SourceList sources ;
2006-03-22 12:03:00 -05:00
string linked_path ;
SoundFileInfo finfo ;
2014-12-20 01:11:28 -05:00
CursorContext : : Handle cursor_ctx = CursorContext : : create ( * this , _cursors - > wait ) ;
2014-06-19 09:25:49 -04:00
gdk_flush ( ) ;
2006-03-22 12:03:00 -05:00
2010-09-14 11:45:21 -04:00
for ( vector < string > : : iterator p = paths . begin ( ) ; p ! = paths . end ( ) ; + + p ) {
2006-03-22 12:03:00 -05:00
2010-09-14 11:45:21 -04:00
string path = * p ;
2010-11-09 12:24:17 -05:00
string error_msg ;
2009-10-14 12:10:01 -04:00
2007-01-09 18:24:54 -05:00
/* note that we temporarily truncated _id at the colon */
2009-10-14 12:10:01 -04:00
2007-01-09 18:24:54 -05:00
if ( ! AudioFileSource : : get_soundfile_info ( path , finfo , error_msg ) ) {
2007-10-11 18:07:47 -04:00
error < < string_compose ( _ ( " Editor: cannot open file \" %1 \" , (%2) " ) , path , error_msg ) < < endmsg ;
2014-12-20 01:11:28 -05:00
return - 3 ;
2007-01-09 18:24:54 -05:00
}
2009-10-14 12:10:01 -04:00
2009-12-17 13:24:23 -05:00
if ( check_sample_rate & & ( finfo . samplerate ! = ( int ) _session - > frame_rate ( ) ) ) {
2007-01-09 18:24:54 -05:00
vector < string > choices ;
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
if ( multifile ) {
2007-01-09 18:24:54 -05:00
choices . push_back ( _ ( " Cancel entire import " ) ) ;
choices . push_back ( _ ( " Don't embed it " ) ) ;
choices . push_back ( _ ( " Embed all without questions " ) ) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
Gtkmm2ext : : Choice rate_choice (
2009-12-22 20:26:33 -05:00
_ ( " Sample rate " ) ,
2009-10-14 12:10:01 -04:00
string_compose ( _ ( " %1 \n This audiofile's sample rate doesn't match the session sample rate! " ) ,
2007-03-18 02:07:08 -04:00
short_path ( path , 40 ) ) ,
2009-12-22 20:26:33 -05:00
choices , false
) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
int resx = rate_choice . run ( ) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
switch ( resx ) {
case 0 : /* stop a multi-file import */
2014-12-20 01:11:28 -05:00
return - 2 ;
2007-07-16 18:04:52 -04:00
case 1 : /* don't embed this one */
2014-12-20 01:11:28 -05:00
return - 1 ;
2007-01-28 12:44:13 -05:00
case 2 : /* do it, and the rest without asking */
check_sample_rate = false ;
break ;
case 3 : /* do it */
break ;
default :
2014-12-20 01:11:28 -05:00
return - 2 ;
2007-01-28 12:44:13 -05:00
}
2007-01-09 18:24:54 -05:00
} else {
choices . push_back ( _ ( " Cancel " ) ) ;
2007-01-28 12:44:13 -05:00
choices . push_back ( _ ( " Embed it anyway " ) ) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
Gtkmm2ext : : Choice rate_choice (
2009-12-22 20:26:33 -05:00
_ ( " Sample rate " ) ,
2007-01-28 12:44:13 -05:00
string_compose ( _ ( " %1 \n This audiofile's sample rate doesn't match the session sample rate! " ) , path ) ,
2009-12-22 20:26:33 -05:00
choices , false
) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
int resx = rate_choice . run ( ) ;
2009-10-14 12:10:01 -04:00
2007-01-28 12:44:13 -05:00
switch ( resx ) {
case 0 : /* don't import */
2014-12-20 01:11:28 -05:00
return - 1 ;
2007-01-28 12:44:13 -05:00
case 1 : /* do it */
break ;
default :
2014-12-20 01:11:28 -05:00
return - 2 ;
2007-01-28 12:44:13 -05:00
}
2007-01-09 18:24:54 -05:00
}
2006-08-31 15:17:00 -04:00
}
2009-10-14 12:10:01 -04:00
2007-10-11 18:07:47 -04:00
for ( int n = 0 ; n < finfo . channels ; + + n ) {
2013-07-23 11:28:45 -04:00
2007-01-09 18:24:54 -05:00
try {
2007-03-18 02:07:08 -04:00
/* check if we have this thing embedded already */
boost : : shared_ptr < Source > s ;
2014-05-29 16:27:33 -04:00
if ( ( s = _session - > audio_source_by_path_and_channel ( path , n ) ) = = 0 ) {
2008-03-17 16:54:03 -04:00
2009-02-16 13:08:22 -05:00
source = boost : : dynamic_pointer_cast < AudioFileSource > (
2013-03-30 14:02:26 -04:00
SourceFactory : : createExternal ( DataType : : AUDIO , * _session ,
2013-07-23 11:28:45 -04:00
path , n ,
2009-11-30 08:12:41 -05:00
( mode = = ImportAsTapeTrack
2009-02-16 21:11:49 -05:00
? Source : : Destructive
2009-02-16 13:08:22 -05:00
: Source : : Flag ( 0 ) ) ,
true , true ) ) ;
2007-03-18 02:07:08 -04:00
} else {
source = boost : : dynamic_pointer_cast < AudioFileSource > ( s ) ;
}
2007-01-28 12:44:13 -05:00
2007-01-09 18:24:54 -05:00
sources . push_back ( source ) ;
2009-10-14 12:10:01 -04:00
}
2007-01-09 18:24:54 -05:00
catch ( failed_constructor & err ) {
error < < string_compose ( _ ( " could not open %1 " ) , path ) < < endmsg ;
2014-12-20 01:11:28 -05:00
return - 3 ;
2007-01-09 18:24:54 -05:00
}
2009-10-14 12:10:01 -04:00
2014-02-21 20:44:34 -05:00
gtk_main_iteration ( ) ;
2007-01-09 18:24:54 -05:00
}
}
2014-12-20 01:11:28 -05:00
if ( ! sources . empty ( ) ) {
return add_sources ( paths , sources , pos , disposition , mode , target_regions , target_tracks , track , true ) ;
2006-03-22 12:03:00 -05:00
}
2006-11-19 11:45:16 -05:00
2014-12-20 01:11:28 -05:00
return 0 ;
2007-10-11 18:07:47 -04:00
}
int
2013-07-23 11:28:45 -04:00
Editor : : add_sources ( vector < string > paths , SourceList & sources , framepos_t & pos , ImportDisposition disposition , ImportMode mode ,
2009-07-21 11:55:17 -04:00
int target_regions , int target_tracks , boost : : shared_ptr < Track > & track , bool /*add_channel_suffix*/ )
2007-10-11 18:07:47 -04:00
{
2008-02-18 14:45:52 -05:00
vector < boost : : shared_ptr < Region > > regions ;
2010-09-14 11:45:21 -04:00
string region_name ;
2007-10-11 18:07:47 -04:00
uint32_t input_chan = 0 ;
uint32_t output_chan = 0 ;
2009-10-01 16:40:51 -04:00
bool use_timestamp ;
2014-06-02 11:20:37 -04:00
vector < string > track_names ;
2009-10-01 16:40:51 -04:00
use_timestamp = ( pos = = - 1 ) ;
2007-10-11 18:07:47 -04:00
2008-02-18 22:24:44 -05:00
// kludge (for MIDI we're abusing "channel" for "track" here)
2010-05-19 19:36:18 -04:00
if ( SMFSource : : safe_midi_file_extension ( paths . front ( ) ) ) {
2008-02-18 22:24:44 -05:00
target_regions = - 1 ;
2010-05-19 19:36:18 -04:00
}
2008-02-18 14:45:52 -05:00
2007-10-11 18:07:47 -04:00
if ( target_regions = = 1 ) {
/* take all the sources we have and package them up as a region */
region_name = region_name_from_path ( paths . front ( ) , ( sources . size ( ) > 1 ) , false ) ;
2009-10-14 12:10:01 -04:00
2010-11-25 15:37:39 -05:00
/* we checked in import_sndfiles() that there were not too many */
2010-11-05 16:36:44 -04:00
2010-11-25 15:37:39 -05:00
while ( RegionFactory : : region_by_name ( region_name ) ) {
region_name = bump_name_once ( region_name , ' . ' ) ;
}
2010-11-05 16:36:44 -04:00
2011-06-01 13:00:29 -04:00
PropertyList plist ;
2010-02-18 08:59:49 -05:00
plist . add ( ARDOUR : : Properties : : start , 0 ) ;
plist . add ( ARDOUR : : Properties : : length , sources [ 0 ] - > length ( pos ) ) ;
plist . add ( ARDOUR : : Properties : : name , region_name ) ;
plist . add ( ARDOUR : : Properties : : layer , 0 ) ;
plist . add ( ARDOUR : : Properties : : whole_file , true ) ;
plist . add ( ARDOUR : : Properties : : external , true ) ;
boost : : shared_ptr < Region > r = RegionFactory : : create ( sources , plist ) ;
2009-10-01 16:40:51 -04:00
if ( use_timestamp & & boost : : dynamic_pointer_cast < AudioRegion > ( r ) ) {
boost : : dynamic_pointer_cast < AudioRegion > ( r ) - > special_set_position ( sources [ 0 ] - > natural_position ( ) ) ;
}
2009-10-14 12:10:01 -04:00
2009-10-01 16:40:51 -04:00
regions . push_back ( r ) ;
2014-06-02 11:20:37 -04:00
/* if we're creating a new track, name it after the cleaned-up
* and " merged " region name .
*/
track_names . push_back ( region_name ) ;
2009-10-14 12:10:01 -04:00
2008-12-12 09:43:24 -05:00
} else if ( target_regions = = - 1 | | target_regions > 1 ) {
2007-10-11 18:07:47 -04:00
/* take each source and create a region for each one */
SourceList just_one ;
SourceList : : iterator x ;
uint32_t n ;
for ( n = 0 , x = sources . begin ( ) ; x ! = sources . end ( ) ; + + x , + + n ) {
just_one . clear ( ) ;
just_one . push_back ( * x ) ;
2009-10-14 12:10:01 -04:00
2011-05-13 15:55:52 -04:00
boost : : shared_ptr < FileSource > fs = boost : : dynamic_pointer_cast < FileSource > ( * x ) ;
2013-07-23 11:28:45 -04:00
if ( sources . size ( ) > 1 & & disposition = = ImportDistinctChannels ) {
/* generate a per-channel region name so that things work as
* intended
*/
string path ;
if ( fs ) {
region_name = basename_nosuffix ( fs - > path ( ) ) ;
} else {
region_name = ( * x ) - > name ( ) ;
}
2014-06-02 11:20:37 -04:00
if ( sources . size ( ) = = 2 ) {
2013-07-23 11:28:45 -04:00
if ( n = = 0 ) {
region_name + = " -L " ;
} else {
region_name + = " -R " ;
}
2014-06-02 11:20:37 -04:00
} else if ( sources . size ( ) > 2 ) {
region_name + = string_compose ( " -%1 " , n + 1 ) ;
2013-07-23 11:28:45 -04:00
}
2014-06-02 11:20:37 -04:00
track_names . push_back ( region_name ) ;
2013-07-23 11:28:45 -04:00
} else {
if ( fs ) {
region_name = region_name_from_path ( fs - > path ( ) , false , false , sources . size ( ) , n ) ;
2014-06-02 11:20:37 -04:00
} else {
2013-07-23 11:28:45 -04:00
region_name = ( * x ) - > name ( ) ;
}
2014-06-02 11:20:37 -04:00
2014-09-13 10:34:01 -04:00
if ( SMFSource : : safe_midi_file_extension ( paths . front ( ) ) ) {
2014-09-13 13:57:04 -04:00
string track_name = string_compose ( " %1-t%2 " , PBD : : basename_nosuffix ( fs - > path ( ) ) , ( n + 1 ) ) ;
2014-09-13 10:34:01 -04:00
track_names . push_back ( track_name ) ;
} else {
track_names . push_back ( PBD : : basename_nosuffix ( paths [ n ] ) ) ;
}
2011-05-13 15:55:52 -04:00
}
2007-10-11 18:07:47 -04:00
2011-04-21 11:19:22 -04:00
PropertyList plist ;
2011-05-17 19:07:46 -04:00
/* Fudge region length to ensure it is non-zero; make it 1 beat at 120bpm
for want of a better idea . It can ' t be too small , otherwise if this
is a MIDI region the conversion from frames - > beats - > frames will
round it back down to 0 again .
*/
2011-04-21 11:19:22 -04:00
framecnt_t len = ( * x ) - > length ( pos ) ;
if ( len = = 0 ) {
2012-06-09 11:04:18 -04:00
len = ( 60.0 / 120.0 ) * _session - > frame_rate ( ) ;
2011-04-21 11:19:22 -04:00
}
2011-06-01 13:00:29 -04:00
2010-02-18 08:59:49 -05:00
plist . add ( ARDOUR : : Properties : : start , 0 ) ;
2011-04-21 11:19:22 -04:00
plist . add ( ARDOUR : : Properties : : length , len ) ;
2010-02-18 08:59:49 -05:00
plist . add ( ARDOUR : : Properties : : name , region_name ) ;
plist . add ( ARDOUR : : Properties : : layer , 0 ) ;
plist . add ( ARDOUR : : Properties : : whole_file , true ) ;
plist . add ( ARDOUR : : Properties : : external , true ) ;
boost : : shared_ptr < Region > r = RegionFactory : : create ( just_one , plist ) ;
2009-10-14 12:10:01 -04:00
2009-10-01 16:40:51 -04:00
if ( use_timestamp & & boost : : dynamic_pointer_cast < AudioRegion > ( r ) ) {
boost : : dynamic_pointer_cast < AudioRegion > ( r ) - > special_set_position ( ( * x ) - > natural_position ( ) ) ;
}
2009-10-14 12:10:01 -04:00
2009-10-01 16:40:51 -04:00
regions . push_back ( r ) ;
2007-10-11 18:07:47 -04:00
}
}
if ( target_regions = = 1 ) {
input_chan = regions . front ( ) - > n_channels ( ) ;
} else {
if ( target_tracks = = 1 ) {
input_chan = regions . size ( ) ;
} else {
input_chan = 1 ;
}
}
2007-01-28 12:44:13 -05:00
2006-10-21 15:01:50 -04:00
if ( Config - > get_output_auto_connect ( ) & AutoConnectMaster ) {
2009-12-17 13:24:23 -05:00
output_chan = ( _session - > master_out ( ) ? _session - > master_out ( ) - > n_inputs ( ) . n_audio ( ) : input_chan ) ;
2006-03-22 12:03:00 -05:00
} else {
output_chan = input_chan ;
}
2007-01-09 18:24:54 -05:00
2007-10-11 18:07:47 -04:00
int n = 0 ;
2010-11-25 15:37:39 -05:00
framepos_t rlen = 0 ;
2007-10-11 18:07:47 -04:00
2012-06-09 11:04:24 -04:00
begin_reversible_command ( Operations : : insert_file ) ;
2014-06-02 11:20:37 -04:00
/* we only use tracks names when importing to new tracks, but we
* require that one is defined for every region , just to keep
* the API simpler .
*/
assert ( regions . size ( ) = = track_names . size ( ) ) ;
2012-06-09 11:04:24 -04:00
2011-06-01 13:00:29 -04:00
for ( vector < boost : : shared_ptr < Region > > : : iterator r = regions . begin ( ) ; r ! = regions . end ( ) ; + + r , + + n ) {
2010-11-25 15:37:39 -05:00
boost : : shared_ptr < AudioRegion > ar = boost : : dynamic_pointer_cast < AudioRegion > ( * r ) ;
2011-06-01 13:00:29 -04:00
2010-12-07 09:45:51 -05:00
if ( use_timestamp ) {
if ( ar ) {
2011-06-01 13:00:29 -04:00
2010-12-07 09:45:51 -05:00
/* get timestamp for this region */
2011-06-01 13:00:29 -04:00
2010-12-07 09:45:51 -05:00
const boost : : shared_ptr < Source > s ( ar - > sources ( ) . front ( ) ) ;
const boost : : shared_ptr < AudioSource > as = boost : : dynamic_pointer_cast < AudioSource > ( s ) ;
2011-06-01 13:00:29 -04:00
2010-12-07 09:45:51 -05:00
assert ( as ) ;
2011-06-01 13:00:29 -04:00
2010-12-07 09:45:51 -05:00
if ( as - > natural_position ( ) ! = 0 ) {
pos = as - > natural_position ( ) ;
} else if ( target_tracks = = 1 ) {
/* hmm, no timestamp available, put it after the previous region
*/
if ( n = = 0 ) {
pos = get_preferred_edit_position ( ) ;
} else {
pos + = rlen ;
}
} else {
pos = get_preferred_edit_position ( ) ;
}
} else {
/* should really get first position in MIDI file, but for now, use edit position*/
pos = get_preferred_edit_position ( ) ;
}
}
2014-06-02 11:20:37 -04:00
finish_bringing_in_material ( * r , input_chan , output_chan , pos , mode , track , track_names [ n ] ) ;
2006-03-22 12:03:00 -05:00
2010-11-25 15:37:39 -05:00
rlen = ( * r ) - > length ( ) ;
2011-06-01 13:00:29 -04:00
2010-11-25 15:37:39 -05:00
if ( target_tracks ! = 1 ) {
track . reset ( ) ;
2011-06-01 13:00:29 -04:00
} else {
2010-11-25 15:37:39 -05:00
if ( ! use_timestamp | | ! ar ) {
/* line each one up right after the other */
pos + = ( * r ) - > length ( ) ;
}
}
2007-10-11 18:07:47 -04:00
}
2012-06-09 11:04:24 -04:00
commit_reversible_command ( ) ;
2007-10-11 18:07:47 -04:00
/* setup peak file building in another thread */
for ( SourceList : : iterator x = sources . begin ( ) ; x ! = sources . end ( ) ; + + x ) {
SourceFactory : : setup_peakfile ( * x , true ) ;
}
return 0 ;
}
2009-10-14 12:10:01 -04:00
2006-03-22 12:03:00 -05:00
int
2010-09-17 14:20:37 -04:00
Editor : : finish_bringing_in_material ( boost : : shared_ptr < Region > region , uint32_t in_chans , uint32_t out_chans , framepos_t & pos ,
2014-06-02 11:20:37 -04:00
ImportMode mode , boost : : shared_ptr < Track > & existing_track , const string & new_track_name )
2006-07-27 21:08:57 -04:00
{
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < AudioRegion > ar = boost : : dynamic_pointer_cast < AudioRegion > ( region ) ;
boost : : shared_ptr < MidiRegion > mr = boost : : dynamic_pointer_cast < MidiRegion > ( region ) ;
2006-07-27 21:08:57 -04:00
switch ( mode ) {
case ImportAsRegion :
/* relax, its been done */
break ;
2009-10-14 12:10:01 -04:00
2006-03-22 12:03:00 -05:00
case ImportToTrack :
2007-10-11 18:07:47 -04:00
{
if ( ! existing_track ) {
2008-02-18 14:45:52 -05:00
if ( ar ) {
existing_track = get_nth_selected_audio_track ( 0 ) ;
} else if ( mr ) {
existing_track = get_nth_selected_midi_track ( 0 ) ;
}
2006-03-22 12:03:00 -05:00
2007-10-11 18:07:47 -04:00
if ( ! existing_track ) {
return - 1 ;
}
2006-03-22 12:03:00 -05:00
}
2007-10-11 18:07:47 -04:00
2010-04-21 16:42:22 -04:00
boost : : shared_ptr < Playlist > playlist = existing_track - > playlist ( ) ;
2010-03-01 19:00:00 -05:00
boost : : shared_ptr < Region > copy ( RegionFactory : : create ( region , region - > properties ( ) ) ) ;
2011-01-20 19:58:45 -05:00
playlist - > clear_changes ( ) ;
2007-10-11 18:07:47 -04:00
playlist - > add_region ( copy , pos ) ;
Ripple mode: basic implementation
Add a value for Ripple to EditMode enum.
Add Ripple edit mode to edit mode dropdown, by adding it to the
Editor::build_edit_mode_menu() helper function, and remove the old code that
added items to the (now unused) Editor::edit_mode_strings.
Add the regions that should be affected by the drag to RegionDrag::_views so
that the drag carries them along automatically.
Use a copy of the RegionList in Playlist::core_ripple(), since bad things
happen when iterating over regions and they get moved around in the list.
Handle rippling in removal of regions from playlist.
When dragging in ripple mode, exclude all regions that lie before the
original start position of the selected regions being dragged from
rippling: this is what Mixbus does.
Make editor dragging respect snap-to settings, by using the existing
compute_x_delta() function, which did almost the right thing. Move setting
of _last_frame_position out of that function so all ripple-dragged regions
can move.
Ripple when dragging from region list: even though Mixbus doesn't do this, it
seems like a good idea.
Prevent multi-track selection being dragged across tracks, by making
RegionMotionDrag::y_movement_allowed() virtual, and overriding it in
RegionRippleDrag to forbid dragging of selections containing regions on more
than one track to dofferent tracks in ripple mode.
Remember which TimeAxisView a ripple-mode drag that's allowed cross-track
drags started from, so that the effect of rippling regions after any region
that's dragged off that track can be undone.
2013-10-23 16:50:01 -04:00
if ( Config - > get_edit_mode ( ) = = Ripple )
playlist - > ripple ( pos , copy - > length ( ) , copy ) ;
2010-03-02 13:05:26 -05:00
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
2006-03-22 12:03:00 -05:00
break ;
2007-10-11 18:07:47 -04:00
}
2006-03-22 12:03:00 -05:00
case ImportAsTrack :
2009-10-14 12:10:01 -04:00
{
2007-10-11 18:07:47 -04:00
if ( ! existing_track ) {
2008-02-18 14:45:52 -05:00
if ( ar ) {
2009-12-17 13:24:23 -05:00
list < boost : : shared_ptr < AudioTrack > > at ( _session - > new_audio_track ( in_chans , out_chans , Normal , 0 , 1 ) ) ;
2007-10-11 18:07:47 -04:00
2008-02-18 14:45:52 -05:00
if ( at . empty ( ) ) {
return - 1 ;
}
existing_track = at . front ( ) ;
} else if ( mr ) {
2012-06-21 21:45:16 -04:00
list < boost : : shared_ptr < MidiTrack > > mt ( _session - > new_midi_track ( ChanCount ( DataType : : MIDI , 1 ) ,
ChanCount ( DataType : : MIDI , 1 ) ,
boost : : shared_ptr < PluginInfo > ( ) ,
Normal , 0 , 1 ) ) ;
2008-02-18 14:45:52 -05:00
if ( mt . empty ( ) ) {
return - 1 ;
}
existing_track = mt . front ( ) ;
2007-10-11 18:07:47 -04:00
}
2011-06-01 13:00:29 -04:00
2014-06-02 11:20:37 -04:00
if ( ! new_track_name . empty ( ) ) {
existing_track - > set_name ( new_track_name ) ;
} else {
existing_track - > set_name ( region - > name ( ) ) ;
}
2006-08-24 03:37:17 -04:00
}
2007-10-11 18:07:47 -04:00
2011-01-20 19:58:45 -05:00
boost : : shared_ptr < Playlist > playlist = existing_track - > playlist ( ) ;
2012-06-09 09:36:02 -04:00
boost : : shared_ptr < Region > copy ( RegionFactory : : create ( region , true ) ) ;
2011-01-20 19:58:45 -05:00
playlist - > clear_changes ( ) ;
playlist - > add_region ( copy , pos ) ;
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
2006-03-22 12:03:00 -05:00
break ;
}
2006-07-27 21:08:57 -04:00
case ImportAsTapeTrack :
{
2011-01-20 19:58:45 -05:00
if ( ! ar ) {
2008-02-18 14:45:52 -05:00
return - 1 ;
2011-01-20 19:58:45 -05:00
}
2008-02-18 14:45:52 -05:00
2009-12-17 13:24:23 -05:00
list < boost : : shared_ptr < AudioTrack > > at ( _session - > new_audio_track ( in_chans , out_chans , Destructive ) ) ;
2006-08-24 03:37:17 -04:00
if ( ! at . empty ( ) ) {
2011-01-20 19:58:45 -05:00
boost : : shared_ptr < Playlist > playlist = at . front ( ) - > playlist ( ) ;
2012-06-09 09:36:02 -04:00
boost : : shared_ptr < Region > copy ( RegionFactory : : create ( region , true ) ) ;
2011-01-20 19:58:45 -05:00
playlist - > clear_changes ( ) ;
playlist - > add_region ( copy , pos ) ;
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
2006-08-24 03:37:17 -04:00
}
2006-07-27 21:08:57 -04:00
break ;
}
}
2006-03-22 12:03:00 -05:00
return 0 ;
}
void *
Editor : : _import_thread ( void * arg )
{
2009-12-04 14:24:09 -05:00
SessionEvent : : create_per_thread_pool ( " import events " , 64 ) ;
2006-03-22 12:03:00 -05:00
Editor * ed = ( Editor * ) arg ;
return ed - > import_thread ( ) ;
}
void *
Editor : : import_thread ( )
{
2012-06-09 11:04:11 -04:00
_session - > import_files ( import_status ) ;
2006-03-22 12:03:00 -05:00
return 0 ;
}