summaryrefslogtreecommitdiff
path: root/drumgizmo
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-01-21 18:05:07 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-02-09 09:02:18 +0100
commit6004e264418fa1f8a033c69633b2f0205c247266 (patch)
tree4d01947d08f33ac1cace240f12ed2e5e660bac00 /drumgizmo
parent6253e37c2f0219d61193d0d405e7f23a4bae3287 (diff)
Added missing changes
Diffstat (limited to 'drumgizmo')
-rw-r--r--drumgizmo/input/midifile.cc78
-rw-r--r--drumgizmo/output/wavfile.cc4
2 files changed, 44 insertions, 38 deletions
diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc
index b0685ec..70c840f 100644
--- a/drumgizmo/input/midifile.cc
+++ b/drumgizmo/input/midifile.cc
@@ -58,26 +58,27 @@ bool MidifileInputEngine::init(Instruments& instruments) {
return false;
}
smf = smf_load(file.c_str());
- if (sfml == nullptr) {
- fprintf(stderr, "Could not open midifile '%s'.\n", filename.c_str());
+ if (smf == nullptr) {
+ fprintf(stderr, "Could not open midifile '%s'.\n", file.c_str());
return false;
}
MidiMapParser p{midimap};
if (p.parse()) {
- fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimapfile.c_str());
+ fprintf(stderr, "Could not parse midimapfile '%s'.\n", midimap.c_str());
return false;
}
- midiMapper.midimap = std::move(p.midimap);
+ midi_mapper.midimap = p.midimap;
for (auto i = 0u; i < instruments.size(); ++i) {
- auto name = instruments[0]->name;
- midiMapper.instrmap[name] = i;
+ auto name = instruments[i]->name();
+ printf("%d : %s\n", i, name.c_str());
+ midi_mapper.instrmap[name] = i;
}
return true;
}
void MidifileInputEngine::setParm(std::string parm, std::string value) {
if(parm == "file") {
- filen = value;
+ file = value;
} else if(parm == "speed") {
speed = std::stof(value);
} else if (parm == "midimap") {
@@ -85,7 +86,7 @@ void MidifileInputEngine::setParm(std::string parm, std::string value) {
} else if (parm == "loop") {
loop = true;
} else {
- printf("Unsupported midifile parameter '%s'\n", parm);
+ printf("Unsupported midifile parameter '%s'\n", parm.c_str());
}
}
@@ -101,58 +102,67 @@ void MidifileInputEngine::pre() {
event_t* MidifileInputEngine::run(size_t pos, size_t len, size_t *nevents) {
event_t* evs{nullptr};
- std::size_t nevs{0u};
- double current_max_time = 1.0 * (pos + len) / (44100.0 / speed);
+ size_t num_events{0u};
+
+ double current_max_time = (1.0 + pos + len) / (44100.0 / speed);
current_max_time -= offset;
- if (current_event == nullptr) {
+ // double cur_min_time = (double)(pos) / (44100.0 / speed);
+
+ if(!current_event) {
current_event = smf_get_next_event(smf);
}
- while(current_event && current_event->time_seconds < cur_max_time) {
+
+ while(current_event && current_event->time_seconds < current_max_time) {
if(!smf_event_is_metadata(current_event)) {
- if((current_event->midi_buffer_length == 3) &&
- ((current_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) &&
- (track == -1 || current_event->track_number == track) &&
- current_event->midi_buffer[2] > 0) {
- if(evs == NULL) {
+ if( (current_event->midi_buffer_length == 3) &&
+ ((current_event->midi_buffer[0] & NOTE_ON) == NOTE_ON) &&
+ (track == -1 || current_event->track_number == track) &&
+ current_event->midi_buffer[2] > 0) {
+
+ if(evs == nullptr) {
+ printf("Yet another raw owning pointer was generated by drumgizmo/input/midifile.cc - GET RID OF THEM!\n");
evs = (event_t *)malloc(sizeof(event_t) * 1000);
}
+
int key = current_event->midi_buffer[1];
int velocity = current_event->midi_buffer[2];
-
- evs[nevs].type = TYPE_ONSET;
+
+ evs[num_events].type = TYPE_ONSET;
size_t evpos = current_event->time_seconds * (44100.0 / speed);
- evs[nevs].offset = evpos - pos;
-
- int i = midiMap.lookup(key);
+ evs[num_events].offset = evpos - pos;
+
+ int i = midi_mapper.lookup(key);
if(i != -1) {
- evs[nevs].instrument = i;
- evs[nevs].velocity = velocity / 127.0;
- nevs++;
- if(nevs > 999) {
+ evs[num_events].instrument = i;
+ evs[num_events].velocity = velocity / 127.0;
+
+ ++num_events;
+ if(num_events > 999) {
fprintf(stderr, "PANIC!\n");
break;
}
}
}
}
+
current_event = smf_get_next_event(smf);
}
-
+
if(!current_event) {
if(loop) {
smf_rewind(smf);
- offset += cur_max_time;
+ offset += current_max_time;
} else {
- if(evs == NULL) {
+ if(evs == nullptr) {
+ printf("Yet another raw owning pointer was generated by drumgizmo/input/midifile.cc - GET RID OF THEM!\n");
evs = (event_t *)malloc(sizeof(event_t) * 1000);
}
- evs[nevs].type = TYPE_STOP;
- evs[nevs].offset = len - 1;
- nevs++;
+ evs[num_events].type = TYPE_STOP;
+ evs[num_events].offset = len - 1;
+ ++num_events;
}
}
-
- *nevents = nevs;
+ *nevents = num_events;
return evs;
}
diff --git a/drumgizmo/output/wavfile.cc b/drumgizmo/output/wavfile.cc
index 7a59892..e1cb16e 100644
--- a/drumgizmo/output/wavfile.cc
+++ b/drumgizmo/output/wavfile.cc
@@ -24,8 +24,6 @@
* along with DrumGizmo; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <cassert>
-
#include "wavfile.h"
WavfileOutputEngine::WavfileOutputEngine()
@@ -89,8 +87,6 @@ void WavfileOutputEngine::run(int ch, sample_t* samples, size_t nsamples) {
return;
}
- assert(channels[ch] != nullptr);
- assert(samples != nullptr);
sf_writef_float(channels[ch], samples, nsamples);
}