fix import of multi-track SMF files with some tracks containing only meta-events; correctly push error to log window when MIDI import fails; remove debug msg
git-svn-id: svn://localhost/ardour2/branches/3.0@9271 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
9ca4623451
commit
05d8801812
@ -373,71 +373,88 @@ write_midi_data_to_new_files (Evoral::SMF* source, ImportStatus& status,
|
|||||||
vector<boost::shared_ptr<Source> >& newfiles)
|
vector<boost::shared_ptr<Source> >& newfiles)
|
||||||
{
|
{
|
||||||
uint32_t buf_size = 4;
|
uint32_t buf_size = 4;
|
||||||
uint8_t* buf = (uint8_t*)malloc(buf_size);
|
uint8_t* buf = (uint8_t*) malloc (buf_size);
|
||||||
|
|
||||||
status.progress = 0.0f;
|
status.progress = 0.0f;
|
||||||
|
|
||||||
|
assert (newfiles.size() == source->num_tracks());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
vector<boost::shared_ptr<Source> >::iterator s = newfiles.begin();
|
||||||
|
|
||||||
|
for (unsigned i = 1; i <= source->num_tracks(); ++i) {
|
||||||
|
|
||||||
for (unsigned i = 1; i <= source->num_tracks(); ++i) {
|
boost::shared_ptr<SMFSource> smfs = boost::dynamic_pointer_cast<SMFSource> (*s);
|
||||||
boost::shared_ptr<SMFSource> smfs = boost::dynamic_pointer_cast<SMFSource>(newfiles[i-1]);
|
|
||||||
smfs->drop_model();
|
|
||||||
|
|
||||||
source->seek_to_track(i);
|
smfs->drop_model ();
|
||||||
|
source->seek_to_track (i);
|
||||||
uint64_t t = 0;
|
|
||||||
uint32_t delta_t = 0;
|
|
||||||
uint32_t size = 0;
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
while (!status.cancel) {
|
|
||||||
gint ignored; // imported files either don't have NoteID's or
|
|
||||||
// we ignore them.
|
|
||||||
|
|
||||||
size = buf_size;
|
|
||||||
|
|
||||||
int ret = source->read_event(&delta_t, &size, &buf, &ignored);
|
uint64_t t = 0;
|
||||||
if (size > buf_size)
|
uint32_t delta_t = 0;
|
||||||
buf_size = size;
|
uint32_t size = 0;
|
||||||
|
bool first = true;
|
||||||
if (ret < 0) { // EOT
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
t += delta_t;
|
|
||||||
|
|
||||||
if (ret == 0) { // Meta
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first) {
|
while (!status.cancel) {
|
||||||
smfs->mark_streaming_write_started ();
|
gint note_id_ignored; // imported files either don't have NoteID's or we ignore them.
|
||||||
first = false;
|
|
||||||
|
size = buf_size;
|
||||||
|
|
||||||
|
int ret = source->read_event (&delta_t, &size, &buf, ¬e_id_ignored);
|
||||||
|
|
||||||
|
if (size > buf_size) {
|
||||||
|
buf_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0) { // EOT
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
t += delta_t;
|
||||||
|
|
||||||
|
if (ret == 0) { // Meta
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
smfs->mark_streaming_write_started ();
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
smfs->append_event_unlocked_beats(Evoral::Event<double>(0,
|
||||||
|
(double)t / (double)source->ppqn(),
|
||||||
|
size,
|
||||||
|
buf));
|
||||||
|
|
||||||
|
if (status.progress < 0.99) {
|
||||||
|
status.progress += 0.01;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
smfs->append_event_unlocked_beats(Evoral::Event<double>(0,
|
if (!first) {
|
||||||
(double)t / (double)source->ppqn(),
|
|
||||||
size,
|
/* we wrote something */
|
||||||
buf));
|
|
||||||
|
const framepos_t pos = 0;
|
||||||
if (status.progress < 0.99)
|
const double length_beats = ceil(t / (double)source->ppqn());
|
||||||
status.progress += 0.01;
|
BeatsFramesConverter converter(smfs->session().tempo_map(), pos);
|
||||||
}
|
smfs->update_length(pos, converter.to(length_beats));
|
||||||
|
smfs->mark_streaming_write_completed ();
|
||||||
const framepos_t pos = 0;
|
|
||||||
const double length_beats = ceil(t / (double)source->ppqn());
|
if (status.cancel) {
|
||||||
BeatsFramesConverter converter(smfs->session().tempo_map(), pos);
|
break;
|
||||||
smfs->update_length(pos, converter.to(length_beats));
|
}
|
||||||
smfs->mark_streaming_write_completed ();
|
}
|
||||||
|
|
||||||
if (status.cancel) {
|
++s; // next source
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
error << "Corrupt MIDI file " << source->file_path() << endl;
|
error << "Corrupt MIDI file " << source->file_path() << endmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buf) {
|
||||||
|
free (buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -498,6 +515,7 @@ Session::import_audiofiles (ImportStatus& status)
|
|||||||
Sources newfiles;
|
Sources newfiles;
|
||||||
framepos_t natural_position = source ? source->natural_position() : 0;
|
framepos_t natural_position = source ? source->natural_position() : 0;
|
||||||
|
|
||||||
|
|
||||||
if (status.replace_existing_source) {
|
if (status.replace_existing_source) {
|
||||||
fatal << "THIS IS NOT IMPLEMENTED YET, IT SHOULD NEVER GET CALLED!!! DYING!" << endmsg;
|
fatal << "THIS IS NOT IMPLEMENTED YET, IT SHOULD NEVER GET CALLED!!! DYING!" << endmsg;
|
||||||
status.cancel = !map_existing_mono_sources (new_paths, *this, frame_rate(), newfiles, this);
|
status.cancel = !map_existing_mono_sources (new_paths, *this, frame_rate(), newfiles, this);
|
||||||
|
@ -1431,7 +1431,6 @@ Session::count_existing_track_channels (ChanCount& in, ChanCount& out)
|
|||||||
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
|
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
|
||||||
boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
|
boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
|
||||||
if (tr && !tr->is_hidden()) {
|
if (tr && !tr->is_hidden()) {
|
||||||
cerr << "Using track i/o counts for " << tr->name() << endl;
|
|
||||||
in += tr->n_inputs();
|
in += tr->n_inputs();
|
||||||
out += tr->n_outputs();
|
out += tr->n_outputs();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user