AutoHotkey Community

It is currently May 25th, 2012, 1:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 65 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: May 8th, 2007, 2:52 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Laszlo wrote:
After a couple of days debugging I ended up rewriting the whole code. Now it works with the default midi device: ID 0: Microsoft GS Wavetable SW Synth. Most of the changes were bug fixes and simplifications, to reduce code size. The hardest part is TomB's original discovery work, which made midi output possible from an AHK script.
Wow! Once you finalize it, perhaps this would be a good candidate for the standard library -- especially if it works on all OSes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2007, 3:21 am 
Offline

Joined: January 14th, 2005, 5:30 pm
Posts: 17
Laszlo wrote:
Quote:
After a couple of days debugging I ended up rewriting the whole code. Now it works with the default midi device: ID 0: Microsoft GS Wavetable SW Synth. Most of the changes were bug fixes and simplifications, to reduce code size. The hardest part is TomB's original discovery work, which made midi output possible from an AHK script.


Well, now I am just plain embarrassed - I guess I proved my point that I am a novice programmer. The scripts worked for me, but I certainly didn't test them out thoroughly.

I wanted to throw them out there in hopes that this would happen - someone who actually knows what they are doing would clean all of this up.

Sorry I created so much work for you Laszlo. It took me probably 15-20 hours to get it to where I did, so between the two of us, there are a lot of man-hours in this little project.

Tom


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2007, 3:44 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
40 hours work for such a nice tool is not much. Before your post I did not even know that Windows has built in midi support, so your work was very important. Our code always has bugs… well, almost. I know someone, who's code always worked so far at the first run, but we, mere mortals just have to bug fix two hours for every hour of coding.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Getting errors
PostPosted: July 30th, 2007, 7:16 pm 
Offline

Joined: July 30th, 2007, 7:02 pm
Posts: 3
Hi,

Thanks very much TomB for developing these MIDI functions, and Laszlo for the edits.

I tried Laszlo's edited code and examples, but I am getting the following errors:

- When it executes the example "single middle C note by midiOutShortMsg," it works fine and I hear the single note.

- When it executes the example "Send two notes on device 0 by MidiStream":

Error 11 in setting the Timebase
Error 7 in midiOutPrepareHeader

- Then, when it executes the example "Send a decaying series of C notes":

Error 11 in setting the Timebase

I'm running Windows ME and using the default MIDI output (device 0).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2007, 7:27 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Search the Web, maybe ME does not support MIDI streaming? I could only test the script on XP SP2, where it works.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2007, 8:45 pm 
Offline

Joined: July 30th, 2007, 7:02 pm
Posts: 3
Laszlo,

Thanks for the quick response.

Quote:
Search the Web, maybe ME does not support MIDI streaming?


I found this page about midiStreamOpen from the MSDN Library:

http://msdn2.microsoft.com/en-us/library/ms711645.aspx

At the bottom of the article, it says:

    Requirements
    Windows NT/2000/XP: Included in Windows NT 3.1 and later.
    Windows 95/98/Me: Included in Windows 95 and later.
    Header: Declared in Mmsystem.h; include Windows.h.
    Library: Use Winmm.lib.
I guess this means that Windows 9x/Me is supported.

Then I tried running the same script on my XP (SP2) computer, and it gives the following error:

    Error at line 30.
    Line Text: DllCall("FreeLibrary", UInt,hModule), hModule := ""
    Error: This line does not contain a recognized action.
    The program will exit.

Thanks,
dpg


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2007, 8:48 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
dpg wrote:
Line Text: DllCall("FreeLibrary", UInt,hModule), hModule := ""
Error: This line does not contain a recognized action.
It looks like you have an old AHK version.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2007, 11:12 pm 
Offline

Joined: July 30th, 2007, 7:02 pm
Posts: 3
Laszlo wrote:
It looks like you have an old AHK version.

Yup! Updated AHK, and it works on the XP now. Thanks.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 10th, 2008, 3:02 am 
Offline

