13
0

Don't create tracks for empty MIDI channels on import (i.e. make import look clean and sensible).

Remove no longer useful debugging output.


git-svn-id: svn://localhost/ardour2/branches/3.0@3365 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2008-05-16 22:40:35 +00:00
parent 415f80dc9f
commit 7666a4a5ff
4 changed files with 23 additions and 22 deletions

View 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)));

View 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;
};

View 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 */

View 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;
}