Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include "bass.h"
  5.  
  6. using namespace std;
  7. int wybor;
  8. HSTREAM stream;      //Current
  9. HSTREAM oldstream;   //Last
  10. const int FLAG_NORMAL     = 1<<1;
  11. const int FLAG_INSTANT    = 1<<2;
  12.  
  13. void aCLog_AddLogEntry(string entry)
  14. {
  15.     fstream plik;
  16.     plik.open("SLib_LogFile.txt", ios::out | ios::app);
  17.     plik << entry << endl;
  18. }
  19.  
  20. void  Init_Bass()
  21. {
  22.     if(!BASS_Init(-1, 44100, 0, 0, 0))
  23.     {
  24.         BASS_Init(0, 44100, 0, 0, 0);
  25.     };
  26. }
  27.  
  28. void  aCMusic_SetVolume(float vol)
  29. {
  30.     Init_Bass();
  31.     BASS_ChannelSetAttribute(stream,BASS_ATTRIB_VOL,vol);
  32. }
  33.  
  34. void  aCMusic_FadeIn(float vol, int dur, bool reset)
  35. {
  36.     Init_Bass();
  37.     BASS_ChannelSetAttribute(stream,BASS_ATTRIB_VOL,0);
  38.     BASS_ChannelPlay(stream,reset);
  39.     BASS_ChannelSlideAttribute(stream,BASS_ATTRIB_VOL,vol, dur);
  40. }
  41.  
  42. void  aCMusic_FadeOut(int dur)
  43. {
  44.     Init_Bass();
  45.     BASS_ChannelSlideAttribute(stream,BASS_ATTRIB_VOL,0, dur);
  46.     Sleep(dur);
  47.     BASS_ChannelPause(stream);
  48. }
  49.  
  50. void  aCMusic_Stop()
  51. {
  52.     Init_Bass();
  53.     BASS_ChannelPause(stream);
  54. }
  55.  
  56. bool SoundWasFound(string file)
  57. {
  58.     string cs = "../_work/data/Music/" + file;
  59.     fstream plik;
  60.     plik.open(cs.c_str());
  61.     if(plik.good())
  62.         return true;
  63.     else
  64.         return false;
  65.  
  66. }
  67. void aCMusic_PlayMusic(string file, float vol, int flags)
  68. {
  69.     if(!SoundWasFound(file))
  70.     {
  71.       aCLog_AddLogEntry("skip - file not found");
  72.        return;
  73.     }
  74.  
  75.     Init_Bass();
  76.     //Sprawdzaæ czy stary strumieñ jest ten sam co nowy i wtedy odpalaæ od momentu zatrzymania :D
  77.     if((flags & FLAG_INSTANT))  {oldstream = stream;}   //Sprawdzaj czy muzyka ma zostaæ gwa³townie zmieniona
  78.  
  79.     stream = BASS_StreamCreateFile(false,file.c_str(),0,0,BASS_SAMPLE_LOOP);    //Update streamu
  80.  
  81.  
  82.     if((oldstream == stream)
  83.     && (flags & FLAG_NORMAL)) //Je¿eli stary stream to ten nowy to graj go od zatrzymanego momentu
  84.     {
  85.         aCMusic_FadeOut(4000);
  86.         stream = oldstream;
  87.         oldstream = 0;
  88.         aCMusic_FadeIn(vol,4000,false);
  89.         return;
  90.     }
  91.  
  92.     if((flags & FLAG_INSTANT))
  93.     {
  94.         aCLog_AddLogEntry("Push without fade in");
  95.         oldstream = stream; //Zapisz stary soundtrack - Czas odtwarzania
  96.         BASS_ChannelPause(stream);
  97.         BASS_ChannelPlay(stream,true);  //zagraj soundtrack od zera...
  98.     }
  99.     else
  100.     {
  101.         aCLog_AddLogEntry("Push without fade in");
  102.         aCMusic_FadeOut(4000);
  103.         aCMusic_FadeIn (vol,4000,true); //zagraj j¹ od zera
  104.     }
  105.  
  106.     do
  107.     {
  108.     }while(BASS_ChannelIsActive(stream));
  109.     BASS_Stop();
  110.     BASS_Free();
  111.  
  112. }
  113.  
  114.  
  115.  
  116.  
  117. int main()
  118. {
  119.     aCMusic_PlayMusic("pliczek.ogg",1,FLAG_NORMAL);
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement