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/session.h"
# include "ardour/session_directory.h"
# include "ardour/audioplaylist.h"
# include "ardour/audioregion.h"
# include "ardour/audio_diskstream.h"
# include "ardour/midi_track.h"
# include "ardour/midi_region.h"
# include "ardour/utils.h"
# include "ardour/audio_track.h"
# include "ardour/audioplaylist.h"
# include "ardour/audiofilesource.h"
# include "ardour/region_factory.h"
# include "ardour/source_factory.h"
# include "ardour/session.h"
2010-05-19 19:36:18 -04:00
# include "ardour/smf_source.h"
2011-01-19 12:38:56 -05:00
# include "ardour/operations.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"
# 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"
2007-03-18 02:07:08 -04:00
# include "utils.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 ;
}
2009-12-17 13:24:23 -05:00
2007-10-11 18:07:47 -04:00
if ( sfbrowser = = 0 ) {
2009-12-17 13:24:23 -05:00
sfbrowser = new SoundFileOmega ( * this , _ ( " 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 ;
2007-10-11 18:07:47 -04:00
uint32_t track_cnt ;
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
2007-10-11 18:07:47 -04:00
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
2007-10-11 18:07:47 -04:00
if ( ! atv ) {
continue ;
} else if ( atv - > is_audio_track ( ) ) {
track_cnt + + ;
}
}
if ( sfbrowser = = 0 ) {
2009-12-17 13:24:23 -05:00
sfbrowser = new SoundFileOmega ( * this , _ ( " Add Existing Media " ) , _session , track_cnt , true ) ;
2007-10-11 18:07:47 -04:00
} else {
sfbrowser - > reset ( track_cnt ) ;
}
sfbrowser - > show_all ( ) ;
2006-03-22 12:03:00 -05:00
2008-02-16 17:43:18 -05:00
bool keepRunning ;
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
do {
keepRunning = false ;
2006-03-22 12:03:00 -05:00
2008-02-16 17:43:18 -05:00
int response = sfbrowser - > run ( ) ;
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
switch ( response ) {
case RESPONSE_APPLY :
// leave the dialog open
break ;
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
case RESPONSE_OK :
sfbrowser - > hide ( ) ;
break ;
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
default :
// cancel from the browser - we are done
sfbrowser - > hide ( ) ;
return ;
}
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
/* lets do it */
2010-09-14 12:51:02 -04:00
vector < string > upaths = sfbrowser - > get_paths ( ) ;
for ( vector < string > : : iterator x = upaths . begin ( ) ; x ! = upaths . end ( ) ; + + x ) {
2010-09-14 11:45:21 -04:00
paths . push_back ( * x ) ;
}
2008-02-16 17:43:18 -05:00
ImportPosition pos = sfbrowser - > get_position ( ) ;
ImportMode mode = sfbrowser - > get_mode ( ) ;
ImportDisposition chns = sfbrowser - > get_channel_disposition ( ) ;
2010-09-17 14:20:37 -04:00
framepos_t where ;
2008-02-16 17:43:18 -05:00
switch ( pos ) {
case ImportAtEditPoint :
where = get_preferred_edit_position ( ) ;
break ;
case ImportAtTimestamp :
where = - 1 ;
break ;
case ImportAtPlayhead :
where = playhead_cursor - > current_frame ;
break ;
case ImportAtStart :
2009-12-17 13:24:23 -05:00
where = _session - > current_start_frame ( ) ;
2008-02-16 17:43:18 -05:00
break ;
}
2007-10-11 18:07:47 -04:00
2008-02-16 17:43:18 -05:00
SrcQuality quality = sfbrowser - > get_src_quality ( ) ;
if ( sfbrowser - > copy_files_btn . get_active ( ) ) {
do_import ( paths , chns , mode , quality , where ) ;
} else {
do_embed ( paths , chns , mode , where ) ;
}
if ( response = = RESPONSE_APPLY ) {
sfbrowser - > clear_selection ( ) ;
keepRunning = true ;
}
} while ( keepRunning ) ;
}
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 ;
/**
* Updating is still disabled , see note in libs / ardour / import . cc Session : : import_audiofiles ( )
*
* 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 ) ) ;
2009-12-17 13:24:23 -05:00
SourceMap all_sources = _session - > get_sources ( ) ;
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
2010-09-17 14:20:37 -04:00
Editor : : do_import ( vector < string > paths , ImportDisposition chns , 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 ;
2008-02-16 17:43:18 -05:00
if ( chns = = 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 ( ) ;
2010-09-29 19:02:32 -04:00
ok = ( import_sndfiles ( paths , 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 ) ;
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 ;
/* NOTREACHED*/
break ;
case 1 :
replace = false ;
break ;
default :
fatal < < " Illegal return " < < check < < " from check_whether_and_how_to_import()! " < < endmsg ;
/* 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 */
2010-08-12 15:43:36 -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 ( ) ;
2010-11-05 16:36:44 -04:00
2010-11-25 15:37:39 -05:00
switch ( chns ) {
case Editing : : ImportDistinctFiles :
2010-03-04 18:03:04 -05: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
2010-11-25 15:37:39 -05:00
if ( mode = = Editing : : ImportToTrack ) {
track = get_nth_selected_audio_track ( nth + + ) ;
}
2010-03-04 18:03:04 -05:00
2010-11-25 15:37:39 -05:00
ok = ( import_sndfiles ( to_import , mode , quality , pos , 1 , - 1 , track , replace ) = = 0 ) ;
break ;
2010-03-04 18:03:04 -05:00
2010-11-25 15:37:39 -05:00
case Editing : : ImportDistinctChannels :
2010-03-04 18:03:04 -05: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
2010-11-25 15:37:39 -05:00
ok = ( import_sndfiles ( to_import , mode , quality , pos , - 1 , - 1 , track , replace ) = = 0 ) ;
break ;
2010-03-04 18:03:04 -05:00
2010-11-25 15:37:39 -05:00
case Editing : : ImportSerializeFiles :
2010-03-04 18:03:04 -05: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
2010-11-25 15:37:39 -05:00
ok = ( import_sndfiles ( to_import , mode , quality , pos , 1 , 1 , track , replace ) = = 0 ) ;
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
2010-09-17 14:20:37 -04:00
Editor : : do_embed ( vector < string > paths , ImportDisposition chns , 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 ;
2007-01-09 18:24:54 -05:00
2007-10-11 18:07:47 -04:00
switch ( chns ) {
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
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
2007-10-11 18:07:47 -04:00
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , mode , pos , 1 , - 1 , track ) < - 1 ) {
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
2007-10-11 18:07:47 -04:00
to_embed . clear ( ) ;
to_embed . push_back ( * a ) ;
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , mode , pos , - 1 , - 1 , track ) < - 1 ) {
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 :
if ( embed_sndfiles ( paths , multi , check_sample_rate , mode , pos , 1 , 1 , track ) < - 1 ) {
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
to_embed . clear ( ) ;
to_embed . push_back ( * a ) ;
if ( embed_sndfiles ( to_embed , multi , check_sample_rate , mode , pos , 1 , 1 , track ) < - 1 ) {
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
2010-09-17 14:20:37 -04:00
Editor : : import_sndfiles ( vector < string > paths , 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 ;
2010-09-22 11:21:06 -04:00
2010-11-16 09:53:16 -05:00
set_canvas_cursor ( _cursors - > wait ) ;
2008-12-12 09:43:24 -05:00
gdk_flush ( ) ;
2006-03-22 12:03:00 -05:00
2007-11-14 21:32:35 -05:00
/* start import thread for this spec. this will ultimately call Session::import_audiofiles()
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 ,
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
}
2010-09-22 11:21:06 -04:00
set_canvas_cursor ( current_canvas_cursor ) ;
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 ,
2010-09-17 14:20:37 -04:00
bool & check_sample_rate , 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 ;
2007-01-28 12:44:13 -05:00
int ret = 0 ;
2006-03-22 12:03:00 -05:00
2010-11-16 09:53:16 -05:00
set_canvas_cursor ( _cursors - > wait ) ;
2008-12-12 09:43:24 -05: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 ;
2007-01-28 12:44:13 -05:00
goto out ;
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 */
2007-07-16 18:04:52 -04:00
ret = - 2 ;
goto out ;
case 1 : /* don't embed this one */
2007-01-28 12:44:13 -05:00
ret = - 1 ;
goto out ;
case 2 : /* do it, and the rest without asking */
check_sample_rate = false ;
break ;
case 3 : /* do it */
break ;
default :
ret = - 2 ;
goto out ;
}
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 */
ret = - 1 ;
goto out ;
case 1 : /* do it */
break ;
default :
ret = - 2 ;
goto out ;
}
2007-01-09 18:24:54 -05:00
}
2006-08-31 15:17:00 -04:00
}
2009-10-14 12:10:01 -04:00
2010-11-16 09:53:16 -05:00
set_canvas_cursor ( _cursors - > wait ) ;
2007-01-28 12:44:13 -05:00
2007-10-11 18:07:47 -04:00
for ( int n = 0 ; n < finfo . channels ; + + n ) {
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 ;
2009-12-17 13:24:23 -05:00
if ( ( s = _session - > 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 > (
2009-12-17 13:24:23 -05:00
SourceFactory : : createReadable ( DataType : : AUDIO , * _session ,
2010-11-09 12:24:17 -05: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 ;
goto out ;
}
2009-10-14 12:10:01 -04:00
2007-01-09 18:24:54 -05:00
ARDOUR_UI : : instance ( ) - > flush_pending ( ) ;
}
}
2006-03-22 12:03:00 -05:00
if ( sources . empty ( ) ) {
goto out ;
}
2006-11-19 11:45:16 -05:00
2007-10-11 18:07:47 -04:00
ret = add_sources ( paths , sources , pos , mode , target_regions , target_tracks , track , true ) ;
2006-11-19 11:45:16 -05:00
2007-10-11 18:07:47 -04:00
out :
2010-09-22 11:21:06 -04:00
set_canvas_cursor ( current_canvas_cursor ) ;
2007-10-11 18:07:47 -04:00
return ret ;
}
int
2010-09-17 14:20:37 -04:00
Editor : : add_sources ( vector < string > paths , SourceList & sources , framepos_t & pos , 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 ;
2009-10-14 12:10:01 -04:00
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
2010-02-18 08:59:49 -05:00
PropertyList plist ;
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 ) ;
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
2008-05-15 23:21:18 -04:00
region_name = region_name_from_path ( ( * x ) - > path ( ) , false , false , sources . size ( ) , n ) ;
2007-10-11 18:07:47 -04:00
2010-02-18 08:59:49 -05:00
PropertyList plist ;
plist . add ( ARDOUR : : Properties : : start , 0 ) ;
plist . add ( ARDOUR : : Properties : : length , ( * x ) - > 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 ( 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
2010-11-25 15:37:39 -05:00
for ( vector < boost : : shared_ptr < Region > > : : iterator r = regions . begin ( ) ; r ! = regions . end ( ) ; + + r , + + n ) {
boost : : shared_ptr < AudioRegion > ar = boost : : dynamic_pointer_cast < AudioRegion > ( * r ) ;
2010-08-12 15:43:36 -04:00
2010-12-07 09:45:51 -05:00
if ( use_timestamp ) {
if ( ar ) {
2010-08-12 15:43:36 -04:00
2010-12-07 09:45:51 -05:00
/* get timestamp for this region */
2010-08-12 15:43:36 -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 ) ;
assert ( as ) ;
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 ( ) ;
}
}
2007-10-11 18:07:47 -04:00
2008-02-18 14:45:52 -05:00
finish_bringing_in_material ( * r , input_chan , output_chan , pos , mode , track ) ;
2006-03-22 12:03:00 -05:00
2010-11-25 15:37:39 -05:00
rlen = ( * r ) - > length ( ) ;
2010-08-12 15:43:36 -04:00
2010-11-25 15:37:39 -05:00
if ( target_tracks ! = 1 ) {
track . reset ( ) ;
} else {
if ( ! use_timestamp | | ! ar ) {
/* line each one up right after the other */
pos + = ( * r ) - > length ( ) ;
}
}
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 ,
2008-02-18 14:45:52 -05:00
ImportMode mode , boost : : shared_ptr < Track > & existing_track )
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-19 12:38:56 -05:00
begin_reversible_command ( Operations : : insert_file ) ;
2011-01-20 19:58:45 -05:00
playlist - > clear_changes ( ) ;
2007-10-11 18:07:47 -04:00
playlist - > add_region ( copy , pos ) ;
2010-03-02 13:05:26 -05:00
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
2007-10-11 18:07:47 -04:00
commit_reversible_command ( ) ;
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 ) {
2009-12-17 13:24:23 -05:00
list < boost : : shared_ptr < MidiTrack > > mt ( _session - > new_midi_track ( 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
}
2010-11-05 16:36:44 -04:00
2007-10-11 18:07:47 -04:00
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 ( ) ;
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < Region > copy ( RegionFactory : : create ( region ) ) ;
2011-01-20 19:58:45 -05:00
begin_reversible_command ( Operations : : insert_file ) ;
playlist - > clear_changes ( ) ;
playlist - > add_region ( copy , pos ) ;
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
commit_reversible_command ( ) ;
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 ( ) ;
2008-02-18 14:45:52 -05:00
boost : : shared_ptr < Region > copy ( RegionFactory : : create ( region ) ) ;
2011-01-20 19:58:45 -05:00
begin_reversible_command ( Operations : : insert_file ) ;
playlist - > clear_changes ( ) ;
playlist - > add_region ( copy , pos ) ;
_session - > add_command ( new StatefulDiffCommand ( playlist ) ) ;
commit_reversible_command ( ) ;
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 ( )
{
2009-12-17 13:24:23 -05:00
_session - > import_audiofiles ( import_status ) ;
2006-03-22 12:03:00 -05:00
pthread_exit_pbd ( 0 ) ;
/*NOTREACHED*/
return 0 ;
}