Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

BASS Library - extreme AHK multimedia power!


  • Please log in to reply
102 replies to this topic
closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
Webster14

you can try this if you change the filename !:
#Include bass.ahk     

BASS_Load()

file=%A_ScriptDir%\air.mp3

hStream := DllCall("BASS\BASS_StreamCreateFile", UInt,0, UInt,&File, UInt64,0, UInt64,0, UInt,0)
ErrorLevel := BASS_ErrorGetCode()


msgbox ,%errorlevel%

Bass_free()


  • Guests
  • Last active:
  • Joined: --
Hey guys I'm still trying to figure out out to play a midi...

All I can tell is that the following doesn't work
#include bass.ahk
#include bassmidi.ahk

BASS_Load()
BASS_Init()
BASS_MIDI_Init()

sfont:= BASS_MIDI_FontInit("CT4MGM.SF2",0)

BASS_StreamFree(stream)
stream:=BASS_MIDI_StreamCreateFile(false,"test.mid",0,0,0x80000000,44100) ; 0x80000000 BASS_Unicode

BASS_MIDI_StreamSetFonts(stream, sfont, 1)

BASS_ChannelPlay(stream,1)
return

exit:
  BASS_Free()
  BASS_MIDI_Free()
	ExitApp


lemo
  • Guests
  • Last active:
  • Joined: --
Btw I did the same test as Emmanuel
#include bass.ahk
#include bassmidi.ahk

BASS_Load()
BInit:=BASS_Init()
BInitM:=BASS_MIDI_Init()

