enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / editor_pt_import.cc
index 17c46be24499fcb329957df4fe8933fba2e50894..2b659e0369d509417f7a6ffe179acaaeb08a79d0 100644 (file)
@@ -60,7 +60,7 @@
 #include "mouse_cursors.h"
 #include "editor_cursors.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -121,6 +121,7 @@ Editor::do_ptimport (std::string ptpath,
        vector<string> to_import;
        string fullpath;
        bool ok = false;
+       bool onefailed = false;
        PTFFormat ptf;
        framepos_t pos = -1;
 
@@ -132,7 +133,7 @@ Editor::do_ptimport (std::string ptpath,
                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+0), ptf.sessionrate, ptf.audiofiles.size(), ptf.regions.size(), ptf.tracks.size()));
+               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 ();
@@ -165,9 +166,19 @@ 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 ();
+       }
+
        for (vector<PTFFormat::region_t>::iterator a = ptf.regions.begin();
                        a != ptf.regions.end(); ++a) {
                for (vector<ptflookup_t>::iterator p = ptfwavpair.begin();
@@ -213,7 +224,7 @@ Editor::do_ptimport (std::string ptpath,
                for (vector<ptflookup_t>::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;
@@ -233,12 +244,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<boost::shared_ptr<AudioTrack> > at (_session->new_audio_track (1, 2, Normal, 0, 1));
+                                       list<boost::shared_ptr<AudioTrack> > 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> playlist = existing_track->playlist();
                                        boost::shared_ptr<Region> copy (RegionFactory::create (r, true));
                                        playlist->clear_changes ();