X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_pt_import.cc;h=cb3054a62b48e369b9ea00dc059727501a810454;hb=df98be1240907af95fc5af6495d120d52560da2f;hp=c1ae3a3bb150aeff216ba8d2e8612196fa2973c0;hpb=1d6e8f6681bb1f9ef16904016bf515c23e93efc9;p=ardour.git diff --git a/gtk2_ardour/editor_pt_import.cc b/gtk2_ardour/editor_pt_import.cc index c1ae3a3bb1..cb3054a62b 100644 --- a/gtk2_ardour/editor_pt_import.cc +++ b/gtk2_ardour/editor_pt_import.cc @@ -36,6 +36,7 @@ #include "ardour/audioregion.h" #include "ardour/midi_region.h" #include "ardour/midi_track.h" +#include "ardour/midi_model.h" #include "ardour/operations.h" #include "ardour/region_factory.h" #include "ardour/smf_source.h" @@ -60,7 +61,7 @@ #include "mouse_cursors.h" #include "editor_cursors.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; using namespace ARDOUR; @@ -121,6 +122,7 @@ Editor::do_ptimport (std::string ptpath, vector to_import; string fullpath; bool ok = false; + bool onefailed = false; PTFFormat ptf; framepos_t pos = -1; @@ -128,11 +130,18 @@ Editor::do_ptimport (std::string ptpath, vector ptfregpair; if (ptf.load(ptpath, _session->frame_rate()) == -1) { - MessageDialog msg (_("Doesn't seem to be a valid PT session file (.ptf only currently supported)")); + MessageDialog msg (_("Doesn't seem to be a valid PT session file")); msg.run (); return; - } + } else { + MessageDialog msg (string_compose (_("PT v%1 Session @ %2Hz\n\n%3 audio files\n%4 regions\n%5 active regions\n\nContinue..."), (int)ptf.version, ptf.sessionrate, ptf.audiofiles.size(), ptf.regions.size(), ptf.tracks.size())); + msg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + int result = msg.run (); + if (result != Gtk::RESPONSE_OK) { + return; + } + } current_interthread_info = &import_status; import_status.current = 1; import_status.total = ptf.audiofiles.size (); @@ -158,14 +167,38 @@ Editor::do_ptimport (std::string ptpath, ptfwavpair.push_back(p); imported.push_back(import_status.sources.back()); + } else { + onefailed = true; } } + if (onefailed) { + MessageDialog msg (_("Failed to load one or more of the audio files, but continuing to attempt import.")); + msg.run (); + } else { + MessageDialog msg (_("Success! Import should complete soon.")); + msg.run (); + } + + // Create a dummy midi track first to get a midi Source + list > mt ( + _session->new_midi_track (ChanCount (DataType::MIDI, 1), + ChanCount (DataType::MIDI, 1), + true, + instrument, (Plugin::PresetRecord*) 0, + (RouteGroup*) 0, + 1, + string(), + PresentationInfo::max_order)); + if (mt.empty()) { + return; + } + for (vector::iterator a = ptf.regions.begin(); a != ptf.regions.end(); ++a) { for (vector::iterator p = ptfwavpair.begin(); p != ptfwavpair.end(); ++p) { - if (p->index1 == a->wave.index) { + if ((p->index1 == a->wave.index) && (strcmp(a->wave.filename.c_str(), "") != 0)) { for (SourceList::iterator x = imported.begin(); x != imported.end(); ++x) { if ((*x)->id() == p->id) { @@ -194,6 +227,42 @@ Editor::do_ptimport (std::string ptpath, } } } + if (strcmp(a->wave.filename.c_str(), "") == 0) { + /* Empty wave - assume MIDI region */ + boost::shared_ptr midi_track = mt.back(); + boost::shared_ptr playlist = midi_track->playlist(); + framepos_t f = (framepos_t)a->startpos; + framecnt_t length = (framecnt_t)a->length; + MusicFrame pos (f, 0); + boost::shared_ptr src = _session->create_midi_source_by_stealing_name (midi_track); + PropertyList plist; + plist.add (ARDOUR::Properties::start, 0); + plist.add (ARDOUR::Properties::length, length); + plist.add (ARDOUR::Properties::name, PBD::basename_nosuffix(src->name())); + boost::shared_ptr region = (RegionFactory::create (src, plist)); + /* sets beat position */ + region->set_position (pos.frame, pos.division); + midi_track->playlist()->add_region (region, pos.frame, 1.0, false, pos.division); + + boost::shared_ptr mr = boost::dynamic_pointer_cast(region); + boost::shared_ptr mm = mr->midi_source(0)->model(); + MidiModel::NoteDiffCommand *midicmd; + midicmd = mm->new_note_diff_command ("Import ProTools MIDI"); + + for (vector::iterator + j = a->midi.begin(); + j != a->midi.end(); ++j) { + Evoral::Beats start = (Evoral::Beats)(j->pos/960000.); + Evoral::Beats len = (Evoral::Beats)(j->length/960000.); + // PT C-2 = 0, Ardour C-1 = 0, subtract twelve to convert... + midicmd->add(boost::shared_ptr > + (new Evoral::Note( (uint8_t)1, start, len, j->note - 12, j->velocity ))); + } + mm->apply_command (_session, midicmd); + boost::shared_ptr copy (RegionFactory::create (mr, true)); + playlist->clear_changes (); + playlist->add_region (copy, a->startpos); + } } boost::shared_ptr existing_track; @@ -206,7 +275,7 @@ Editor::do_ptimport (std::string ptpath, for (vector::iterator p = ptfregpair.begin(); p != ptfregpair.end(); ++p) { - if ((p->index1 == a->reg.index)) { + if (p->index1 == a->reg.index) { // Matched a ptf active region to an ardour region utr.index1 = a->index; utr.index2 = nth; @@ -226,12 +295,27 @@ Editor::do_ptimport (std::string ptpath, } else { // Put on a new track DEBUG_TRACE (DEBUG::FileUtils, string_compose ("\twav(%1) reg(%2) new_tr(%3)\n", a->reg.wave.filename.c_str(), a->reg.index, nth)); - list > at (_session->new_audio_track (1, 2, Normal, 0, 1)); + list > at (_session->new_audio_track (1, 2, 0, 1, string(), PresentationInfo::max_order, Normal)); if (at.empty()) { return; } existing_track = at.back(); - existing_track->set_name (a->name); + std::string trackname; + try { + trackname = Glib::convert_with_fallback (a->name, "UTF-8", "UTF-8", "_"); + } catch (Glib::ConvertError& err) { + trackname = string_compose ("Invalid %1", a->index); + } + // TODO legalize track name (no slashes, no colons) +#if 0 // TODO -- "find_route_name" is currently private + /* generate a unique name by adding a number if needed */ + uint32_t id = 0; + if (!_session->find_route_name (trackname.c_str (), id, trackname, false)) { + fatal << _("PTImport: UINT_MAX routes? impossible!") << endmsg; + abort(); /*NOTREACHED*/ + } +#endif + existing_track->set_name (trackname); boost::shared_ptr playlist = existing_track->playlist(); boost::shared_ptr copy (RegionFactory::create (r, true)); playlist->clear_changes ();