Re: was: HELP!
Re: was: HELP!
- Subject: Re: was: HELP!
- From: Jeff Moore <email@hidden>
- Date: Thu, 31 Aug 2006 14:49:48 -0700
On Aug 31, 2006, at 1:11 PM, Daniel Jalkut wrote:
On Aug 31, 2006, at 12:52 PM, Jeff Moore wrote:
One other thing I'll throw out there: Back in OS 9, AppleScript
supported Scripting Additions which were bits of native code that
added capabilities to AppleScript, much like XCMDs did for
Hypercard or JNI does for Java. I definitely recall somebody, back
in the day, writing a Scripting Addition that interfaced to OMS and/
or the MIDI Manager. The best possible solution to this problem
would be a similar approach that connected AppleScript directly to
CoreMIDI, provided that AppleScript still has something like
Scripting Additions in it.
For the record, AppleScript never stopped supporting Scripting
Additions. You can install them on your system today in ~/Library/
ScriptingAdditions for example. Apple even continues to ship some of
their own in /System/Library/ScriptingAdditions.
The bigger problem with trying to do something like this in
AppleScript is that AppleScript is not good at blocking for user
input. Even when the "wires are hooked up," for instance when trying
to detect a regular old typing keyboard key press, scripters tend to
need to jump through all kinds of hoops to make a script "notice"
when it happens. This usually involves some crude combination of
sleeping and polling. So even if there were a "MIDI Interface"
scripting addition, it might be hard to achieve exactly what the
original poster is looking for.
Thank you for setting the record straight. While it may not be
perfect, this approach does have a lot of positives, such as being
able to keep the app logic entirely in AppleScript.
On Aug 31, 2006, at 3:51 PM, djl wrote:
I know what needs to be done from the example code (Echo.cpp) but
don't have the experience/means to execute the changes as I don't
know enough about the frameworks and coding conventions to call the
required commands etc.
If I'm getting the original poster's gist, he wants to be able to
react with an arbitrary script when a keyboard note is pressed via
MIDI. If the "Echo.cpp" example does indeed do everything except the
"calling his script," then perhaps some combination of Echo.cpp with
the AppleScript handler execution described here:
http://developer.apple.com/qa/qa2001/qa1111.html
Would be a step in the right direction. I think instead of
attempting to make the script itself detect key presses in this
case, it would be better to aim for a standalone program that
dispatches to an AppleScript (or other script) in response to key
presses.
This is an excellent suggestion. It turns the problem on it's head and
comes up with a solid solution. Whether or not it is a viable solution
for this problem is hard to say because we still don't know what the
actual problem is.
On Aug 31, 2006, at 12:51 PM, djl wrote:
Correct me if I'm wrong, but the sample code for Echo.cpp looks for
attached MIDI devices and echo's the result?
How difficult can it be to keep a loop going that calls whatever
commands are required to 'read' a MIDI In note-on event and echo
that too?
These tasks are not complicated, as the sample code shows. But you are
totally ignoring the totality of the problem. You still have to get
the MIDI data from the capturing process to the script's process.
That's can be pretty tricky stuff and usually requires a both a
healthy understanding of how the system works and chops at writing
code in one of the C-ish languages.
Not to mention, you can't just fork the capturing process from your
script whenever you want a MIDI key and expect to get anything useful.
As I said, forking processes and doing communication between the two
processes has overhead that isn't predictable in terms of timing
unless you take some extreme precautions (which again requires writing
C-ish code and a healthy knowledge of the system). You can and will
miss the key the user just hit because the fork took an extra second
or two this time versus the last time. IMHO, this is possibly the
worst solution to the problem.
On the other hand, forking a process that runs continuously and feeds
MIDI keys back to the script's process, while an excellent way to
solve the problem, still has the problem of shipping the data back to
the script's process. You will have to use some kind of shared memory
construct or something like a pipe to manage the communication between
the processes. Neither task is trivial. You will have to write a fair
amount of code in a C-ish language to do it.
I hope I've been clear enough with what I want to do this time and I
await your comments/replies.
You still haven't actually described what you are trying to do,
holistically. All I've seen written is that you want to capture MIDI
key events in an AppleScript script. Fair enough, but such a vague
description doesn't provide enough constraints to allow the folks on
this list to provide an applicable solution. Honestly, I can think of
a lot of ways to get MIDI keys into a script, but which approach to
use depends entirely on what you are trying to do and how you are
going to use the information.
I want to help you, but you sure aren't making it easy.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden