Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

Committer:
bikeNomad
Date:
Thu Jun 20 15:03:49 2013 +0000
Revision:
8:ad0c038ebfc1
Parent:
7:dba9221acf48
Made main loop repeat forever; eliminated time shifting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 0:84aaade0de8f 1 #ifndef __included_song_hpp
bikeNomad 0:84aaade0de8f 2 #define __included_song_hpp
bikeNomad 0:84aaade0de8f 3
bikeNomad 0:84aaade0de8f 4 #include <DirHandle.h>
bikeNomad 0:84aaade0de8f 5
bikeNomad 0:84aaade0de8f 6 #include "billybass.hpp"
bikeNomad 0:84aaade0de8f 7 #include "config.hpp"
bikeNomad 0:84aaade0de8f 8 #include "action.hpp"
bikeNomad 0:84aaade0de8f 9
bikeNomad 0:84aaade0de8f 10 class Song
bikeNomad 0:84aaade0de8f 11 {
bikeNomad 0:84aaade0de8f 12 public:
bikeNomad 4:f009306756b3 13 typedef Action actions_t[ MAX_ACTIONS_PER_SONG ];
bikeNomad 0:84aaade0de8f 14
bikeNomad 0:84aaade0de8f 15 // _name is relative to BASS_DIRECTORY
bikeNomad 0:84aaade0de8f 16 // return a pointer to a fully read-in Song if valid
bikeNomad 0:84aaade0de8f 17 static Song *newSong(char const *_name);
bikeNomad 0:84aaade0de8f 18
bikeNomad 4:f009306756b3 19
bikeNomad 4:f009306756b3 20 void reset() {
bikeNomad 4:f009306756b3 21 sequenceNumber = 0;
bikeNomad 4:f009306756b3 22 whichFish = NO_FISH;
bikeNomad 4:f009306756b3 23 basename = 0;
bikeNomad 4:f009306756b3 24 extension = 0;
bikeNomad 4:f009306756b3 25 numActions = 0;
bikeNomad 0:84aaade0de8f 26 }
bikeNomad 4:f009306756b3 27
bikeNomad 4:f009306756b3 28 BillyBass * myFish() {
bikeNomad 4:f009306756b3 29 return BillyBass::bassNumber(whichFish);
bikeNomad 3:6c91a6232c4a 30 }
bikeNomad 0:84aaade0de8f 31 bool isValid() const {
bikeNomad 0:84aaade0de8f 32 return basename != 0 && whichFish != NO_FISH;
bikeNomad 0:84aaade0de8f 33 }
bikeNomad 0:84aaade0de8f 34 bool parseFilename(char const *_name);
bikeNomad 0:84aaade0de8f 35 bool readActions();
bikeNomad 0:84aaade0de8f 36
bikeNomad 0:84aaade0de8f 37 unsigned getSequenceNumber() const {
bikeNomad 0:84aaade0de8f 38 return sequenceNumber;
bikeNomad 0:84aaade0de8f 39 }
bikeNomad 0:84aaade0de8f 40 unsigned getWhichFish() const {
bikeNomad 0:84aaade0de8f 41 return whichFish;
bikeNomad 0:84aaade0de8f 42 }
bikeNomad 0:84aaade0de8f 43 char const *getSampleFileName() {
bikeNomad 0:84aaade0de8f 44 if (!extension) return 0;
bikeNomad 0:84aaade0de8f 45 strcpy(extension, sampleExtension);
bikeNomad 0:84aaade0de8f 46 return fullname;
bikeNomad 0:84aaade0de8f 47 }
bikeNomad 0:84aaade0de8f 48 char const *getTextFileName() {
bikeNomad 0:84aaade0de8f 49 if (!extension) return 0;
bikeNomad 0:84aaade0de8f 50 strcpy(extension, textExtension);
bikeNomad 0:84aaade0de8f 51 return fullname;
bikeNomad 0:84aaade0de8f 52 }
bikeNomad 4:f009306756b3 53 Action *getActions() {
bikeNomad 0:84aaade0de8f 54 return actions;
bikeNomad 0:84aaade0de8f 55 }
bikeNomad 7:dba9221acf48 56 bool addAction(float _time, int _state, DigitalOut* _out, char _code);
bikeNomad 7:dba9221acf48 57
bikeNomad 4:f009306756b3 58 unsigned getNumActions() const {
bikeNomad 4:f009306756b3 59 return numActions;
bikeNomad 4:f009306756b3 60 }
bikeNomad 0:84aaade0de8f 61
bikeNomad 3:6c91a6232c4a 62 void print(FILE *f) {
bikeNomad 3:6c91a6232c4a 63 fprintf(f, "%s fish=%u seq=%u\r\n", getSampleFileName(), whichFish, sequenceNumber);
bikeNomad 4:f009306756b3 64 Action *lastAction = actions + numActions;
bikeNomad 4:f009306756b3 65 for (Action *action = actions; action < lastAction; action++) {
bikeNomad 4:f009306756b3 66 fprintf(f, "%0.02f %s %d\r\n", action->actionTime, myFish()->outputName(action->output), action->desiredState);
bikeNomad 0:84aaade0de8f 67 }
bikeNomad 0:84aaade0de8f 68 }
bikeNomad 0:84aaade0de8f 69
bikeNomad 0:84aaade0de8f 70 protected:
bikeNomad 4:f009306756b3 71 Song() {
bikeNomad 4:f009306756b3 72 reset();
bikeNomad 4:f009306756b3 73 }
bikeNomad 4:f009306756b3 74 ~Song() {}
bikeNomad 0:84aaade0de8f 75
bikeNomad 0:84aaade0de8f 76 static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ];
bikeNomad 0:84aaade0de8f 77 static unsigned const NO_FISH;
bikeNomad 0:84aaade0de8f 78 static char const *textExtension;
bikeNomad 0:84aaade0de8f 79 static char const *sampleExtension;
bikeNomad 4:f009306756b3 80 static Song theSong;
bikeNomad 0:84aaade0de8f 81
bikeNomad 0:84aaade0de8f 82 unsigned sequenceNumber; // 0-relative
bikeNomad 0:84aaade0de8f 83 unsigned whichFish; // 0-relative
bikeNomad 0:84aaade0de8f 84 char fullname[ MAX_PATH_LEN ]; // with directory name
bikeNomad 0:84aaade0de8f 85 char *basename; // points into fullname
bikeNomad 0:84aaade0de8f 86 char *extension; // points into fullname
bikeNomad 0:84aaade0de8f 87 actions_t actions;
bikeNomad 4:f009306756b3 88 unsigned numActions;
bikeNomad 0:84aaade0de8f 89 };
bikeNomad 0:84aaade0de8f 90
bikeNomad 0:84aaade0de8f 91 #endif // __included_song_hpp