1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /*
- * This file is part of Soft Mood (https://notabug.org/alkeon/soft-mood).
- * Copyright (c) 2019 Alejandro "alkeon" Castilla
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "song.h"
- song::song(const string& file){
- Mix_VolumeMusic(0);
- _music = Mix_LoadWAV(file.c_str());
- if(!_music)
- cout << "Mixer couldn't load song: " << file << endl;
- Mix_VolumeChunk(_music, 0);
- if(!_music)
- cout << "Mixer couldn't change volume" << endl;
- _channel = Mix_PlayChannel(-1, _music, -1);
- if(_channel < 0)
- cout << "Mixer couldn't get a channel" << endl;
- }
- void song::set_volume(int volume){
- if(volume == 0 && Mix_Paused(_channel) == 1)
- Mix_Pause(_channel);
- else {
- _volume = volume;
- Mix_VolumeChunk(_music, _volume);
- }
- }
- void song::change_song(const string& file, int volume){
- Mix_HaltChannel(_channel);
- Mix_VolumeMusic(0);
- _music = Mix_LoadWAV(file.c_str());
- if(!_music)
- cout << "Mixer couldn't load song: " << file << endl;
- Mix_VolumeChunk(_music, volume);
- if(!_music)
- cout << "Mixer couldn't change volume" << endl;
- _channel = Mix_PlayChannel(_channel, _music, -1);
- if(_channel < 0)
- cout << "Mixer couldn't get a channel" << endl;
- }
|