wxSound

BlitzMax Modules Forums/Brucey's Modules/wxSound

Create in BlitzMax/mod/wx.mod/ a new directory "wxsound.mod" and in this directory you put the following 4 files:
glue.h
/*
  Copyright (c) 2007,2008 Bruce A Henderson & Oliver Skawronek
 
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/ 

#include "wxglue.h"
#include "wx/sound.h"

class MaxSound;

extern "C" {

#include <blitz.h>
	MaxSound * bmx_wxsound_create(BBObject * handle, BBString * fileName, bool isResource);
	bool bmx_wxsound_isok(wxSound * sound);
	// bool bmx_wxsound_isplaying(wxSound * sound);
	bool bmx_wxsound_play(wxSound * sound, unsigned flags);
	void bmx_wxsound_stop(wxSound * sound);
	void bmx_wxsound_free(wxSound * sound);
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


class MaxSound : public wxSound
{
public:
	MaxSound(BBObject * handle, BBString * fileName, bool isResource);
	~MaxSound();

private:
	BBObject * maxHandle;


};


glue.cpp
/*
  Copyright (c) 2007,2008 Bruce A Henderson & Oliver Skawronek
 
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/ 

#include "glue.h"

// ---------------------------------------------------------------------------------------


MaxSound::MaxSound(BBObject * handle, BBString * fileName, bool isResource)
	: maxHandle(handle), wxSound(wxStringFromBBString(fileName), isResource)
{
	wxbind(this, handle);
}

MaxSound::~MaxSound() {
	wxunbind(this);
}

// *********************************************


MaxSound * bmx_wxsound_create(BBObject * handle, BBString * fileName, bool isResource) {
	return new MaxSound(handle, fileName, isResource);
}

bool bmx_wxsound_isok(wxSound * sound) {
	return sound->IsOk();
}

/*
bool bmx_wxsound_isplaying(wxSound * sound) {
	return sound->IsPlaying();
}
*/

bool bmx_wxsound_play(wxSound * sound, unsigned flags) {
	return sound->Play(flags);
}

void bmx_wxsound_stop(wxSound * sound) {
	return sound->Stop();
}

void bmx_wxsound_free(wxSound * sound) {
	delete sound;
}


common.bmx
' Copyright (c) 2007,2008 Bruce A Henderson & Oliver Skawronek
' 
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
' 
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
' THE SOFTWARE.
' 
SuperStrict

Import wx.wx
Import BRL.Blitz


' headers :-)
?linux
Import "../lib/linux/wx/include/gtk2-unicode-release-static/*.h"
Import "../include/*.h"
?win32
Import "../lib/win32/mswu/*.h"
Import "../include/*.h"
?macosppc
Import "../lib/macosppc/wx/include/mac-unicode-release-static/*.h"
Import "../include/*.h"
?macosx86
Import "../lib/macosx86/wx/include/mac-unicode-release-static/*.h"
Import "../include/*.h"
?

Import "glue.cpp"

Extern
	Function bmx_wxsound_create:Byte Ptr(handle:Object, fileName:String, isResource:Int=False)
	Function bmx_wxsound_isok:Int(handle:Byte Ptr)
	'Function bmx_wxsound_isplaying:Int(handle:Byte Ptr)
	Function bmx_wxsound_play:Int(handle:Byte Ptr, flags:Int=wxSOUND_ASYNC)
	Function bmx_wxsound_stop(handle:Byte Ptr)
	Function bmx_wxsound_free(handle:Byte Ptr)
End Extern

Const wxSOUND_SYNC  : Int = 0
Const wxSOUND_ASYNC : Int = 1
Const wxSOUND_LOOP  : Int = 2


wxsound.bmx
' Copyright (c) 2007,2008 Bruce A Henderson & Oliver Skawronek
' 
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
' 
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
' THE SOFTWARE.
' 
SuperStrict

Rem
bbdoc: wxSound
End Rem
Module wx.wxSound

