diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 06edb9fd8e..61d0a22882 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -781,9 +781,6 @@ Editor::add_sources (vector 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))); diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 8d818e4c6b..74655e28bc 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -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; }; diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 9bf7033c0b..4befd2ab00 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -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 > Sources; Sources all_new_sources; boost::shared_ptr afs; + boost::shared_ptr 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 source; - std::auto_ptr smf_reader; + std::auto_ptr 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(*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(*x), false); } + + /* don't create tracks for empty MIDI sources (channels) */ + if ((smfs = boost::dynamic_pointer_cast(*x)) != 0 && smfs->is_empty()) { + x = all_new_sources.erase(x); + } else { + ++x; + } } /* save state so that we don't lose these new Sources */ diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 5ab3a5df13..6ec5f6cf46 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -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; }