Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Midi NoteOn timer
#1
I'm trying to figure out the best approach to having a Midi NoteOn start a timer, if the timer exceeds a limit before the corresponding Midi NoteOff is sent, a function runs.

Thanks,
Jim
#2
The main part I need help with is setting a timer that will timeout after a specified time and trigger a function.

If a note off comes around before the timeout, then the timer is killed without running the function.
#3
If you have QM "MIDI Triggers" functions, look in function MT_MidiInProc. It receives all MIDI messages and recognizes key-on messages. Add similar code to recognize key-off messages. I don't remember how. Then you can start a timer in the dialog thread with SetTimer, and stop with KillTimer.
#4
I'm good with the MidiTriggers, it's the timer that I really don't have a clue about.
#5
This is what I came up with playing around with some stuff I pieced together, should do the trick.

Function MIDI_Timer
Code:
Copy      Help
;;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("MIDI_Timer" &MIDI_Timer 0)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 255 140 "Midi Timer"
;3 Button 0x54032000 0x0 6 6 48 14 "Time 1"
;4 Button 0x54032000 0x0 6 24 48 14 "Time 2"
;5 Button 0x54032000 0x0 6 42 48 14 "Time 3"
;6 Button 0x54032000 0x0 6 60 48 14 "Time 4"
;7 Button 0x54032000 0x0 6 78 48 14 "Time 5"
;13 Button 0x54032000 0x0 124 6 48 14 "KILL 1"
;14 Button 0x54032000 0x0 124 24 48 14 "KILL 2"
;15 Button 0x54032000 0x0 124 42 48 14 "KILL 3"
;16 Button 0x54032000 0x0 124 60 48 14 "KILL 4"
;17 Button 0x54032000 0x0 124 78 48 14 "KILL 5"
;23 Static 0x54000000 0x0 64 8 48 10 "CLOSED"
;24 Static 0x54000000 0x0 64 26 48 10 "CLOSED"
;25 Static 0x54000000 0x0 64 44 48 10 "CLOSED"
;26 Static 0x54000000 0x0 64 62 48 10 "CLOSED"
;27 Static 0x54000000 0x0 64 80 48 10 "CLOSED"
;END DIALOG
;DIALOG EDITOR: "" 0x2040100 "*" "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,int- TimeMax=5000
,case WM_TIMER
,sel wParam
,,case [3,4,5,6,7]
,,out F"{wParam} Expired"
,,_s="ALARM"
,,_s.setwintext(id(wParam+20 hDlg))
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case [3,4,5,6,7]
,SetTimer hDlg wParam TimeMax 0
,_s="OPEN"
,_s.setwintext(id(wParam+20 hDlg))
,case [13,14,15,16,17]
,KillTimer hDlg wParam-10
,_s="CLOSED"
,_s.setwintext(id(wParam+10 hDlg))
,case IDOK
,case IDCANCEL
ret 1
#6
Code:
Copy      Help
;in function that receives MIDI messages, eg MT_MidiInProc:
;detect whether it is a key on or key off message, then
if messageType=1 ;;key on
,SetTimer _hwndmt 10 5000 0
else if messageType=2 ;;key off
,KillTimer _hwndmt 10
;let _hwndmt be MIDI manager dialog handle, int+

;_______________________

;in MIDI manager dialog procedure, eg MIDI_Timer:
,case WM_TIMER
,sel wParam
,,case 10
,,out "a function runs"


Forum Jump:


Users browsing this thread: 1 Guest(s)