Post
by nicowald » 19 Jun 2004, 10:46
Hi cweise,
it took me a month but finally I found time to answer your questions:
--Open MIDIPipe (I know I can do this part)
--Automatically have it start listening for/storing incoming MIDI data
in your launch-script simply open the .mipi file, it will launch MidiPipe
--On mouseClick (or some signal that the user's finished):
----Stop listening
the AppleScript currently waits for a program change message; you can change that but the signal has to be in the midi stream
----Parse so just NOTE ON's are kept
----Copy the Note #'s (as text) to the clipboard (or a variable that can be passed back to Rev via AS)
the script outputs something like this to the clipboard: "C1, F#3, G6" -- by editing the AppleScript you can change the output format
----Quit
it's included in the script, but currently disabled (by placing "--" at the beginning of the line) for better testing
--Run in the background, if possible (nothing wrong with seeing the MPipe screen, mind you, just might confuse the user a little...).
since MidiPipe 0.9.4 there is a Preference setting "hide after launch" which should do what you need
here is the script for the "AppleScript Trigger" tool in MidiPipe:
---
-- this script records all Note On messages on channel "fromChannel" to "toChannel" and puts them into the clipboard after a program change message is received
property fromChannel : 1
property toChannel : 16
property myData : {}
on runme(message)
if ((item 1 of message >= (143 + fromChannel)) and (item 1 of message <= (143 + toChannel))) then
if (item 3 of message > 0) then
-- note on
set myDataRef to a reference to myData
copy (item 2 of message) to the end of myDataRef
else
-- note off
end if
else
if ((item 1 of message >= (191 + fromChannel)) and (item 1 of message <= (191 + toChannel))) then
putIntoClipboard()
--tell application "MidiPipe"
--quit
--end tell
end if
end if
end runme
on putIntoClipboard()
set outText to {}
set outTextRef to a reference to outText
set numItems to length of myData
if (numItems > 0) then
if (numItems >= 2) then
repeat with n from 1 to (numItems - 1)
copy {convertValueToKey(item n of myData), ", "} to the end of outText
end repeat
end if
copy {convertValueToKey(item numItems of myData)} to the end of outText
end if
set the clipboard to outText as string
set myData to {}
end putIntoClipboard
on convertValueToKey(value)
set keyNumber to (value mod 12)
set octaveNumber to (value div 12)
if (keyNumber = 0) then set keyName to "C"
if (keyNumber = 1) then set keyName to "C#"
if (keyNumber = 2) then set keyName to "D"
if (keyNumber = 3) then set keyName to "D#"
if (keyNumber = 4) then set keyName to "E"
if (keyNumber = 5) then set keyName to "F"
if (keyNumber = 6) then set keyName to "F#"
if (keyNumber = 7) then set keyName to "G"
if (keyNumber = 8 ) then set keyName to "G#"
if (keyNumber = 9) then set keyName to "A"
if (keyNumber = 10) then set keyName to "A#"
if (keyNumber = 11) then set keyName to "B"
return {keyName, octaveNumber}
end convertValueToKey
---
Happy MidiPipeing!
Regards, Nico
Last edited by
nicowald on 22 Jun 2004, 12:38, edited 1 time in total.