Big Mouth Billy Bass automation library

Dependents:   BillyBass_with_SD

song.hpp

Committer:
bikeNomad
Date:
2013-06-18
Revision:
3:6c91a6232c4a
Parent:
2:eaba75af0f0d
Child:
4:f009306756b3

File content as of revision 3:6c91a6232c4a:

#ifndef __included_song_hpp
#define __included_song_hpp

#include <DirHandle.h>

#include "billybass.hpp"
#include "config.hpp"
#include "action.hpp"

class Song
{
public:
    typedef std::vector<Action> actions_t;

    // _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);
    }
    ~Song() {
        actions.clear();
    }
    
    BillyBass * myFish() { return BillyBass::bassNumber(whichFish); }
    bool isValid() const {
        return basename != 0 && whichFish != NO_FISH;
    }
    bool parseFilename(char const *_name);
    bool readActions();

    unsigned getSequenceNumber() const {
        return sequenceNumber;
    }
    unsigned getWhichFish() const {
        return whichFish;
    }
    char const *getSampleFileName() {
        if (!extension) return 0;
        strcpy(extension, sampleExtension);
        return fullname;
    }
    char const *getTextFileName() {
        if (!extension) return 0;
        strcpy(extension, textExtension);
        return fullname;
    }
    actions_t &getActions() {
        return actions;
    }

    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);
        }
    }

protected:

    static char const directoryName[ BASS_DIRECTORY_LENGTH + 1 ];
    static unsigned const NO_FISH;
    static char const *textExtension;
    static char const *sampleExtension;

    unsigned sequenceNumber;    // 0-relative
    unsigned whichFish;         // 0-relative
    char fullname[ MAX_PATH_LEN ];  // with directory name
    char *basename;     // points into fullname
    char *extension;    // points into fullname
    actions_t actions;
};

#endif                                 // __included_song_hpp