Advanced Strategic Command
music.cpp
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <SDL_mixer.h>
8 
9 #ifndef karteneditor
10 #include "sdl/sound.h"
11 #endif
12 
13 
14 #include "basestrm.h"
15 #include "stringtokenizer.h"
16 #include "music.h"
17 #include "itemrepository.h"
18 #include "dlg_box.h"
19 #include "textfile_evaluation.h"
20 #include "sgstream.h"
21 
22 
25 
26 void PlayListLoader::readTextFiles ( PropertyReadingContainer& prc, const ASCString& fileName, const ASCString& location )
27 {
28  MusicPlayList* mpl = new MusicPlayList;
29  mpl->runTextIO ( prc );
30 
31  mpl->filename = fileName;
32  mpl->location = location;
33  playLists.push_back ( mpl );
34 }
35 
37 {
38  readPointerContainer( playLists, stream );
39 }
40 
42 {
43  writePointerContainer( playLists, stream );
44 }
45 
46 
48 {
49  pc.addString( "Name", name );
50  pc.addStringArray( "Tracks", fileGroups );
51 
52  displayLogMessage ( 4, "Reading play list: " );
53 
54  reset();
55 }
56 
57 
59 {
60  int version = stream.readInt(); // version
61  if ( version != 1 ) fatalError ("invalid version for MusicPlayList" );
62  name = stream.readString();
63  filename = stream.readString();
64  location = stream.readString();
65  readClassContainer( fileGroups, stream );
66  reset();
67 }
68 
69 void MusicPlayList :: write ( tnstream& stream ) const
70 {
71  stream.writeInt( 1 );
72  stream.writeString ( name );
73  stream.writeString ( filename );
74  stream.writeString ( location );
75  writeClassContainer( fileGroups, stream );
76 }
77 
78 
80 {
81  if ( fileNameList.empty() ) {
82  static ASCString emptyString;
83  return emptyString;
84  }
85 
86  if ( iter == fileNameList.end() )
87  reset();
88 
89  return *(iter++);
90 }
91 
93 {
94  fileNameList.clear();
95 
96  for ( TrackList::iterator i = fileGroups.begin(); i != fileGroups.end(); i++ ) {
97  tfindfile ff ( *i );
98  int loc;
99  bool incontainer;
100  ASCString location,name;
101  name = ff.getnextname ( &loc, &incontainer, &location );
102  while ( !name.empty()) {
103  if ( !incontainer ) {
104  ASCString filename = location + pathdelimitterstring + name;
105  displayLogMessage ( 4, filename + ", " );
106  fileNameList.push_back ( filename );
107  }
108  name = ff.getnextname ( &loc, &incontainer, &location );
109  };
110  }
111  displayLogMessage ( 4, "Finished \n" );
112 
113  iter = fileNameList.begin();
114 }
115 
116 
118 {
119  ASCString text;
120 
121  text += "Play List location:\n";
122  text += location + "\n\n";
123 
124  text += "File Patterns:\n";
125  if ( fileGroups.empty() )
126  text += "-none-\n";
127  else
128  for ( TrackList::iterator i = fileGroups.begin(); i != fileGroups.end(); i++ )
129  text += *i + "\n";
130  text += "\n";
131 
132  text += "Found Files:\n";
133  if ( fileNameList.empty() )
134  text += "-none-\n";
135  else
136  for ( TrackList::iterator i = fileNameList.begin(); i != fileNameList.end(); i++ )
137  text += *i + "\n";
138  text += "\n";
139 
140  return text;
141 }
142 
143 void startMusic ()
144 {
145 #ifndef karteneditor
146  if ( !playLists.empty() )
147  SoundSystem::getInstance()->playMusic ( playLists.front() );
148  else
149  displayLogMessage ( 1, "No play lists available!\n" );
150 
151 #endif
152 }
153 
154 
155 
156 
157 
159  public :
161  virtual void setup(void);
162  virtual void buttonpressed(int id);
163  virtual void run(void);
164  virtual void get_text( int nr);
165  };
166 
168 {
169  action = 0;
170  title = "Select PlayList";
171  numberoflines = playLists.size();
172  ey = ysize - 90;
174  addbutton("~O~K",20,ysize - 80,xsize/2-5,ysize - 60,0,1,12,true);
175  addbutton("~C~ancel", xsize/2+5,ysize - 80,xsize-20,ysize - 60,0,1,14,true);
176  addkey ( 12, ct_enter );
177  addkey ( 14, ct_esc );
178 }
179 
180 
182 {
184  switch (id) {
185 
186  case 14: action = -1;
187  break;
188 
189  case 12: if ( redline >= 0) {
190 #ifndef karteneditor
191  SoundSystem::getInstance()->playMusic ( playLists[redline] );
192  action = 1;
193 #endif
194  } else
195  displaymessage ( "Please select a play list", 3);
196  break;
197  }
198 }
199 
200 
202 {
203  strcpy(txt,playLists[nr]->getName().c_str() );
204 }
205 
206 
208 {
209  do {
211  } while ( action == 0 );
212 }
213 
214 
216 {
217  PlayListSelector gps;
218 
219  gps.init();
220  gps.run();
221  gps.done();
222 }
223 
int startpos
Definition: dlg_box.h:420
void runTextIO(PropertyContainer &pc)
loads a PlayList from a .ASCTXT file
Definition: music.cpp:47
void startMusic()
start playing the first playlist
Definition: music.cpp:143
ASCString getDiagnosticText()
Definition: music.cpp:117
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
int numberoflines
Definition: dlg_box.h:420
void playMusic(MusicPlayList *playlist)
plays the pieces of music which are referenced in the playlist
Definition: sound.cpp:220
void init(void)
Definition: dlg_box.cpp:3424
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
A List containing several tracks of music.
Definition: music.h:19
int xsize
Definition: dlg_box.h:40
Functions to evaluate the parsed *.asctxt files.
virtual void run(void)
Definition: music.cpp:207
virtual void setup(void)
Definition: music.cpp:167
#define ct_enter
Definition: keysymbols.h:51
void read(tnstream &stream)
Definition: music.cpp:58
Interface for some basic classes from which all of ASC's dialogs are derived.
deallocating_vector< MusicPlayList * > PlayLists
Definition: music.cpp:23
The interface for all kinds of IO stream.
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual void buttonpressed(int id)
Definition: music.cpp:181
void addStringArray(const ASCString &name, vector< ASCString > &property)
int ysize
Definition: dlg_box.h:40
ASCString filename
Definition: music.h:31
void done(void)
Definition: dlg_box.cpp:3617
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
void reset()
resets the internal track iterator
Definition: music.cpp:92
static SoundSystem * getInstance()
Definition: sound.h:127
char txt[2000]
Definition: dlg_box.h:416
virtual void read(tnstream &stream)
Definition: music.cpp:36
A simple string tokenizer.
void displayLogMessage(int msgVerbosity, const char *message,...)
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
void addbutton(const char *ltxt, int lx1, int ly1, int lx2, int ly2, int lart, int lstyle, int lid, bool enabled)
Definition: dlg_box.cpp:471
#define ct_esc
Definition: keysymbols.h:43
void readPointerContainer(vector< BaseType * > &v, tnstream &stream)
Definition: basestrm.h:714
Searching for files.
Definition: basestrm.h:484
virtual void get_text(int nr)
Definition: music.cpp:201
The interface for the various streams that ASC offers, like file and memory streams.
const ASCString & getNextTrack()
returns the filename of the next music track
Definition: music.cpp:79
virtual void readTextFiles(PropertyReadingContainer &prc, const ASCString &fileName, const ASCString &location)
Definition: music.cpp:26
void selectPlayList()
opens a dialog to select a playlist
Definition: music.cpp:215
The IO for many basic classes and structurs of ACS.
void readClassContainer(C &c, tnstream &stream)
Definition: basestrm.h:752
void addkey(int id, tkey key)
Definition: dlg_box.cpp:774
virtual void write(tnstream &stream)
Definition: music.cpp:41
const char * pathdelimitterstring
Definition: unix/fileio.cpp:24
void write(tnstream &stream) const
Definition: music.cpp:69
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
a container that stores pointers and deletes the pointed-to objects on destruction ...
Definition: typen.h:314
void writeClassContainer(const C &c, tnstream &stream)
Definition: basestrm.h:742
void addString(const ASCString &name, ASCString &property)
virtual void buttonpressed(int id)
Definition: dlg_box.cpp:3476
void fatalError(const ASCString &string)
virtual void run(void)
Definition: dlg_box.cpp:3487
ASCString location
Definition: music.h:31
PlayLists playLists
Definition: music.cpp:24
const char * title
Definition: dlg_box.h:162
void writePointerContainer(const C &c, tnstream &stream)
Definition: basestrm.h:704