Joined: July 7th, 2008, 7:29 pm
Posts: 27
I just started useing this MIDI output library and its working great. However when I try to combine it with a MIDI input library(http://www.autohotkey.com/forum/viewtopic.php?t=30715) it stops working.

here's some code I used to test it out.

-------------------------------------------------------------------------------
hModule := OpenMidiAPI()
mm6 := midiOutOpen(1)

OnExit, sub_exit
if (midi_in_Open(8))
ExitApp

listenCC(64, "SustainIn", 2)

return

sub_exit:
midi_in_Close()
midiOutClose(mm6)
FreeMidiAPI(hModule)
ExitApp

a::
midiOutShortMsg(mm6, "CC", 2, 64, 127)
return

SustainIn(CCNum, Vel)
{
midiOutShortMsg(mm6, "CC", 2, 64, 127)
}

#Include midi_out_lib.ahk
#Include midi_in_lib.ahk

------------------------------------------------------------------------

When I trigger the output with "a" it works fine but when I trigger it with my sustain pedal I get message box that says "there was error sending the MIDI event".

anyone have any suggestions or other ways to get MIDI input and output.

thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2008, 5:31 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
So I've been using this library a lot and it is really fantastic. Thanks both of you guys for working so hard on it. Been having huge success with it, but theres one thing thats got me stumped, so I've got a bit of whats probably a newbie question for you.

About sending pitch wheel events-- what kinds of values should I put into parameter 2 for pitch wheel? I can't seem to get any consistent output. Everything is all over the place. Something like -638000 sends the pitchwheel to -64 and 8192 sends it to -32 or something. I don't remember the exact values but I figure I am using the wrong kind of input?

Thanks a bunch.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2008, 3:33 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I am using a dllcall directly, for speed. If you have a pitch bend value 0 <= PB < 16384 (with the center value 8192 corresponding to no bend, 0 to the max downward bend and 16383 to the max upward bend), a possible call is
Code:
DllCall("winmm.dll\midiOutShortMsg", UInt,h_midiout, UInt,(channel+0xDF)|(PB&0x7F)<<8|(PB>>7)<<16) ; channel = 1..16

That is, Param1 := PB & 127, Param2 := PB>>7. We need the bit-manipulation operations because only 7 bits of the PB value should be included in MIDI messages.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2008, 6:21 am 
Offline

Joined: September 21st, 2008, 6:34 am
Posts: 16
Thanks man. That took a little bit of studying on my part to decipher, but you solved my problem.

_________________
Composer
http://www.joshuaevensen.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 3:05 am 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
I am using the orginal MIDI functions with success in my first major AHK's project. However, being a newbie I am finding what I want to do a bit out of my grasp.

The sample code...

Code:
   NumPorts := MidiOutsEnumerate()     ;function that fills an global array called MidiOutPortName and returns the number of ports
    Loop, % NumPorts
    {
      Port := A_Index -1
      msg := msg . "ID: " . Port . " --> " . MidiOutPortName%Port% . "`n"
    }
    InputBoxH := 100 + NumPorts * 25
    InputBox, MidiDevice, Select Midi Port, Select the MIDI Output Port for MuCKeys`n`n%msg%,, 350, % (NumPorts * 25 + 100),,,,, 0
    if (errorlevel)
        exit
h_midiout := midiOutOpen(MidiDevice)


...brings up a msgbox with the MIDI port numbers and names, but I would like to save the selected port name in an ini file and then when the program is run in the future seek to see if that output port is still available and if so use it as default. If it is not available, then the msgbox could just pop back up and let the user rechoose. Is this hard? I don't get arrays too well and spent an hour or so trying to guess my way to success, but couldn't. How can I search the array and set the MIDI output port from the ini file if it is available ? Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 4:32 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Your script does not use arrays, but a long msg string of fields delimited by new lines (`n). You can later use
Code:
Loop Parse, msg, `n
to get the pieces in the automatic loop variable A_LoopField. A_Index contains the number of the current iteration inside the loop block, delimited by {...}.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 4:57 am 
Offline

Joined: December 20th, 2007, 4:12 am
Posts: 22
Got it working. Thanks.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 65 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, DataLife, MSN [Bot], Yahoo [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group