1 //----------------------------------------------------------------------------- 2 // Copyright (c) 2015-2018 Marcelo Fernandez 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a copy 5 // of this software and associated documentation files (the "Software"), to 6 // deal in the Software without restriction, including without limitation the 7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 // sell copies of the Software, and to permit persons to whom the Software is 9 // furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 // IN THE SOFTWARE. 21 //----------------------------------------------------------------------------- 22 23 #ifndef __OAMLMUSICTRACK_H__ 24 #define __OAMLMUSICTRACK_H__ 25 26 class ByteBuffer; 27 class oamlAudio; 28 29 class oamlMusicTrack : public oamlTrack { 30 private: 31 bool playing; 32 int playingOrder; 33 int maxPlayOrder; 34 35 unsigned int filesSamples; 36 unsigned int tailPos; 37 38 std::vector<oamlAudio*> loopAudios; 39 std::vector<oamlAudio*> randAudios; 40 std::vector<oamlAudio*> condAudios; 41 std::vector<oamlAudio*> introAudios; 42 43 int curAudio; 44 int tailAudio; 45 int fadeAudio; 46 int playCondAudio; 47 int playCondSamples; 48 49 oamlAudio* GetAudioByTypeId(int type, int id); 50 oamlAudio* GetCurAudio(); 51 oamlAudio* GetTailAudio(); 52 oamlAudio* GetFadeAudio(); 53 54 int PickNextAudio(); 55 56 void SetCurAudio(int type, int id); 57 58 void PlayNext(); 59 void PlayCond(int audio); 60 void PlayCondWithMovement(int audio); 61 void XFadePlay(); 62 63 void SaveAudioState(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement *node, const char *nodeName, std::vector<oamlAudio*> *audios); 64 void LoadAudioState(tinyxml2::XMLElement *node, std::vector<oamlAudio*> *audios); 65 void _SetLayerGain(std::vector<oamlAudio*> *audios, std::string layer, float gain); 66 67 public: 68 oamlMusicTrack(bool _verbose); 69 ~oamlMusicTrack(); 70 71 void GetAudioList(std::vector<std::string>& list); 72 void AddAudio(oamlAudio *audio); 73 oamlAudio* GetAudio(std::string filename); 74 oamlRC RemoveAudio(std::string filename); 75 oamlRC Play(int mainCondValue); 76 oamlRC Load(); 77 float LoadProgress(); 78 void Stop(); 79 80 bool IsPlaying(); 81 void ShowPlaying(); 82 std::string GetPlayingInfo(); 83 84 void Mix(float *samples, int channels, bool debugClipping); 85 86 void SetCondition(int id, int value); 87 88 bool IsMusicTrack() const { return true; } 89 90 void ReadInfo(oamlTrackInfo *info); 91 92 void SetLayerGain(std::string layer, float gain); 93 94 void SaveState(tinyxml2::XMLDocument &doc, tinyxml2::XMLElement *node); 95 void LoadState(tinyxml2::XMLElement *node); 96 97 void FreeMemory(); 98 }; 99 100 #endif 101