ModuleInfo "Version: 1.00"
ModuleInfo "License: MIT"
ModuleInfo "Author: Bruce A Henderson"
ModuleInfo "Copyright: (c) 2007 Bruce A Henderson"
ModuleInfo "Modserver: BRL"

?linux
ModuleInfo "CC_OPTS: -D__WXGTK__"
ModuleInfo "CC_OPTS: -D_FILE_OFFSET_BITS=64"
ModuleInfo "CC_OPTS: -D_LARGE_FILES"
ModuleInfo "CC_OPTS: -DWX_PRECOMP"
?win32
ModuleInfo "CC_OPTS: -DHAVE_W32API_H"
ModuleInfo "CC_OPTS: -D__WXMSW__"
ModuleInfo "CC_OPTS: -D_UNICODE"
ModuleInfo "CC_OPTS: -DUNICODE"
?macos
ModuleInfo "CC_OPTS: -D__WXMAC__"
ModuleInfo "CC_OPTS: -D_FILE_OFFSET_BITS=64"
ModuleInfo "CC_OPTS: -D_LARGE_FILES"
ModuleInfo "CC_OPTS: -DWX_PRECOMP"
?

Import "common.bmx"

Rem
bbdoc: This class represents a short sound.
about: This class represents a short sound (loaded from Windows WAV file),
that can be stored in memory and played. Currently this class is implemented on
Windows and Unix (and uses either Open Sound System or Simple DirectMedia Layer).
End Rem
Type wxSound Extends wxObject

	' creates a "soft link" to a wxMenu*
	Function _create:wxSound(wxObjectPtr:Byte Ptr)
		If wxObjectPtr Then
			Local this:wxSound = New wxSound
			this.wxObjectPtr = wxObjectPtr
			Return this
		End If
	End Function
	
	Function _find:wxSound(wxObjectPtr:Byte Ptr)
		If wxObjectPtr Then
			Local sound:wxSound = wxSound(wxfind(wxObjectPtr))
			If Not sound Then
				Return _create(wxObjectPtr)
			End If
			Return sound
		End If
	End Function

	Rem
	bbdoc: Constructs a #wxSound object.
	about: TODO
	End Rem
	Function CreateSound:wxSound(fileName:String, isResource:Int=False)
		Return New wxSound.Create(fileName, isResource)
	End Function

	Rem
	bbdoc: 
	End Rem
	Method Create:wxSound(fileName:String, isResource:Int=False)
		wxObjectPtr = bmx_wxsound_create(Self, fileName, isResource)
		Return Self
	End Method
	
	Rem
	bbdoc: Returns true if the object contains a successfully loaded file or resource, false otherwise.
	about: TODO
	End Rem
	Method IsOk:Int()
		Return bmx_wxsound_isok(wxObjectPtr)
	End Method

'	Rem
'	bbdoc: Returns True If the Object contains a successfully loaded file Or resource, False otherwise.
'	about: TODO
'	End Rem
'	Method IsPlaying:Int()
'		Return bmx_wxsound_isplaying(wxObjectPtr)
'	End Method

	Rem
	bbdoc: Returns true if a sound is played at the moment.
	about: This method is currently not implemented under Windows.
	End Rem
	Method Play:Int(flags:Int = wxSOUND_ASYNC)
		Return bmx_wxsound_play(wxObjectPtr, flags)
	End Method

	Rem
	bbdoc: If a sound is played, this function stops it.
	about: TODO
	End Rem
	Method Stop()
		bmx_wxsound_stop(wxObjectPtr)
	End Method

	Rem
	bbdoc: Deletes this Sound
	End Rem
	Method Free()
		If wxObjectPtr Then
			bmx_wxsound_free(wxObjectPtr)
			wxObjectPtr = Null
		End If
	End Method
	
End Type


After compiling you can test it:
SuperStrict

Framework wx.wxApp
Import wx.wxSound

Type Application Extends wxApp
	Field Sound : wxSound
	
	Method OnInit:Int()
		Sound = New wxSound.Create("Test.wav")
		DebugLog Sound.IsOk()
		DebugLog Sound.Play()

		Return True
	End Method

End Type

New Application.Run()
End


cu olli