Big Mouth Billy Bass automation library
Diff: song.hpp
- Revision:
- 4:f009306756b3
- Parent:
- 3:6c91a6232c4a
- Child:
- 6:ea8136eb6976
--- a/song.hpp Tue Jun 18 13:11:07 2013 +0000
+++ b/song.hpp Tue Jun 18 14:10:34 2013 +0000
@@ -10,22 +10,24 @@
class Song
{
public:
- typedef std::vector<Action> actions_t;
+ typedef Action actions_t[ MAX_ACTIONS_PER_SONG ];
// _name is relative to BASS_DIRECTORY
// return a pointer to a fully read-in Song if valid
- // also adds new song to songs
static Song *newSong(char const *_name);
- Song() : sequenceNumber(0), whichFish(NO_FISH), basename(0), extension(0) {
- fullname[0] = 0;
- actions.reserve(MAX_ACTIONS_PER_SONG);
+
+ void reset() {
+ sequenceNumber = 0;
+ whichFish = NO_FISH;
+ basename = 0;
+ extension = 0;
+ numActions = 0;
}
- ~Song() {
- actions.clear();
+
+ BillyBass * myFish() {
+ return BillyBass::bassNumber(whichFish);
}
-
- BillyBass * myFish() { return BillyBass::bassNumber(whichFish); }
bool isValid() const {
return basename != 0 && whichFish != NO_FISH;
}
@@ -48,24 +50,37 @@
strcpy(extension, textExtension);
return fullname;
}
- actions_t &getActions() {
+ Action *getActions() {
return actions;
}
+ bool addAction(float _time, int _state, DigitalOut* _out) {
+ if (numActions >= MAX_ACTIONS_PER_SONG) return false;
+ actions[numActions++].set(_time, _state, _out);
+ return true;
+ }
+ unsigned getNumActions() const {
+ return numActions;
+ }
void print(FILE *f) {
fprintf(f, "%s fish=%u seq=%u\r\n", getSampleFileName(), whichFish, sequenceNumber);
- for (actions_t::const_iterator action_it = actions.begin(); action_it != actions.end(); action_it++) {
- Action const &action = *action_it;
- fprintf(f, "%0.02f %s %d\r\n", action.actionTime, action.outputName, action.desiredState ? 1 : 0);
+ Action *lastAction = actions + numActions;
+ for (Action *action = actions; action < lastAction; action++) {
+ fprintf(f, "%0.02f %s %d\r\n", action->actionTime, myFish()->outputName(action->output), action->desiredState);
}
}
protected:
+ Song() {
+ reset();
+ }
+ ~Song() {}
static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ];
static unsigned const NO_FISH;
static char const *textExtension;
static char const *sampleExtension;
+ static Song theSong;
unsigned sequenceNumber; // 0-relative
unsigned whichFish; // 0-relative
@@ -73,6 +88,7 @@
char *basename; // points into fullname
char *extension; // points into fullname
actions_t actions;
+ unsigned numActions;
};
#endif // __included_song_hpp
Ned Konz