1 /* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm) 2 3 This file is part of KeeperRL. 4 5 KeeperRL is free software; you can redistribute it and/or modify it under the terms of the 6 GNU General Public License as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 10 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with this program. 14 If not, see http://www.gnu.org/licenses/ . */ 15 16 #pragma once 17 18 #include "util.h" 19 20 class Options; 21 class AudioDevice; 22 class SoundStream; 23 class FilePath; 24 25 enum class MusicType { INTRO, MAIN, PEACEFUL, BATTLE, NIGHT, ADV_PEACEFUL, ADV_BATTLE }; 26 27 class Jukebox { 28 public: 29 Jukebox(Options*, AudioDevice&, vector<pair<MusicType, FilePath>> tracks, float maxVolume, 30 map<MusicType, float> maxVolumes); 31 32 void setType(MusicType, bool now); 33 void toggle(bool on); 34 35 private: 36 void play(int index); 37 void setCurrent(MusicType); 38 void continueCurrent(); 39 bool turnedOff(); 40 void refresh(); 41 MusicType getCurrentType(); 42 43 typedef std::unique_lock<std::recursive_mutex> MusicLock; 44 std::recursive_mutex musicMutex; 45 46 vector<FilePath> music; 47 unique_ptr<SoundStream> stream; 48 map<MusicType, vector<int>> byType; 49 int current = 0; 50 int currentPlaying = 0; 51 bool on = false; 52 int numTracks = 0; 53 float getMaxVolume(int track); 54 float maxVolume; 55 map<MusicType, float> maxVolumes; 56 optional<MusicType> nextType; 57 optional<AsyncLoop> refreshLoop; 58 AudioDevice& audioDevice; 59 }; 60