Big Mouth Billy Bass automation library
song.hpp@2:eaba75af0f0d, 2013-06-18 (annotated)
- Committer:
- bikeNomad
- Date:
- Tue Jun 18 06:12:48 2013 +0000
- Revision:
- 2:eaba75af0f0d
- Parent:
- 1:9b1f3eb204ac
- Child:
- 3:6c91a6232c4a
Still not doing actions but loading OK;
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 | 0:84aaade0de8f | 13 | typedef std::vector<Action> actions_t; |
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 | // also adds new song to songs |
bikeNomad | 0:84aaade0de8f | 18 | static Song *newSong(char const *_name); |
bikeNomad | 0:84aaade0de8f | 19 | |
bikeNomad | 1:9b1f3eb204ac | 20 | Song() : sequenceNumber(0), whichFish(NO_FISH), basename(0), extension(0) { |
bikeNomad | 0:84aaade0de8f | 21 | fullname[0] = 0; |
bikeNomad | 1:9b1f3eb204ac | 22 | actions.reserve(MAX_ACTIONS_PER_SONG); |
bikeNomad | 0:84aaade0de8f | 23 | } |
bikeNomad | 0:84aaade0de8f | 24 | |
bikeNomad | 0:84aaade0de8f | 25 | bool isValid() const { |
bikeNomad | 0:84aaade0de8f | 26 | return basename != 0 && whichFish != NO_FISH; |
bikeNomad | 0:84aaade0de8f | 27 | } |
bikeNomad | 0:84aaade0de8f | 28 | bool parseFilename(char const *_name); |
bikeNomad | 0:84aaade0de8f | 29 | bool readActions(); |
bikeNomad | 0:84aaade0de8f | 30 | |
bikeNomad | 0:84aaade0de8f | 31 | unsigned getSequenceNumber() const { |
bikeNomad | 0:84aaade0de8f | 32 | return sequenceNumber; |
bikeNomad | 0:84aaade0de8f | 33 | } |
bikeNomad | 0:84aaade0de8f | 34 | unsigned getWhichFish() const { |
bikeNomad | 0:84aaade0de8f | 35 | return whichFish; |
bikeNomad | 0:84aaade0de8f | 36 | } |
bikeNomad | 0:84aaade0de8f | 37 | char const *getSampleFileName() { |
bikeNomad | 0:84aaade0de8f | 38 | if (!extension) return 0; |
bikeNomad | 0:84aaade0de8f | 39 | strcpy(extension, sampleExtension); |
bikeNomad | 0:84aaade0de8f | 40 | return fullname; |
bikeNomad | 0:84aaade0de8f | 41 | } |
bikeNomad | 0:84aaade0de8f | 42 | char const *getTextFileName() { |
bikeNomad | 0:84aaade0de8f | 43 | if (!extension) return 0; |
bikeNomad | 0:84aaade0de8f | 44 | strcpy(extension, textExtension); |
bikeNomad | 0:84aaade0de8f | 45 | return fullname; |
bikeNomad | 0:84aaade0de8f | 46 | } |
bikeNomad | 2:eaba75af0f0d | 47 | actions_t &getActions() { |
bikeNomad | 0:84aaade0de8f | 48 | return actions; |
bikeNomad | 0:84aaade0de8f | 49 | } |
bikeNomad | 0:84aaade0de8f | 50 | |
bikeNomad | 0:84aaade0de8f | 51 | void print(Serial &pc) { |
bikeNomad | 0:84aaade0de8f | 52 | pc.printf("%s fish=%u seq=%u\r\n", getSampleFileName(), whichFish, sequenceNumber); |
bikeNomad | 0:84aaade0de8f | 53 | for (actions_t::const_iterator action_it = actions.begin(); action_it != actions.end(); action_it++) { |
bikeNomad | 0:84aaade0de8f | 54 | Action const &action = *action_it; |
bikeNomad | 0:84aaade0de8f | 55 | pc.printf("%0.02f %s %d\r\n", action.actionTime, action.outputName, action.desiredState ? 1 : 0); |
bikeNomad | 0:84aaade0de8f | 56 | } |
bikeNomad | 0:84aaade0de8f | 57 | } |
bikeNomad | 0:84aaade0de8f | 58 | |
bikeNomad | 0:84aaade0de8f | 59 | protected: |
bikeNomad | 0:84aaade0de8f | 60 | |
bikeNomad | 0:84aaade0de8f | 61 | static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ]; |
bikeNomad | 0:84aaade0de8f | 62 | static unsigned const NO_FISH; |
bikeNomad | 0:84aaade0de8f | 63 | static char const *textExtension; |
bikeNomad | 0:84aaade0de8f | 64 | static char const *sampleExtension; |
bikeNomad | 0:84aaade0de8f | 65 | |
bikeNomad | 0:84aaade0de8f | 66 | unsigned sequenceNumber; // 0-relative |
bikeNomad | 0:84aaade0de8f | 67 | unsigned whichFish; // 0-relative |
bikeNomad | 0:84aaade0de8f | 68 | char fullname[ MAX_PATH_LEN ]; // with directory name |
bikeNomad | 0:84aaade0de8f | 69 | char *basename; // points into fullname |
bikeNomad | 0:84aaade0de8f | 70 | char *extension; // points into fullname |
bikeNomad | 0:84aaade0de8f | 71 | actions_t actions; |
bikeNomad | 0:84aaade0de8f | 72 | }; |
bikeNomad | 0:84aaade0de8f | 73 | |
bikeNomad | 0:84aaade0de8f | 74 | #endif // __included_song_hpp |