' AF6ABFF78F36CE9471F843B7E3755EF3CF445CAE4E53DF5B65D007F82BABEDCD5673AD6406CDD40797864A209CFB762468B376CCC79EC30AE3C5FFD26BF6613D ' sRipeTech ' 4D56B50924 2024-07-03 18:25:14 ' ------------------------------------ ' 2024-07-03 ' A script for pwScripter ' Playing a WAV / MID file using the MCI interfaces of the winmm DLL. ' ' To get help for a command, e.g. xyz, enter ' help("xyz') ' on the Command Line ' ' ------------------------------------ ' delete any current user defined script/variables/functions ... newscript ' break$flag = true ' ------------------------------------ ' link to the DLL Winmm ' (open DLLs are automatically closed when the next newscript command executes). dim myDLL = dll.open ("winmm") IF ( ! myDLL ) THEN Message ( "Could not open the DLL file" ) STOP END IF ' ------------------------------------ ' link to some MCI functions in that DLL ' Since pwScripter uses wide-character we need to link to the "W" version not then "A" versions ' MCIERROR mciSendString( LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback ); dim mciSendString = dll.link( myDLL, "mciSendStringW" ,4,"unsigned" ) ' BOOL mciGetErrorString( DWORD fdwError, LPTSTR lpszErrorText, UINT cchErrorText ); dim mciGetErrorString = dll.link( myDLL, "mciGetErrorStringW",3,"unsigned" ) ' ------------------------------------ ' Some programming languages set a function's return value by ' assigning the appropriate value to the name of the function. ' e.g. ' function SQ ( p0 ) ' sq = p0 * p0 ' end function ' pwScripter supports this approach. ' ' AND pwScripter supports the following approach: ' function SQ ( p0 ) ' returnValue = p0 * p0 ' end function ' Why? Because IF you need to change the name of a function, then using returnValue is function name indpendent! ' Laziness! ' Technically returnValue and SQ are, in the above examples, fully interchangeable. ' Here another version of SQ but with some error handling ' function SQ ( p0 ) ' if ISNUMERICAL ( p0 ) then ' returERnValue = p0 * p0 ' else ' sq = 0 ' end if ' end function FUNCTION mciPlay ( fileName ) returnValue = 1 ' implies error mciSendString ( "close WAVE", 0 ,0 , 0 ) mciSendString ( "close MIDI", 0 ,0 , 0 ) IF ( ! (isFile ( filename) == 1) ) then Report ("Error: " & filename & " is not a file or is not accessible") EXIT function END if ' get the extension used by the input file dim ext = right ( filename , length( filename ) - inStrRev( filename , ".") ) ' mciSendString needs the \ in a file path to be doubled ' e.g. c:\windows\system32 needs to be c:\\windows\\system32 ' note that the pwScripter command line reader treats \ as an ' escape character. ' the 2 character combination \" would embed a " into a string ' the 2 character combination \\ would embed a \ into a string ' Thats why the next line may LOOK strange. fileName = Replace ( fileName , "\\" , "\\\\" ) ' again we use a 2 character combination in this case \" ' which embeds a " into a string dim cmd = "Open " & "\"" & filename & "\"" ' note: == is case insensitive for strings, for case sensitive use CEQU IF ( ext == "wav" ) then cmd = cmd & " type waveaudio alias WAVE" returnValue = mciSendString ( cmd, 0 ,0 , 0 ) IF ! returnValue then returnValue = mciSendString ( "play WAVE", 0 ,0 , 0 ) END IF ELSEIF ( ext == "mid" ) then cmd = cmd & " type sequencer alias MIDI" returnValue = mciSendString ( cmd, 0 ,0 , 0 ) IF ! returnValue then returnValue = mciSendString ( "play MIDI", 0 ,0 , 0 ) END IF END if IF ( returnValue ) then report ( "Error:" & returnValue & " when handling: " & cmd ) END IF END function dim SoundFile ' ------------------------------------ ' 1) using hardcoded values ' WAV ' You MUST set this as appropriate for your system, and preferred wave file ' ------------------------------------------------------------------------------------------ break "About to play a LOCAL wav file. Check that the soundfile exists" ' ------------------------------------------------------------------------------------------ SoundFile = "C:\Users\george\Desktop\pwScripter\Future V7_1-64bit core\Publish\Demos\Trumpet1.wav" mciPlay (SoundFile) sleep (1000) ' ------------------------------------------------------------------------------------------ break "About to play a LOCAL mid file. Check that the soundfile exists" ' ------------------------------------------------------------------------------------------ ' MID ' You MUST set this as appropriate for your system, and preferred midi file SoundFile = "C:\Users\george\Desktop\pwScripter\Future V7_1-64bit core\Publish\Demos\town.mid" mciPlay (SoundFile) sleep (3000) ' ------------------------------------ ' if playing has NOT stopped by the time we get here then force it to stop mciSendString ( "close WAVE", 0 ,0 , 0 ) mciSendString ( "close MIDI", 0 ,0 , 0 )