return to the old way of editing track names, but hopefully better than it was. likel...
[ardour.git] / gtk2_ardour / editor_audio_import.cc
index e21d2efe3e7095382683969cffb09dcb8b80197a..3a120c709fd2445c3c0936dc7bc2d928ad550339 100644 (file)
 
 #include <gtkmm2ext/choice.h>
 
-#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/audioregion.h"
+#include "ardour/midi_region.h"
+#include "ardour/midi_track.h"
+#include "ardour/operations.h"
 #include "ardour/region_factory.h"
-#include "ardour/source_factory.h"
-#include "ardour/session.h"
 #include "ardour/smf_source.h"
-#include "ardour/operations.h"
+#include "ardour/source_factory.h"
+#include "ardour/utils.h"
 #include "pbd/memento_command.h"
 
 #include "ardour_ui.h"
@@ -86,7 +80,7 @@ Editor::add_external_audio_action (ImportMode mode_hint)
        }
 
        if (sfbrowser == 0) {
-               sfbrowser = new SoundFileOmega (*this, _("Add Existing Media"), _session, 0, true, mode_hint);
+               sfbrowser = new SoundFileOmega (_("Add Existing Media"), _session, 0, true, mode_hint);
        } else {
                sfbrowser->set_mode (mode_hint);
        }
@@ -98,7 +92,8 @@ void
 Editor::external_audio_dialog ()
 {
        vector<string> paths;
-       uint32_t track_cnt;
+       uint32_t audio_track_cnt;
+       uint32_t midi_track_cnt;
 
        if (_session == 0) {
                MessageDialog msg (_("You can't import or embed an audiofile until you have a session loaded."));
@@ -106,91 +101,35 @@ Editor::external_audio_dialog ()
                return;
        }
 
-       track_cnt = 0;
+       audio_track_cnt = 0;
+       midi_track_cnt = 0;
 
        for (TrackSelection::iterator x = selection->tracks.begin(); x != selection->tracks.end(); ++x) {
                AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*>(*x);
 
-               if (!atv) {
-                       continue;
-               } else if (atv->is_audio_track()) {
-                       track_cnt++;
+               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++;
+                               }
+                       }
                }
        }
 
        if (sfbrowser == 0) {
-               sfbrowser = new SoundFileOmega (*this, _("Add Existing Media"), _session, track_cnt, true);
+               sfbrowser = new SoundFileOmega (_("Add Existing Media"), _session, audio_track_cnt, midi_track_cnt, true);
        } else {
-               sfbrowser->reset (track_cnt);
+               sfbrowser->reset (audio_track_cnt, midi_track_cnt);
        }
 
        sfbrowser->show_all ();
-
-
-       bool keepRunning;
-
-       do {
-               keepRunning = false;
-
-               int response = sfbrowser->run ();
-
-               switch (response) {
-                       case RESPONSE_APPLY:
-                               // leave the dialog open
-                               break;
-
-                       case RESPONSE_OK:
-                               sfbrowser->hide ();
-                               break;
-
-                       default:
-                               // cancel from the browser - we are done
-                               sfbrowser->hide ();
-                               return;
-               }
-
-               /* lets do it */
-
-               vector<string> upaths = sfbrowser->get_paths ();
-                for (vector<string>::iterator x = upaths.begin(); x != upaths.end(); ++x) {
-                        paths.push_back (*x);
-                }
-
-               ImportPosition pos = sfbrowser->get_position ();
-               ImportMode mode = sfbrowser->get_mode ();
-               ImportDisposition chns = sfbrowser->get_channel_disposition ();
-               framepos_t where;
-
-               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:
-                               where = _session->current_start_frame();
-                               break;
-               }
-
-               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);
 }
 
 void
@@ -204,7 +143,7 @@ Editor::session_import_dialog ()
 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()
+ * Updating is still disabled, see note in libs/ardour/import.cc Session::import_files()
  *
  * all_or_nothing:
  *   true  = show "Update", "Import" and "Skip"
