Skip to content

Commit

Permalink
add color playing to sound queue
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Oct 14, 2024
1 parent 1b7b7b4 commit d2ae53b
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions sound/sound_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ struct SoundToPlay {
Effect* effect_;
int selection_;

SoundToPlay() :filename_(nullptr), effect_(nullptr) {}
explicit SoundToPlay(const char* file) : filename_(file){ }
SoundToPlay() :filename_(nullptr), effect_(nullptr), selection_(-1) {}
explicit SoundToPlay(const char* file) : filename_(file) { }
SoundToPlay(Effect* effect, int selection = -1) : filename_(nullptr), effect_(effect), selection_(selection) {}
SoundToPlay(uint8_t R, uint8_t G, uint8_t B) :filename_(nullptr), effect_(nullptr), selection_((R << 16) + (G << 8) + B) {}
bool Play(BufferedWavPlayer* player) {
if (filename_) return player->PlayInCurrentDir(filename_);
effect_->Select(selection_);
player->PlayOnce(effect_);
return true;
}
if (filename_) {
return player->PlayInCurrentDir(filename_);
}
if (effect_) {
effect_->Select(selection_);
player->PlayOnce(effect_);
return true;
}
// color
char filename[32];
strcpy(filename, "colors/");
char* tmp = filename + strlen(filename);
int N = selection_;
for (int j = 0; j < 6; j++) {
*(tmp++) = "0123456789abcdef"[(N >> 20) & 0xf];
N <<= 4;
}
strcpy(tmp, ".wav");
return player->PlayInCurrentDir(filename);
}
bool isSet() {
return filename_ != nullptr || effect_ != nullptr;
return filename_ != nullptr || effect_ != nullptr || selection_ != -1;
}
};

Expand Down

0 comments on commit d2ae53b

Please sign in to comment.