msgbox,BInit: %BInit%`nBInitM: %BInitM%
BInit ->1
BIinitM -> returns nothing ?

Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
Mp3 working version (slightly modified from here)
#SingleInstance Force
#Persistent
SetBatchLines,-1
Thread, NoTimers
onexit, exit
#include bass.ahk

; Caller must ensure sufficient space at DestPtr.
CopyAnsiToUnicode(Source, DestPtr, Len)
{   ; Not sure how well this works on 9x/ME:
    return DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &Source, "int", Len + 1, "Uint", DestPtr, "int", Len + 1)
}


BASS_Load()
BASS_Init()

Filter := *
; Convert pipe-delimited ANSI filter string to null-delimited Unicode string.
VarSetCapacity(wFilter, StrLen(Filter)*2+2)
ptr := &wFilter
Loop, Parse, Filter, |
    ptr += 2 * CopyAnsiToUnicode(A_LoopField, ptr, StrLen(A_LoopField))
NumPut(0, ptr+0, "short")
VarSetCapacity(wFile,(nMaxFile:=65535)*2)
; Initialize filename to empty unicode string.
NumPut(0, wFile, "short")
VarSetCapacity(ofn, 88, 0)
if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME
  NumPut(76, ofn)
else NumPut(88, ofn)
NumPut(&wFilter, ofn, 12)
NumPut(&wFile, ofn, 28)
NumPut(nMaxFile, ofn, 32)
NumPut((OFN_HIDEREADONLY:=0x4)|(OFN_EXPLORER:=0x80000), ofn, 52)
; Unicode support on 9x/ME (WIN32_WINDOWS) by Lexikos
DllCall((A_OSType="WIN32_WINDOWS" ? "unicows" : "comdlg32") . "\GetOpenFileNameW", "uint", &ofn)



BASS_StreamFree(stream)
stream:=BASS_StreamCreateFile(false,&wFile,0,0,0x80000000) ; 0x80000000 BASS_Unicode

BASS_ChannelPlay(stream,1)
return

exit:
  BASS_Free()
	ExitApp

I tried to replace with Midi but it doesn't work
#SingleInstance Force
#Persistent
SetBatchLines,-1
Thread, NoTimers
onexit, exit
#include bass.ahk

; Caller must ensure sufficient space at DestPtr.
CopyAnsiToUnicode(Source, DestPtr, Len)
{   ; Not sure how well this works on 9x/ME:
    return DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &Source, "int", Len + 1, "Uint", DestPtr, "int", Len + 1)
}


BASS_Load()
BASS_Init()
[color=red]BASS_MIDI_Init()[/color]

Filter := *
; Convert pipe-delimited ANSI filter string to null-delimited Unicode string.
VarSetCapacity(wFilter, StrLen(Filter)*2+2)
ptr := &wFilter
Loop, Parse, Filter, |
    ptr += 2 * CopyAnsiToUnicode(A_LoopField, ptr, StrLen(A_LoopField))
NumPut(0, ptr+0, "short")
VarSetCapacity(wFile,(nMaxFile:=65535)*2)
; Initialize filename to empty unicode string.
NumPut(0, wFile, "short")
VarSetCapacity(ofn, 88, 0)
if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME
  NumPut(76, ofn)
else NumPut(88, ofn)
NumPut(&wFilter, ofn, 12)
NumPut(&wFile, ofn, 28)
NumPut(nMaxFile, ofn, 32)
NumPut((OFN_HIDEREADONLY:=0x4)|(OFN_EXPLORER:=0x80000), ofn, 52)
; Unicode support on 9x/ME (WIN32_WINDOWS) by Lexikos
DllCall((A_OSType="WIN32_WINDOWS" ? "unicows" : "comdlg32") . "\GetOpenFileNameW", "uint", &ofn)



BASS_StreamFree(stream)
[color=red]stream:=BASS_MIDI_StreamCreateFile(false,&wFile,0,0,0x80000000,44100) ; 0x80000000 BASS_Unicode[/color]

BASS_ChannelPlay(stream,1)
return

exit:
  BASS_Free()
[color=red]  BASS_MIDI_Free()[/color]
	ExitApp

K3ph is obviously not on this forum anymore, so if anyone can help it's great

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
this is what i use to test:
#SingleInstance force
Msgbox,% "BASS_DLLCALL: " 			BASS_DLLCALL		:= DllCall("LoadLibrary","str",A_ScriptDir "\bass.dll")
Msgbox,% "BASS_MIDI_DLLCALL: " 		BASS_MIDI_DLLCALL	:= DllCall("LoadLibrary", "str",A_ScriptDir "\bassmidi.dll")
Msgbox,% "BASS_Init: " 				DllCall(A_ScriptDir . "\bass.dll\BASS_Init",Int,-1,Int,44100,Int,0,UInt,0,UInt,0)
Msgbox,% "BASS_MIDI_HANDLE: "		BASS_MIDI_HANDLE		:=  DllCall(A_ScriptDir "\bass.dll\BASS_PluginLoad", "str", A_ScriptDir "\bassmidi.dll", UInt, 0)
File=D:\Beethoven's Fur Elise.mid
; Msgbox,% "BASS_MIDI_StreamCreateFile: " hMedia:= DllCall(A_ScriptDir "\bassmidi.dll\BASS_MIDI_StreamCreateFile", UInt, False, UInt, &file, UInt64, 0, UInt64, 0, UInt, 0, UInt, 0)
Msgbox,% "BASS_MIDI_StreamCreateFile: " hMedia:= DllCall(A_ScriptDir "\bassmidi.dll\BASS_MIDI_StreamCreateFile", UInt, False, UInt, &file, UInt64, 0, UInt64, 0, UInt, 0, UInt, 44100)
if !hMedia {
	Msgbox,% "Failed to load:`n""" Track_%nr%_path """"
	Return
	}
Msgbox,% "BASS_ChannelPlay: " DllCall(A_ScriptDir . "\bass.dll\BASS_ChannelPlay", UInt,hMedia, Int,1, Cdecl Int)
return
esc::
	DllCall(A_ScriptDir "\bass.dll\BASS_PluginFree", UInt, BASS_WMA_HANDLE)
	DllCall(A_ScriptDir "\bass.dll\BASS_Free")
	DllCall("FreeLibrary", UInt, BASS_MIDI_DLLCALL)
	DllCall("FreeLibrary", UInt, BASS_DLLCALL)
	reload
	return
put your dll's in scriptdir change "File=D:\Beethoven's Fur Elise.mid"
and look, no errors
but also no sound

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
hey emmanuel thx for posting

wow you're doing the dll calls directly without bass.ahk that's neat
when I change it to my File=test.mid, I have your Failed to load:"" error
and of course no sound indeed :p

did you try some BASS_ErrorGetCode before?
on the thread I told you about on BASS forums, we noticed with Ian that the problem may be the midi plugin that fails to load

