Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to use midi cc slider/knob to control iTunes volume

Hey, didn't know where to share this, figured this was as good a place as any...


Because I am such a n00b at applescript, or any type of coding for that matter, when trying to figure out how to get a midi control knob to control my iTunes volume it turned to google, but to no avail...


So after much trial and error, I have written my own code that seems to work nicely and thought I should share it in case someone else like me is looking for a cut and paste answer.


So it is not perfect, as obviously iTunes addresses its volume from 0 to 100 and midi is 0 to 127, which means that any message above 100 is ignored, so it is full volume before the knob reaches its full volume, but it works. If anyone can suggest a better way, perhaps one that maps it more on a percentage scale? If that makes sense....


this is what I wrote:


on runme(message)

set myVariable to (item 3 of message)

if (item 1 of message = 176) and (item 2 of message = 109) then tell application "iTunes"

set sound volume to myVariable

end tell

end runme




I use this in my live set as an applescript in midipipe along side a bunch of other things to help me control mainstage better with my lexicon mpx R1 foot controller and behringer UMA25s keyboard.


So now I can have mainstage running in full screen mode, finish the last song of a set and click a button on my foot controller which I use an applescript to open itunes and play a specific playlist for while I'm on break. Then if it is too loud or quiet for the venue I am in, I can quickly change the volume with one of the knobs on my keyboard, rather than having to exit full screen, open iTunes window and fumble around with my trackpad and the tiny iTunes slider...


Feedback is welcomed, as I really have no idea what the **** I am doing!

MacBook Pro (13-inch Early 2011)

Posted on Feb 5, 2014 1:03 AM

Reply
Question marked as Best reply

Posted on Feb 9, 2015 7:23 PM

I know it was a year ago. But here is my script (in progress)...


on runme(message)

if (item 1 of message = 176) and (item 2 of message = 23) and (item 3 of message > 0) then

set volume output volume ((item 3 of message) * 0.78)

end if

if (item 1 of message = 176) and (item 2 of message = 22) and (item 3 of message > 0) then

tell application "iTunes"

set sound volume to ((item 3 of message) * 0.78)

end tell

end if

if (item 1 of message = 144) and (item 2 of message = 59) and (item 3 of message > 0) then

tell application "iTunes"

playpause

if player state is playing then

return {144,59,127}

else

return {144,59,0}

end if

end tell

end if

end runme


The * 0.78 compensates for the 0-127 coming from the value to the 0-100 needed for volume. The top if changes the overall mac volume. The next if changes the volume in iTunes only. The next if cycles play/pause and also then checks to see if it's playing and turns on or off the light on the play button.


These codes are all for the Numark Mixtrack Pro 2.


I'll probably add more functionality as well, like the selection scroller doing up/down arrows in the song list or whatever.

2 replies
Question marked as Best reply

Feb 9, 2015 7:23 PM in response to jeremypeterallen

I know it was a year ago. But here is my script (in progress)...


on runme(message)

if (item 1 of message = 176) and (item 2 of message = 23) and (item 3 of message > 0) then

set volume output volume ((item 3 of message) * 0.78)

end if

if (item 1 of message = 176) and (item 2 of message = 22) and (item 3 of message > 0) then

tell application "iTunes"

set sound volume to ((item 3 of message) * 0.78)

end tell

end if

if (item 1 of message = 144) and (item 2 of message = 59) and (item 3 of message > 0) then

tell application "iTunes"

playpause

if player state is playing then

return {144,59,127}

else

return {144,59,0}

end if

end tell

end if

end runme


The * 0.78 compensates for the 0-127 coming from the value to the 0-100 needed for volume. The top if changes the overall mac volume. The next if changes the volume in iTunes only. The next if cycles play/pause and also then checks to see if it's playing and turns on or off the light on the play button.


These codes are all for the Numark Mixtrack Pro 2.


I'll probably add more functionality as well, like the selection scroller doing up/down arrows in the song list or whatever.

Applescript to use midi cc slider/knob to control iTunes volume

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.