Big Mouth Billy Bass automation library
song.hpp@6:ea8136eb6976, 2013-06-20 (annotated)
- Committer:
- bikeNomad
- Date:
- Thu Jun 20 03:04:36 2013 +0000
- Revision:
- 6:ea8136eb6976
- Parent:
- 4:f009306756b3
- Child:
- 7:dba9221acf48
Added diagnostic output and manual (keyboard) testing
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:ea8136eb6976 | 56 | bool addAction(float _time, int _state, DigitalOut* _out, char _code) { |
bikeNomad | 4:f009306756b3 | 57 | if (numActions >= MAX_ACTIONS_PER_SONG) return false; |
bikeNomad | 6:ea8136eb6976 | 58 | actions[numActions++].set(_time, _state, _out, _code); |
bikeNomad | 4:f009306756b3 | 59 | return true; |
bikeNomad | 4:f009306756b3 | 60 | } |
bikeNomad | 4:f009306756b3 | 61 | unsigned getNumActions() const { |
bikeNomad | 4:f009306756b3 | 62 | return numActions; |
bikeNomad | 4:f009306756b3 | 63 | } |
bikeNomad | 0:84aaade0de8f | 64 | |
bikeNomad | 3:6c91a6232c4a | 65 | void print(FILE *f) { |
bikeNomad | 3:6c91a6232c4a | 66 | fprintf(f, "%s fish=%u seq=%u\r\n", getSampleFileName(), whichFish, sequenceNumber); |
bikeNomad | 4:f009306756b3 | 67 | Action *lastAction = actions + numActions; |
bikeNomad | 4:f009306756b3 | 68 | for (Action *action = actions; action < lastAction; action++) { |
bikeNomad | 4:f009306756b3 | 69 | fprintf(f, "%0.02f %s %d\r\n", action->actionTime, myFish()->outputName(action->output), action->desiredState); |
bikeNomad | 0:84aaade0de8f | 70 | } |
bikeNomad | 0:84aaade0de8f | 71 | } |
bikeNomad | 0:84aaade0de8f | 72 | |
bikeNomad | 0:84aaade0de8f | 73 | protected: |
bikeNomad | 4:f009306756b3 | 74 | Song() { |
bikeNomad | 4:f009306756b3 | 75 | reset(); |
bikeNomad | 4:f009306756b3 | 76 | } |
bikeNomad | 4:f009306756b3 | 77 | ~Song() {} |
bikeNomad | 0:84aaade0de8f | 78 | |
bikeNomad | 0:84aaade0de8f | 79 | static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ]; |
bikeNomad | 0:84aaade0de8f | 80 | static unsigned const NO_FISH; |
bikeNomad | 0:84aaade0de8f | 81 | static char const *textExtension; |
bikeNomad | 0:84aaade0de8f | 82 | static char const *sampleExtension; |
bikeNomad | 4:f009306756b3 | 83 | static Song theSong; |
bikeNomad | 0:84aaade0de8f | 84 | |
bikeNomad | 0:84aaade0de8f | 85 | unsigned sequenceNumber; // 0-relative |
bikeNomad | 0:84aaade0de8f | 86 | unsigned whichFish; // 0-relative |
bikeNomad | 0:84aaade0de8f | 87 | char fullname[ MAX_PATH_LEN ]; // with directory name |
bikeNomad | 0:84aaade0de8f | 88 | char *basename; // points into fullname |
bikeNomad | 0:84aaade0de8f | 89 | char *extension; // points into fullname |
bikeNomad | 0:84aaade0de8f | 90 | actions_t actions; |
bikeNomad | 4:f009306756b3 | 91 | unsigned numActions; |
bikeNomad | 0:84aaade0de8f | 92 | }; |
bikeNomad | 0:84aaade0de8f | 93 | |
bikeNomad | 0:84aaade0de8f | 94 | #endif // __included_song_hpp |