Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include "bass.h"
- using namespace std;
- int wybor;
- HSTREAM stream; //Current
- HSTREAM oldstream; //Last
- const int FLAG_NORMAL = 1<<1;
- const int FLAG_INSTANT = 1<<2;
- void aCLog_AddLogEntry(string entry)
- {
- fstream plik;
- plik.open("SLib_LogFile.txt", ios::out | ios::app);
- plik << entry << endl;
- }
- void Init_Bass()
- {
- if(!BASS_Init(-1, 44100, 0, 0, 0))
- {
- BASS_Init(0, 44100, 0, 0, 0);
- };
- }
- void aCMusic_SetVolume(float vol)
- {
- Init_Bass();
- BASS_ChannelSetAttribute(stream,BASS_ATTRIB_VOL,vol);
- }
- void aCMusic_FadeIn(float vol, int dur, bool reset)
- {
- Init_Bass();
- BASS_ChannelSetAttribute(stream,BASS_ATTRIB_VOL,0);
- BASS_ChannelPlay(stream,reset);
- BASS_ChannelSlideAttribute(stream,BASS_ATTRIB_VOL,vol, dur);
- }
- void aCMusic_FadeOut(int dur)
- {
- Init_Bass();
- BASS_ChannelSlideAttribute(stream,BASS_ATTRIB_VOL,0, dur);
- Sleep(dur);
- BASS_ChannelPause(stream);
- }
- void aCMusic_Stop()
- {
- Init_Bass();
- BASS_ChannelPause(stream);
- }
- bool SoundWasFound(string file)
- {
- string cs = "../_work/data/Music/" + file;
- fstream plik;
- plik.open(cs.c_str());
- if(plik.good())
- return true;
- else
- return false;
- }
- void aCMusic_PlayMusic(string file, float vol, int flags)
- {
- if(!SoundWasFound(file))
- {
- aCLog_AddLogEntry("skip - file not found");
- return;
- }
- Init_Bass();
- //Sprawdzaæ czy stary strumieñ jest ten sam co nowy i wtedy odpalaæ od momentu zatrzymania :D
- if((flags & FLAG_INSTANT)) {oldstream = stream;} //Sprawdzaj czy muzyka ma zostaæ gwa³townie zmieniona
- stream = BASS_StreamCreateFile(false,file.c_str(),0,0,BASS_SAMPLE_LOOP); //Update streamu
- if((oldstream == stream)
- && (flags & FLAG_NORMAL)) //Je¿eli stary stream to ten nowy to graj go od zatrzymanego momentu
- {
- aCMusic_FadeOut(4000);
- stream = oldstream;
- oldstream = 0;
- aCMusic_FadeIn(vol,4000,false);
- return;
- }
- if((flags & FLAG_INSTANT))
- {
- aCLog_AddLogEntry("Push without fade in");
- oldstream = stream; //Zapisz stary soundtrack - Czas odtwarzania
- BASS_ChannelPause(stream);
- BASS_ChannelPlay(stream,true); //zagraj soundtrack od zera...
- }
- else
- {
- aCLog_AddLogEntry("Push without fade in");
- aCMusic_FadeOut(4000);
- aCMusic_FadeIn (vol,4000,true); //zagraj j¹ od zera
- }
- do
- {
- }while(BASS_ChannelIsActive(stream));
- BASS_Stop();
- BASS_Free();
- }
- int main()
- {
- aCMusic_PlayMusic("pliczek.ogg",1,FLAG_NORMAL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement