Controlling Photoshop with MIDI controller

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

lanz_the_joiner
Posts: 2
Joined: Tue Aug 16, 2016 12:15 am

Controlling Photoshop with MIDI controller

Post by lanz_the_joiner »

Hi there,

My aim is to map one of the sliders on my MIDI controller, to one of the RGB colour sliders in Photoshop's colour picker. I imagine this is possible but I don't know... do you think it is possible?

I am very very new to scripting - I am at the stage of familiarising myself with the 'Intro to Scripting' and 'Scripting in Photoshop' documents which are available from Adobe. Using Bome's Midi Translator, I can select what kind of message my Midi controller's slider will send to Photoshop - keystrokes, mouse clicks, etc.

With my pre-rudimentary understanding of scripting, the only way I can envisage setting this up, is to divide the colour slider's 255 values in half, so that each of the 127 MIDI signals sent by my controller will correspond almost perfectly with a place along the colour slider's scale. Then I could create a script with 127 crazy keyboard shortcuts, and use Bome's Midi Translator to set my controller to send these keystrokes when I move the slider.

That solution seems pretty long-winded and clunky. I would hope for there to be a solution involving a created variable... X for example. I just have no idea whatsoever of how I could write a script to tie X to a bunch of data being sent by my controller. I imagine this would be simpler to write, and it would be more elegant - you could draw lines while moving the fader, for example, which would not be possible if the fader simply sent out a series of simulated keystrokes.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Controlling Photoshop with MIDI controller

Post by Kukurykus »

Probably best would be if you read https://autohotkey.com documentation, it's very clear and you meet many willing active users on forum to help. You'll see it's quite easy to call the ahk script by pressing any key. Then the ahk script create for ex. a folder/txt file on a desktop with name/code/number of key you just pressed. I don't know Bome's Midi Translator but if it seems you're able to tie some keyboard character to MIDI key. You can then pressing that MIDI key call ahk script (so same effect like after triggering computer key). Problem is, that you had to specify (at least a hundred conditions) in ahk script what content a pressed key has to send. That would create .txt file (like I mentioned) contining name of that pressed key. Then the same script execute .jsx script which check code of that .txt file to use it as value for own X variable. At the end it'll be converted to RGB information. Below you find example of everything I described:

- put Keystroke.exe and Keystroke.jsx on your desktop
- launch Keystroke.exe
- you must simultaneously press 3 key on your NUMERIC keybord: +, 1 and 0 (plus, one and zero)
- it'll create RGB folder with _10 subfolder (so equivalent to RGB value 10)
- then it will run Keystroke.jsx script which read name of subfolder in RGB folder
- it set values of all RGB components to 10
- RGB folder will be deleted with its subfolder

Of course it can be programmed to operate only on one or two / three RGB channels separately. Additionally if you set your MIDI key to for ex. those 3 keys (_10) it should be send perfectly than pressing it manually at the same time (so don't give up when folder doesn't appear at first times :) or just change AHK code to some simpler sequence.

Ah and that 3th file .ahk (you find in attachment too) is not needed. It's a code wrote before compilating .ahk to .exe. If you want to do it yourself, but you must download first an installer from http://ahkscript.net/

If you meant something else with those RGB sliders than I give you in my answer let me know ;)

Keystroke.ahk:

Code: Select all

NumpadAdd::
If GetKeyState("Numpad1") {
If GetKeyState("Numpad0") {
FileCreateDir, %A_Desktop%\RGB
FileCreateDir, %A_Desktop%\RGB\_10
run, %A_Desktop%\Keystroke.jsx
}
}
return
Keystroke.jsx:

Code: Select all

#target photoshop
bringToFront()
if ((cnt = File('~/Desktop/RGB')).exists) {
X = (nme = cnt.getFiles()[0].name).slice(1, nme.length)
for(i = 0; i < (arr = ['red', 'green', 'blue']).length; i++) {
eval('foregroundColor.rgb.' + arr[i] + ' = X')
}
File(cnt + '/' + nme).remove(), cnt.remove()
}
Attachments
Keystroke.zip
(529.82 KiB) Downloaded 599 times
lanz_the_joiner
Posts: 2
Joined: Tue Aug 16, 2016 12:15 am

Re: Controlling Photoshop with MIDI controller

Post by lanz_the_joiner »

Thanks so much for such a detailed response!

I will take my time to put together the solution you've presented and give it a shot.

Much appreciated!
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Controlling Photoshop with MIDI controller

Post by Kukurykus »

What do you mean? :) Are you interested in something over here?