@@ -447,11 +386,17 @@ Editor::do_embed (vector<string> paths, ImportDisposition chns, ImportMode mode,
        vector<string> to_embed;
        bool multi = paths.size() > 1;
        int nth = 0;
+       bool use_timestamp = (pos == -1);
 
        switch (chns) {
        case Editing::ImportDistinctFiles:
                for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
 
+                       /* have to reset this for every file we handle */
+                       if (use_timestamp) {
+                               pos = -1;
+                       }
+
                        to_embed.clear ();
                        to_embed.push_back (*a);
 
@@ -468,6 +413,11 @@ Editor::do_embed (vector<string> paths, ImportDisposition chns, ImportMode mode,
        case Editing::ImportDistinctChannels:
                for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
 
+                       /* have to reset this for every file we handle */
+                       if (use_timestamp) {
+                               pos = -1;
+                       }
+
                        to_embed.clear ();
                        to_embed.push_back (*a);
 
@@ -486,6 +436,11 @@ Editor::do_embed (vector<string> paths, ImportDisposition chns, ImportMode mode,
        case Editing::ImportSerializeFiles:
                for (vector<string>::iterator a = paths.begin(); a != paths.end(); ++a) {
 
+                       /* have to reset this for every file we handle */
+                       if (use_timestamp) {
+                               pos = -1;
+                       }
+
                        to_embed.clear ();
                        to_embed.push_back (*a);
 
@@ -525,7 +480,7 @@ Editor::import_sndfiles (vector<string> paths, ImportMode mode, SrcQuality quali
        set_canvas_cursor (_cursors->wait);
        gdk_flush ();
 
-       /* start import thread for this spec. this will ultimately call Session::import_audiofiles()
+       /* start import thread for this spec. this will ultimately call Session::import_files()
           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.
        */
@@ -767,7 +722,7 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
                        */
                        framecnt_t len = (*x)->length (pos);
                        if (len == 0) {
-                               len = (60 / 120) * _session->frame_rate ();
+                               len = (60.0 / 120.0) * _session->frame_rate ();
                        }
 
                        plist.add (ARDOUR::Properties::start, 0);
@@ -806,6 +761,8 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
        int n = 0;
        framepos_t rlen = 0;
 
+       begin_reversible_command (Operations::insert_file);
+       
        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);
 
@@ -853,6 +810,8 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
                }
        }
 
+       commit_reversible_command ();
+       
        /* setup peak file building in another thread */
 
        for (SourceList::iterator x = sources.begin(); x != sources.end(); ++x) {
@@ -864,7 +823,7 @@ Editor::add_sources (vector<string> paths, SourceList& sources, framepos_t& pos,
 
 int
 Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t in_chans, uint32_t out_chans, framepos_t& pos,
-                                 ImportMode mode, boost::shared_ptr<Track>& existing_track)
+                                    ImportMode mode, boost::shared_ptr<Track>& existing_track)
 {
        boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion>(region);
        boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(region);
@@ -891,11 +850,9 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
 
                boost::shared_ptr<Playlist> playlist = existing_track->playlist();
                boost::shared_ptr<Region> copy (RegionFactory::create (region, region->properties()));
-               begin_reversible_command (Operations::insert_file);
                playlist->clear_changes ();
                playlist->add_region (copy, pos);
                _session->add_command (new StatefulDiffCommand (playlist));
-               commit_reversible_command ();
                break;
        }
 
@@ -911,7 +868,10 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
 
                                existing_track = at.front();
                        } else if (mr) {
-                               list<boost::shared_ptr<MidiTrack> > mt (_session->new_midi_track (Normal, 0, 1));
+                               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));
 
                                if (mt.empty()) {
                                        return -1;
@@ -924,12 +884,10 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
                }
 
                boost::shared_ptr<Playlist> playlist = existing_track->playlist();
-               boost::shared_ptr<Region> copy (RegionFactory::create (region));
-               begin_reversible_command (Operations::insert_file);
+               boost::shared_ptr<Region> copy (RegionFactory::create (region, true));
                playlist->clear_changes ();
                playlist->add_region (copy, pos);
                _session->add_command (new StatefulDiffCommand (playlist));
-               commit_reversible_command ();
                break;
        }
 
@@ -942,12 +900,10 @@ Editor::finish_bringing_in_material (boost::shared_ptr<Region> region, uint32_t
                list<boost::shared_ptr<AudioTrack> > at (_session->new_audio_track (in_chans, out_chans, Destructive));
                if (!at.empty()) {
                        boost::shared_ptr<Playlist> playlist = at.front()->playlist();
-                       boost::shared_ptr<Region> copy (RegionFactory::create (region));
-                       begin_reversible_command (Operations::insert_file);
+                       boost::shared_ptr<Region> copy (RegionFactory::create (region, true));
                        playlist->clear_changes ();
                        playlist->add_region (copy, pos);
                        _session->add_command (new StatefulDiffCommand (playlist));
-                       commit_reversible_command ();
                }
                break;
        }
@@ -968,7 +924,7 @@ Editor::_import_thread (void *arg)
 void *
 Editor::import_thread ()
 {
-       _session->import_audiofiles (import_status);
+       _session->import_files (import_status);
        pthread_exit_pbd (0);
        /*NOTREACHED*/
        return 0;