Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

Committer:
bikeNomad
Date:
Mon Jun 17 22:17:59 2013 +0000
Revision:
0:84aaade0de8f
Child:
1:9b1f3eb204ac
Mostly working; hangs when reading actions

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 0:84aaade0de8f 13
bikeNomad 0:84aaade0de8f 14 typedef std::vector<Action> actions_t;
bikeNomad 0:84aaade0de8f 15
bikeNomad 0:84aaade0de8f 16 // _name is relative to BASS_DIRECTORY
bikeNomad 0:84aaade0de8f 17 // return a pointer to a fully read-in Song if valid
bikeNomad 0:84aaade0de8f 18 // also adds new song to songs
bikeNomad 0:84aaade0de8f 19 static Song *newSong(char const *_name);
bikeNomad 0:84aaade0de8f 20 static std::list<Song*> songs;
bikeNomad 0:84aaade0de8f 21 static unsigned readAllSongs(DIR *bassDir);
bikeNomad 0:84aaade0de8f 22 static void clearAllSongs();
bikeNomad 0:84aaade0de8f 23
bikeNomad 0:84aaade0de8f 24 Song() : sequenceNumber(0), whichFish(NO_FISH), basename(0), extension(0) {
bikeNomad 0:84aaade0de8f 25 fullname[0] = 0;
bikeNomad 0:84aaade0de8f 26 actions.reserve(60);
bikeNomad 0:84aaade0de8f 27 }
bikeNomad 0:84aaade0de8f 28
bikeNomad 0:84aaade0de8f 29 bool isValid() const {
bikeNomad 0:84aaade0de8f 30 return basename != 0 && whichFish != NO_FISH;
bikeNomad 0:84aaade0de8f 31 }
bikeNomad 0:84aaade0de8f 32 bool parseFilename(char const *_name);
bikeNomad 0:84aaade0de8f 33 bool readActions();
bikeNomad 0:84aaade0de8f 34
bikeNomad 0:84aaade0de8f 35 unsigned getSequenceNumber() const {
bikeNomad 0:84aaade0de8f 36 return sequenceNumber;
bikeNomad 0:84aaade0de8f 37 }
bikeNomad 0:84aaade0de8f 38 unsigned getWhichFish() const {
bikeNomad 0:84aaade0de8f 39 return whichFish;
bikeNomad 0:84aaade0de8f 40 }
bikeNomad 0:84aaade0de8f 41 char const *getSampleFileName() {
bikeNomad 0:84aaade0de8f 42 if (!extension) return 0;
bikeNomad 0:84aaade0de8f 43 strcpy(extension, sampleExtension);
bikeNomad 0:84aaade0de8f 44 return fullname;
bikeNomad 0:84aaade0de8f 45 }
bikeNomad 0:84aaade0de8f 46 char const *getTextFileName() {
bikeNomad 0:84aaade0de8f 47 if (!extension) return 0;
bikeNomad 0:84aaade0de8f 48 strcpy(extension, textExtension);
bikeNomad 0:84aaade0de8f 49 return fullname;
bikeNomad 0:84aaade0de8f 50 }
bikeNomad 0:84aaade0de8f 51 actions_t const &getActions() const {
bikeNomad 0:84aaade0de8f 52 return actions;
bikeNomad 0:84aaade0de8f 53 }
bikeNomad 0:84aaade0de8f 54
bikeNomad 0:84aaade0de8f 55 void print(Serial &pc) {
bikeNomad 0:84aaade0de8f 56 pc.printf("%s fish=%u seq=%u\r\n", getSampleFileName(), whichFish, sequenceNumber);
bikeNomad 0:84aaade0de8f 57 for (actions_t::const_iterator action_it = actions.begin(); action_it != actions.end(); action_it++) {
bikeNomad 0:84aaade0de8f 58 Action const &action = *action_it;
bikeNomad 0:84aaade0de8f 59 pc.printf("%0.02f %s %d\r\n", action.actionTime, action.outputName, action.desiredState ? 1 : 0);
bikeNomad 0:84aaade0de8f 60 }
bikeNomad 0:84aaade0de8f 61 }
bikeNomad 0:84aaade0de8f 62
bikeNomad 0:84aaade0de8f 63 protected:
bikeNomad 0:84aaade0de8f 64
bikeNomad 0:84aaade0de8f 65 static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ];
bikeNomad 0:84aaade0de8f 66 static unsigned const NO_FISH;
bikeNomad 0:84aaade0de8f 67 static char const *textExtension;
bikeNomad 0:84aaade0de8f 68 static char const *sampleExtension;
bikeNomad 0:84aaade0de8f 69
bikeNomad 0:84aaade0de8f 70 unsigned sequenceNumber; // 0-relative
bikeNomad 0:84aaade0de8f 71 unsigned whichFish; // 0-relative
bikeNomad 0:84aaade0de8f 72 char fullname[ MAX_PATH_LEN ]; // with directory name
bikeNomad 0:84aaade0de8f 73 char *basename; // points into fullname
bikeNomad 0:84aaade0de8f 74 char *extension; // points into fullname
bikeNomad 0:84aaade0de8f 75 actions_t actions;
bikeNomad 0:84aaade0de8f 76 };
bikeNomad 0:84aaade0de8f 77
bikeNomad 0:84aaade0de8f 78 #endif // __included_song_hpp