Big Mouth Billy Bass automation library
Diff: song.cpp
- Revision:
- 4:f009306756b3
- Parent:
- 3:6c91a6232c4a
- Child:
- 5:869b3711bdb3
diff -r 6c91a6232c4a -r f009306756b3 song.cpp --- a/song.cpp Tue Jun 18 13:11:07 2013 +0000 +++ b/song.cpp Tue Jun 18 14:10:34 2013 +0000 @@ -15,16 +15,15 @@ char const *Song::sampleExtension = "raw"; // class static unsigned const Song::NO_FISH = MAX_FISH + 1; +// one song, re-used +Song Song::theSong; // _name is relative to BASS_DIRECTORY // class static Song *Song::newSong(char const *_name) { - Song *s = new Song; - if (!s) { - fprintf(stderr, "new Song == 0\r\n"); - return 0; - } + Song *s = &theSong; + s->reset(); if (! s->parseFilename(_name)) { fprintf(stderr, "parseFilename(%s) failed\r\n", _name); goto on_error; @@ -38,7 +37,6 @@ return s; on_error: - delete s; return 0; } @@ -131,11 +129,11 @@ } // fprintf(stderr, "%d add %f %f %s\r\n", line, startTime, endTime, outName); - actions.push_back(Action(startTime, bass->onState(), out, outName)); - actions.push_back(Action(endTime, bass->offState(), out, outName)); + addAction(startTime, bass->onState(), out); + addAction(endTime, bass->offState(), out); } - fprintf(stderr, "Added %d actions\r\n", actions.size()); - std::sort(actions.begin(), actions.end()); // sort actions by time + fprintf(stderr, "Added %d actions\r\n", numActions); + qsort(actions, numActions, sizeof(Action), &Action::compare); retval = true; done: @@ -143,3 +141,4 @@ fclose(txtfile); return retval; } +