#include bass.ahk
BASS_Load()
a:=BASS_ErrorGetCode()
msgBox, BASS_Load:%a%

BASS_Init()
b:=BASS_ErrorGetCode()
msgBox, BASS_Init:%b%

BASS_MIDI_Init()
c:=BASS_ErrorGetCode()
msgBox, BASS_MIDI_Init:%c%

BASS_Load:0
BASS_Init:0
BASS_MIDI_Init:2 (<-aka BASS_ERROR_FILEOPEN)

I'm currently investigating around that :roll:

I'll drop the link here too
<!-- m -->http://www.un4seen.c.../?topic=12717.0<!-- m -->

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009

when I change it to my File=test.mid, I have your Failed to load:"" error

put the full path there eg: c:\test.mid

and i dont have any error that's the hole problem:
#SingleInstance force
Msgbox,% "BASS_DLLCALL: " 			BASS_DLLCALL		:= DllCall("LoadLibrary","str",A_ScriptDir "\bass.dll")
Msgbox,% "BASS_MIDI_DLLCALL: " 		BASS_MIDI_DLLCALL	:= DllCall("LoadLibrary", "str",A_ScriptDir "\bassmidi.dll")
Msgbox,% "BASS_Init: " 				DllCall(A_ScriptDir . "\bass.dll\BASS_Init",Int,-1,Int,44100,Int,0,UInt,0,UInt,0)
Msgbox,% "BASS_MIDI_HANDLE: "		BASS_MIDI_HANDLE		:=  DllCall(A_ScriptDir "\bass.dll\BASS_PluginLoad", "str", A_ScriptDir "\bassmidi.dll", UInt, 0)
File=D:\Beethoven's Fur Elise.mid
; Msgbox,% "BASS_MIDI_StreamCreateFile: " hMedia:= DllCall(A_ScriptDir "\bassmidi.dll\BASS_MIDI_StreamCreateFile", UInt, False, UInt, &file, UInt64, 0, UInt64, 0, UInt, 0, UInt, 0)
Msgbox,% "BASS_MIDI_StreamCreateFile: " hMedia:= DllCall(A_ScriptDir "\bassmidi.dll\BASS_MIDI_StreamCreateFile", UInt, False, UInt, &file, UInt64, 0, UInt64, 0, UInt, 0, UInt, 44100)
Msgbox,% "BASS_ErrorGetCode: " DllCall(A_ScriptDir "\bass.dll\BASS_ErrorGetCode", Int)
if !hMedia {
	Msgbox,% "Failed to load:`n""" Track_%nr%_path """"
	Return
	}
Msgbox,% "BASS_ChannelPlay: " DllCall(A_ScriptDir . "\bass.dll\BASS_ChannelPlay", UInt,hMedia, Int,1, Cdecl Int)
return
esc::
	DllCall(A_ScriptDir "\bass.dll\BASS_PluginFree", UInt, BASS_WMA_HANDLE)
	DllCall(A_ScriptDir "\bass.dll\BASS_Free")
	DllCall("FreeLibrary", UInt, BASS_MIDI_DLLCALL)
	DllCall("FreeLibrary", UInt, BASS_DLLCALL)
	reload
	return

BASS_MIDI_Init:2 (<-aka BASS_ERROR_FILEOPEN)

looks like your dll is in the wrong place , or your includes, look in the file bass.ahk for the propper locations

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
Yeah my locations are fine, bass.ahk says everything's in the script folder.
Also my test.mid is in there too so File=test.mid should be right I suppose
The full path gives me the same thing (and BASS_ErrorGetCode:2)

Did you see the last post on BASS forums?
Actually I don't have that BASS_ERROR_FILEOPEN error anymore (for bassmidi.dll) now that I've specified BASS_UNICODE
Maybe there's a mess in the whole thing around that ANSI/UNICODE stuff

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009

Maybe there's a mess in the whole thing around that ANSI/UNICODE stuff

wouldn't know about that, I'm still using the old ahk for my player.
try using my code on the old ahk. and see then, no error , and no sound

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
Well with the basic AHK, I'm getting no error from GetErrorCode
But still your "Failed to load" stuff
Apparently you did that before, but I'll try again to get in touch with skwire from Trout player :roll:

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
when i doo this:
#SingleInstance force
BASS_DLLCALL		:= DllCall("LoadLibrary","str",A_ScriptDir "\bass.dll")
BASS_MIDI_DLLCALL	:= DllCall("LoadLibrary", "str",A_ScriptDir "\bassmidi.dll")
BASS_Init			:= DllCall(A_ScriptDir . "\bass.dll\BASS_Init",Int,-1,Int,44100,Int,0,UInt,0,UInt,0)
BASS_MIDI_HANDLE	:=  DllCall(A_ScriptDir "\bass.dll\BASS_PluginLoad", "str", A_ScriptDir "\bassmidi.dll", UInt, 0)
File				:=A_ScriptDir "\test Beethoven's Fur Elise.mid"
BASS_MIDI_StreamCreateFile:=hMedia:= DllCall(A_ScriptDir "\bassmidi.dll\BASS_MIDI_StreamCreateFile", UInt, False, UInt, &file, UInt64, 0, UInt64, 0, UInt, 0, UInt, 44100)
BASS_ErrorGetCode	:= DllCall(A_ScriptDir "\bass.dll\BASS_ErrorGetCode", Int)
if !hMedia {
	Msgbox,% "Failed to load:`n""" Track_%nr%_path """"
	Return
	}
BASS_ChannelPlay	:=DllCall(A_ScriptDir . "\bass.dll\BASS_ChannelPlay", UInt,hMedia, Int,1, Cdecl Int)
clipboard=
(
BASS_DLLCALL: %BASS_DLLCALL%
BASS_MIDI_DLLCALL: %BASS_MIDI_DLLCALL%
BASS_Init: %BASS_Init%
BASS_MIDI_HANDLE: %BASS_MIDI_HANDLE%
File: %File%
BASS_MIDI_StreamCreateFile: %BASS_MIDI_StreamCreateFile%
BASS_ErrorGetCode: %BASS_ErrorGetCode%
BASS_ChannelPlay: %BASS_ChannelPlay%
)

return
esc::
	DllCall(A_ScriptDir "\bass.dll\BASS_PluginFree", UInt, BASS_WMA_HANDLE)
	DllCall(A_ScriptDir "\bass.dll\BASS_Free")
	DllCall("FreeLibrary", UInt, BASS_MIDI_DLLCALL)
	DllCall("FreeLibrary", UInt, BASS_DLLCALL)
	reload
	return
the result is:

BASS_DLLCALL: 285212672
BASS_MIDI_DLLCALL: 274726912
BASS_Init: 1
BASS_MIDI_HANDLE: 274726912
File: D:\Program Files\TinyShuffler\test Beethoven's Fur Elise.mid
BASS_MIDI_StreamCreateFile: -1342177279
BASS_ErrorGetCode: 0
BASS_ChannelPlay: 1

here you see that everything is fine.

PS Trout Player doesn't do midi files, it loads them like my example, but it doesnt play.

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
Did you try a BASS_ErrorGetCode check after each command?
Sometimes even if the other ones return error 0,
I'm often getting an error 5 (aka BASS_ERROR_HANDLE) for BASS_ChannelPlay

About Trout player, I've seen at least one example of success
If a single person can play it, there is hope! :p

Thx for the link to the website, and its contact page
As he's not responding on trout's topic,
I will now proceed to direct email attempt :roll:

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009
forgot all about CT4MGM.SF2 it works now
with my example
and just putting CT4MGM.SF2 in:
C:\WINDOWS\system32\CT4MGM.SF2
:lol:

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum


Lemo
  • Members
  • 14 posts
  • Last active: Aug 25 2011 02:15 PM
  • Joined: 23 May 2011
Yeah I have that soundfont there for weeks already
With your last example, I'm still getting fail to load,
even with ahk_basic
File            :=A_ScriptDir "\test.mid"
and test.mid and dlls are in that same folder

Glad you have it working :shock: , you mean you can hear sound and all?

emmanuel d
  • Members
  • 519 posts
  • Last active: Jul 15 2017 12:04 PM
  • Joined: 29 Jan 2009

Glad you have it working :shock: , you mean you can hear sound and all?

Yes i do, never had i any sound before.

Stopwatch emdkplayer
the code i post falls under the: WTFYW-WTFPL license

http://www.ahkscript.org/ the new forum