Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126727
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/music-player.cpp b/util/music-player.cpp
new file mode 100644
index 00000000..c658dce7
--- /dev/null
+++ b/util/music-player.cpp
@@ -0,0 +1,95 @@
+#include "music-player.h"
+#include "globals.h"
+#include <iostream>
+
+#ifdef USE_ALLEGRO
+#include "dumb/include/aldumb.h"
+
+#ifdef _WIN32
+#include <winalleg.h>
+#endif
+
+#endif
+
+namespace Util{
+
+MusicPlayer::MusicPlayer(){
+}
+
+MusicPlayer::~MusicPlayer(){
+}
+
+#ifdef USE_ALLEGRO
+
+static const char * typeToExtension( int i ){
+ switch (i){
+ case 0 : return ".xm";
+ case 1 : return ".s3m";
+ case 2 : return ".it";
+ case 3 : return ".mod";
+ default : return "";
+ }
+}
+
+DumbPlayer::DumbPlayer(const char * path):
+volume(1.0){
+ for (int i = 0; i < 4; i++){
+ /* the order of trying xm/s3m/it/mod matters because mod could be
+ * confused with one of the other formats, so load it last.
+ */
+ switch (i){
+ case 0 : {
+ music_file = dumb_load_xm_quick(path);
+ break;
+ }
+ case 1 : {
+ music_file = dumb_load_s3m_quick(path);
+ break;
+ }
+ case 2 : {
+ music_file = dumb_load_it_quick(path);
+ break;
+ }
+ case 3 : {
+ music_file = dumb_load_mod_quick(path);
+ break;
+ }
+ }
+
+ if ( music_file != NULL ){
+ Global::debug(0) << "Loaded " << path << " type " << typeToExtension( i ) << "(" << i << ")" << std::endl;
+ break;
+ }
+ }
+
+ if (music_file){
+ int buf = 1 << 11;
+ player = al_start_duh(music_file, 2, 0, volume, buf, 22050);
+ }
+}
+
+void DumbPlayer::play(){
+ al_resume_duh(this->player);
+}
+
+void DumbPlayer::poll(){
+ if (al_poll_duh(this->player) != 0){
+ }
+}
+
+void DumbPlayer::pause(){
+ al_pause_duh(this->player);
+}
+
+void DumbPlayer::setVolume(int volume){
+ al_duh_set_volume(player, volume);
+}
+
+DumbPlayer::~DumbPlayer(){
+ al_stop_duh(player);
+ unload_duh(music_file);
+}
+
+#endif
+
+}
diff --git a/util/music-player.h b/util/music-player.h
new file mode 100644
index 00000000..9608675d
--- /dev/null
+++ b/util/music-player.h
@@ -0,0 +1,43 @@
+#ifndef _paintown_music_player_h
+#define _paintown_music_player_h
+
+struct DUH;
+#ifdef USE_ALLEGRO
+struct AL_DUH_PLAYER;
+#endif
+
+namespace Util{
+
+class MusicPlayer{
+public:
+ MusicPlayer();
+ virtual void play() = 0;
+ virtual void poll() = 0;
+ virtual void pause() = 0;
+ virtual void setVolume(int volume) = 0;
+ virtual ~MusicPlayer();
+};
+
+/* interface to DUMB, plays mod/s3m/xm/it */
+class DumbPlayer: public MusicPlayer {
+public:
+ DumbPlayer(const char * path);
+ virtual void play();
+ virtual void poll();
+ virtual void pause();
+ virtual void setVolume(int volume);
+
+ virtual ~DumbPlayer();
+
+protected:
+#ifdef USE_ALLEGRO
+ AL_DUH_PLAYER * player;
+#endif
+ DUH * music_file;
+
+ double volume;
+};
+
+}
+
+#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:44 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69090
Default Alt Text
(3 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline