source: golgotha/src/golg/music.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.5 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "music.hh"
10#include "music/stream.hh"
11#include "string/string.hh"
12#include "file/file.hh"
13#include "memory/malloc.hh"
14
15g1_music_manager_class g1_music_man;
16
17void g1_music_manager_class::next_song()
18{
19  if (no_songs) return;
20 
21  song_on++;
22 
23  if (song_on>=total_songs)
24    song_on=0;
25
26  if (stream)
27  {
28    delete stream;
29    stream=0;
30  }
31
32  i4_const_str *slist=i4_string_man.get_array("songs");
33
34  if (!slist[song_on].null())
35  {
36    i4_file_class *fp=i4_open(slist[song_on], I4_SUPPORT_ASYNC | I4_READ);
37    if (fp)
38    {     
39      stream = new i4_stream_wav_player(fp, 512*1024,
40                                        i4_F,            // don't loop the song
41                                        i4_F);           // first load is not async
42      if (stream)
43      {
44        stream->set_volume(I4_SOUND_VOLUME_LEVELS*2/4);
45
46        if (!stream->poll())  // music probably doesn't work if we can't poll() once
47        {
48          delete stream;
49          stream=0;
50
51          total_missing++;
52          if (total_missing==total_songs) no_songs = i4_T;
53        }   
54      }
55    }
56    else
57    {
58      total_missing++;
59      if (total_missing==total_songs) no_songs = i4_T;
60    }
61  } 
62
63  i4_free(slist);   
64}
65
66void g1_music_manager_class::init()
67{
68  playing=i4_F;
69  no_songs=i4_F;
70  stream=0;
71  song_on=-1;
72
73  i4_const_str *slist=i4_string_man.get_array("songs");
74
75  total_missing = 0;
76
77  total_songs = 0;
78  for (sw32 i=0; !slist[i].null(); i++) total_songs++;
79
80  if (total_songs==0) no_songs = i4_T;
81
82  i4_free(slist);
83}
84
85void g1_music_manager_class::poll()
86{
87  if (stream)
88  {
89    if (//playing &&
90        !stream->poll())
91      next_song();
92  }
93  else
94    next_song();
95}
96
97void g1_music_manager_class::uninit()
98{
99  stop();
100}
101
102void g1_music_manager_class::start()
103{
104  if (!stream)
105  {   
106    next_song();
107    if (stream)
108      playing=i4_T;
109  }
110}
111
112void g1_music_manager_class::stop()
113{
114  if (stream)
115  {
116    delete stream;
117    stream=0;
118  }
119  playing=i4_F;
120}
121
Note: See TracBrowser for help on using the repository browser.