Don't create tracks for empty MIDI channels on import (i.e. make import look clean...
authorDavid Robillard <d@drobilla.net>
Fri, 16 May 2008 22:40:35 +0000 (22:40 +0000)
committerDavid Robillard <d@drobilla.net>
Fri, 16 May 2008 22:40:35 +0000 (22:40 +0000)
Remove no longer useful debugging output.

git-svn-id: svn://localhost/ardour2/branches/3.0@3365 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_audio_import.cc
libs/ardour/ardour/smf_source.h
libs/ardour/import.cc
libs/ardour/smf_source.cc

index 06edb9fd8ebe825366dc6334667903c1858c33a9..61d0a2288295b95e53a0ce8221883b4d8e7e1035 100644 (file)
@@ -781,9 +781,6 @@ Editor::add_sources (vector<Glib::ustring> paths, SourceList& sources, nframes64
                        
                        region_name = region_name_from_path ((*x)->path(), false, false, sources.size(), n);
 
-                       cout << "REGION NAME: " << region_name << endl;
-                       cout << "SOURCE LENGTH: " << (*x)->length() << endl;
-
                        regions.push_back (RegionFactory::create (just_one, 0, (*x)->length(), region_name, 0,
                                                                   Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External)));
 
index 8d818e4c6bd0fc0758add8b4d7343c1571df54cc..74655e28bc0676dfd8dbb67b5d64798346514a18 100644 (file)
@@ -137,9 +137,10 @@ class SMFSource : public MidiSource {
        string         _take_id;
        bool           _allow_remove_if_empty;
        FILE*          _fd;
-       double         _last_ev_time; // last frame time written, relative to source start
+       double         _last_ev_time; ///< last frame time written, relative to source start
        uint32_t       _track_size;
-       uint32_t       _header_size; // size of SMF header, including MTrk chunk header
+       uint32_t       _header_size; ///< size of SMF header, including MTrk chunk header
+       bool           _empty; ///< true iff file contains (non-empty) events
 
        static string _search_path;
 };
index 9bf7033c0b4829406fc86ee1c1c29978e1a665ce..4befd2ab0083ca9d71bff1ddacbe74b7009cf112 100644 (file)
@@ -171,9 +171,6 @@ get_paths_for_new_sources (const bool allow_replacing, const string& import_file
 
                filepath += '/';
                filepath += get_non_existent_filename (type, allow_replacing, filepath, basename, n, channels); 
-
-               cout << "NEW SOURCE PATH: " << filepath << endl;
-
                new_paths.push_back (filepath);
        }
 
@@ -377,6 +374,7 @@ Session::import_audiofiles (import_status& status)
        typedef vector<boost::shared_ptr<Source> > Sources;
        Sources all_new_sources;
        boost::shared_ptr<AudioFileSource> afs;
+       boost::shared_ptr<SMFSource> smfs;
        uint channels = 0;
 
        status.sources.clear ();
@@ -385,9 +383,8 @@ Session::import_audiofiles (import_status& status)
                        p != status.paths.end() && !status.cancel;
                        ++p, ++cnt)
        {
-
                boost::shared_ptr<ImportableSource> source;
-               std::auto_ptr<SMFReader>        smf_reader;
+               std::auto_ptr<SMFReader>            smf_reader;
                const DataType type = ((*p).rfind(".mid") != string::npos) ? 
                        DataType::MIDI : DataType::AUDIO;
                
@@ -458,10 +455,7 @@ Session::import_audiofiles (import_status& status)
 
                /* flush the final length(s) to the header(s) */
 
-               for (Sources::iterator x = all_new_sources.begin(); x != all_new_sources.end(); ++x)
-               {
-                       cout << "NEW SOURCE: " << (*x)->path() << endl;
-
+               for (Sources::iterator x = all_new_sources.begin(); x != all_new_sources.end(); ) {
                        if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(*x)) != 0) {
                                afs->update_header(0, *now, xnow);
                                afs->done_with_peakfile_writes ();
@@ -472,6 +466,13 @@ Session::import_audiofiles (import_status& status)
                        if (Config->get_auto_analyse_audio()) {
                                Analyser::queue_source_for_analysis (boost::static_pointer_cast<Source>(*x), false);
                        }
+
+                       /* don't create tracks for empty MIDI sources (channels) */
+                       if ((smfs = boost::dynamic_pointer_cast<SMFSource>(*x)) != 0 && smfs->is_empty()) {
+                               x = all_new_sources.erase(x);
+                       } else {
+                               ++x;
+                       }
                }
 
                /* save state so that we don't lose these new Sources */
index 5ab3a5df13f383e74161267bab33375458bfe26b..6ec5f6cf468870a9c03bb0311fd61cfe398eeeac 100644 (file)
@@ -59,6 +59,7 @@ SMFSource::SMFSource (Session& s, std::string path, Flag flags)
        , _last_ev_time(0)
        , _track_size(4) // 4 bytes for the ever-present EOT event
        , _header_size(22)
+       , _empty(true)
 {
        /* constructor used for new internal-to-session files. file cannot exist */
 
@@ -83,6 +84,7 @@ SMFSource::SMFSource (Session& s, const XMLNode& node)
        , _last_ev_time(0)
        , _track_size(4) // 4 bytes for the ever-present EOT event
        , _header_size(22)
+       , _empty(true)
 {
        /* constructor used for existing internal-to-session files. file must exist */
 
@@ -156,6 +158,7 @@ SMFSource::open()
                uint32_t track_size_be = 0;
                fread(&track_size_be, 4, 1, _fd);
                _track_size = GUINT32_FROM_BE(track_size_be);
+               _empty = _track_size > 4;
                //cerr << "SMF - read track size " << _track_size << endl;
 
        // We're making a new file
@@ -167,6 +170,7 @@ SMFSource::open()
                        return -2;
                }
                _track_size = 4;
+               _empty = true;
 
                // Write a tentative header just to pad things out so writing happens in the right spot
                flush_header();
@@ -499,12 +503,12 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
 void
 SMFSource::append_event_unlocked(EventTimeUnit unit, const MIDI::Event& ev)
 {
-       printf("SMFSource: %s - append_event_unlocked chan = %u, time = %lf, size = %u, data = ",
+       /*printf("SMFSource: %s - append_event_unlocked chan = %u, time = %lf, size = %u, data = ",
                        name().c_str(), (unsigned)ev.channel(), ev.time(), ev.size()); 
        for (size_t i=0; i < ev.size(); ++i) {
                printf("%X ", ev.buffer()[i]);
        }
-       printf("\n");
+       printf("\n");*/
        
        assert(ev.time() >= 0);
        
@@ -533,8 +537,10 @@ SMFSource::append_event_unlocked(EventTimeUnit unit, const MIDI::Event& ev)
 
        _track_size += stamp_size + ev.size();
        _write_data_count += ev.size();
-
        _last_ev_time = ev.time();
+
+       if (ev.size() > 0)
+               _empty = false;
 }
 
 
@@ -844,11 +850,7 @@ SMFSource::set_source_name (string newname, bool destructive)
 bool
 SMFSource::is_empty () const
 {
-       bool ret = (_track_size > 4);
-
-       //cerr << name() << " IS EMPTY: " << ret << endl;
-
-       return ret;
+       return _empty;
 }