Jump to content

"Compare" button - how to recognize it for MCU controller? any idea?


vladistone
Go to solution Solved by Jordi Torres,

Recommended Posts

To @Jordi Torres

I made the small edited version of your lua script "TogglePluginCompareWithMidi" with var discribtion:

local Control = hs.midi.new('SSLnucleus2')

and changed CC number:

metaData.controllerNumber == 79

see full script:

2023-03-16 22:51:28: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

-- print available MIDI device names to the Hammerspoon Console
print(hs.inspect(hs.midi.devices()))


-- Create a new hs.midi object for the desired MIDI device by passing in the device name
local Control = hs.midi.new('SSLnucleus2')
local windowFilter = hs.window.filter
local runScript = hs.osascript


-- AppleScript to click plugin Compare button
local clickCompareButton = [[
  tell application "System Events"
	  tell process "Logic Pro"
        click checkbox "Compare" of window 1
	  end tell
  end tell
]]

-- Callback function for the Hammerspoon MIDI object created above (hs.midi.new)
-- Parameters: object, deviceName, commandType, description, metadata
-- Here we listen for incoming Control Change message that will trigger the AppleScript when received
local handleMidi = function(...)
  local commandType = select(3, ...)
  local metaData = select(5, ...)
  if commandType == 'controlChange' then
      if metaData.controllerNumber == 79 and metaData.controllerValue == 127 then
        runScript.applescript(clickCompareButton)
      end
  end
end


-- Create Window Filter for Logic Pro window
local logicWindowFilter = windowFilter.new('Logic Pro')

-- Subscribe to events when Logic Pro window is in focus (or not)
logicWindowFilter:subscribe(windowFilter.windowFocused, function()
  -- Sets the callback for the Hammerspoon MIDI object when Logic Pro is in focus
  Control:callback(handleMidi)
  print('Logic in focus...')
end):subscribe(windowFilter.windowUnfocused, function()
  -- Removes the callback when Logic Pro loses focus
  Control:callback(nil)
  print('Logic not in focus...')
end)

but I can`t to do anything for control action...

HS consol showed:

2023-03-16 23:02:39: -- Loading extension: inspect
2023-03-16 23:02:39: -- Loading extension: midi
2023-03-16 23:02:39: { "network", "Bluetooth", "ipMIDI" }
2023-03-16 23:02:39: -- Loading extension: window
2023-03-16 23:02:39: -- Loading extensions: window.filter
2023-03-16 23:02:39: -- Loading extension: osascript

2023-03-16 23:59:22: 23:59:22 ERROR:   LuaSkin: hs.application.watcher callback: [string "-- print available MIDI device names to the H..."]:40: attempt to index a nil value (upvalue 'Control')
stack traceback:
	[string "-- print available MIDI device names to the H..."]:40: in local 'fn'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:950: in upvalue 'emit'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:976: in method 'filterEmitEvent'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1010: in method 'emitEvent'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1094: in method 'focused'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1286: in function <...2.app/Contents/Resources/extensions/hs/window/filter.lua:1273>
	(...tail calls...)
2023-03-16 23:59:35: 23:59:35 ERROR:   LuaSkin: hs.application.watcher callback: [string "-- print available MIDI device names to the H..."]:44: attempt to index a nil value (upvalue 'Control')
stack traceback:
	[string "-- print available MIDI device names to the H..."]:44: in local 'fn'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:950: in upvalue 'emit'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:976: in method 'filterEmitEvent'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1010: in method 'emitEvent'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1102: in method 'unfocused'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1291: in method 'deactivated'
	...2.app/Contents/Resources/extensions/hs/window/filter.lua:1276: in function <...2.app/Contents/Resources/extensions/hs/window/filter.lua:1273>
	(...tail calls...)

probably is it issue due to:

my MIDI setup have 6 ipMIDI ports for controller connection, but it is not discribed to scrip:

{ ipMIDI 1; ipMIDI 2; ipMIDI 3; ipMIDI 4; ipMIDI 5; ipMIDI 6 }

or may be more any errors I have made in scrip localisation?

ipMIDI.png

Edited by vladistone
Link to comment
Share on other sites

after I had changed this var and reload HS:

local Control = hs.midi.new('ipMIDI')

consol showed:

2023-03-17 00:20:31: -- Loading extension: inspect
2023-03-17 00:20:31: -- Loading extension: midi
2023-03-17 00:20:31: { "network", "Bluetooth", "ipMIDI" }
2023-03-17 00:20:31: -- Loading extension: window
2023-03-17 00:20:31: -- Loading extensions: window.filter
2023-03-17 00:20:31: -- Loading extension: osascript

2023-03-17 00:20:33: Logic in focus...
2023-03-17 00:20:42: Logic in focus...
2023-03-17 00:20:44: Logic not in focus...

but nothing happens by under MCU control of "compare" button

Monitor MIDI events.png

Edited by vladistone
Link to comment
Share on other sites

Hi @vladistone,

10 hours ago, vladistone said:

I made the small edited version of your lua script "TogglePluginCompareWithMidi" with var discribtion:

local Control = hs.midi.new('SSLnucleus2')

You cannot just pass any string to the hs.midi.new constructor like that, it has to be an actual device from the ones returned by:

-- print available MIDI device names to the Hammerspoon Console
print(hs.inspect(hs.midi.devices()))

That's why you get that error:

2023-03-16 23:59:22: 23:59:22 ERROR:   LuaSkin: hs.application.watcher callback: [string "-- print available MIDI device names to the H..."]:40: attempt to index a nil value (upvalue 'Control')

 

10 hours ago, vladistone said:

probably is it issue due to:

my MIDI setup have 6 ipMIDI ports for controller connection, but it is not discribed to scrip:

{ ipMIDI 1; ipMIDI 2; ipMIDI 3; ipMIDI 4; ipMIDI 5; ipMIDI 6 }

Yes, that's probably why, as those would be virtual sources, not physical devices. So it will probably work when you use the constructor for virtual sources. Use something like the following:

local virtualSources = hs.midi.virtualSources()
print(hs.inspect(virtualSources))

And based on what gets printed to the HS console, you'll be able to choose and set the appropriate ipMIDI port to pass it as a string to the hs.midi.newVirtualsource contructor, something like this:

local Control = hs.midi.newVirtualSource('ip_midi_port_name')

Again, the actual string to pass to this constructor will depend on what you get in the HS console from print(hs.inspect(virtualSources)), I'm guessing in your case it will be just 'Port 3' based on what you've posted above from your MIDI Monitor window.

Be sure to read the documentation on hs.midi here:

Hammerspoon docs: hs.midi

Good luck 😄

J.

Edited by Jordi Torres
  • Like 1
Link to comment
Share on other sites

Hi @Хорди Торрес

I started to lean the hs.midi and your inform me quite right

but HS console showed me this information:

> print(hs.inspect(virtualSources))
2023-03-17 10:30:47: nil

 

> print ( hs.inspect ( hs.midi.devices ( ) ) )
2023-03-17 10:14:33: -- Loading extension: inspect
2023-03-17 10:14:33: { "network", "Bluetooth", "ipMIDI", "ipMIDI" }


> local virtualSources = hs.midi.virtualSources()
print(hs.inspect(virtualSources))
NSInvalidArgumentException: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

 


(
	0   CoreFoundation                      0x00007fff37ddff3b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fff5f138942 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff37e1ffcc _CFThrowFormattedException + 194
	3   CoreFoundation                      0x00007fff37d013dd -[__NSArrayM insertObject:atIndex:] + 1245
	4   internal.so                         0x0000000111a9865e virtualSources + 382
	5   LuaSkin                             0x000000010d05305c luaD_precall + 464
	6   LuaSkin                             0x000000010d04954b luaV_execute + 18507
	7   LuaSkin                             0x000000010d0531a5 ccall + 85
	8   LuaSkin                             0x000000010d03cfcd luai_objcttry + 28
	9   LuaSkin                             0x000000010d0536e3 luaD_pcall + 92
	10  LuaSkin                             0x000000010d057422 lua_pcallk + 318
	11  LuaSkin                             0x000000010d054f5a luaB_xpcall + 115
	12  LuaSkin                             0x000000010d05305c luaD_precall + 464
	13  LuaSkin                             0x000000010d04954b luaV_execute + 18507
	14  LuaSkin                             0x000000010d0531a5 ccall + 85
	15  LuaSkin                             0x000000010d03cfcd luai_objcttry + 28
	16  LuaSkin                             0x000000010d0536e3 luaD_pcall + 92
	17  LuaSkin                             0x000000010d057422 lua_pcallk + 318
	18  LuaSkin                             0x000000010d031c46 -[LuaSkin protectedCallAndTraceback:nresults:] + 251
	19  Hammerspoon                         0x000000010cc369d4 MJLuaRunString + 200
	20  Hammerspoon                         0x000000010cc3116c -[MJConsoleWindowController tryMessage:] + 146
	21  AppKit                              0x00007fff35a7fa43 -[NSApplication(NSResponder) sendAction:to:from:] + 312
	22  AppKit                              0x00007fff3552553f -[NSControl sendAction:to:] + 86
	23  AppKit                              0x00007fff35496daa -[NSTextField textDidEndEditing:] + 937
	24  Hammerspoon                         0x000000010cc34c24 -[HSGrowingTextField textDidEndEditing:] + 42
	25  CoreFoundation                      0x00007fff37d7039c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
	26  CoreFoundation                      0x00007fff37d7026a _CFXRegistrationPost + 458
	27  CoreFoundation                      0x00007fff37d6ffa1 ___CFXNotificationPost_block_invoke + 225
	28  CoreFoundation                      0x00007fff37d2eb32 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
	29  CoreFoundation                      0x00007fff37d2dbc3 _CFXNotificationPost + 659
	30  Foundation                          0x00007fff39e5c047 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
	31  AppKit                              0x00007fff3560b43a -[NSTextView(NSPrivate) _giveUpFirstResponder:] + 440
	32  AppKit                              0x00007fff35483cff -[NSTextView doCommandBySelector:] + 200
	33  AppKit                              0x00007fff35483c13 -[NSTextInputContext(NSInputContext_WithCompletion) doCommandBySelector:completionHandler:] + 118
	34  AppKit                              0x00007fff3546514e -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 2898
	35  AppKit                              0x00007fff35cfecbf __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke.1109 + 360
	36  AppKit                              0x00007fff35cfeaee __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke_3 + 79
	37  AppKit                              0x00007fff3546c989 -[NSTextInputContext tryHandleEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 92
	38  AppKit                              0x00007fff35cfea6d __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke.1099 + 251
	39  HIToolbox                           0x00007fff3706aace __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_5 + 70
	40  HIToolbox                           0x00007fff37069986 ___ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec_block_invoke + 110
	41  AppKit                              0x00007fff35cf74cc __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke.320 + 580
	42  AppKit                              0x00007fff354664df __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2 + 79
	43  AppKit                              0x00007fff35466462 -[NSTextInputContext tryHandleTSMEvent_HasMarkedText_withDispatchCondition:dispatchWork:continuation:] + 92
	44  AppKit                              0x00007fff35465fc5 -[NSTextInputContext handleTSMEvent:completionHandler:] + 1722
	45  AppKit                              0x00007fff35465895 _NSTSMEventHandler + 311
	46  HIToolbox                           0x00007fff37013904 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1541
	47  HIToolbox                           0x00007fff37012c4d _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 374
	48  HIToolbox                           0x00007fff37012ac3 SendEventToEventTargetWithOptions + 45
	49  HIToolbox                           0x00007fff37066bd9 SendTSMEvent_WithCompletionHandler + 389
	50  HIToolbox                           0x00007fff370670a4 __SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler_block_invoke + 403
	51  HIToolbox                           0x00007fff37066f02 __SendFilterTextEvent_WithCompletionHandler_block_invoke + 219
	52  HIToolbox                           0x00007fff37066c28 SendTSMEvent_WithCompletionHandler + 468
	53  HIToolbox                           0x00007fff37066a27 SendFilterTextEvent_WithCompletionHandler + 233
	54  HIToolbox                           0x00007fff370666e6 SendUnicodeTextAEToUnicodeDoc_WithCompletionHandler + 290
	55  HIToolbox                           0x00007fff3706649a __utDeliverTSMEvent_WithCompletionHandler_block_invoke_2 + 289
	56  HIToolbox                           0x00007fff3706631b __utDeliverTSMEvent_WithCompletionHandler_block_invoke + 405
	57  HIToolbox                           0x00007fff37066108 TSMKeyEvent_WithCompletionHandler + 636
	58  HIToolbox                           0x00007fff37065e4c __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_4 + 262
	59  HIToolbox                           0x00007fff37065c67 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_3 + 263
	60  HIToolbox                           0x00007fff370659a2 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke_2 + 288
	61  HIToolbox                           0x00007fff370656f8 __TSMProcessRawKeyEventWithOptionsAndCompletionHandler_block_invoke + 280
	62  HIToolbox                           0x00007fff37064cef TSMProcessRawKeyEventWithOptionsAndCompletionHandler + 3433
	63  AppKit                              0x00007fff35cfe8e9 __84-[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:]_block_invoke.1090 + 115
	64  AppKit                              0x00007fff35cfdcb7 __204-[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:]_block_invoke.1016 + 120
	65  AppKit                              0x00007fff35cfdb20 -[NSTextInputContext tryTSMProcessRawKeyEvent_orSubstitution:dispatchCondition:setupForDispatch:furtherCondition:doubleSpaceSubstitutionCondition:doubleSpaceSubstitutionWork:dispatchTSMWork:continuation:] + 255
	66  AppKit                              0x00007fff35cfe32d -[NSTextInputContext _handleEvent:options:allowingSyntheticEvent:completionHandler:] + 1237
	67  AppKit                              0x00007fff35cfd9ad -[NSTextInputContext _handleEvent:allowingSyntheticEvent:] + 114
	68  AppKit                              0x00007fff3546433d -[NSView interpretKeyEvents:] + 209
	69  AppKit                              0x00007fff3546415f -[NSTextView keyDown:] + 724
	70  AppKit                              0x00007fff35c1c43d -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 5040
	71  AppKit                              0x00007fff35c1ac70 -[NSWindow(NSEventRouting) sendEvent:] + 497
	72  AppKit                              0x00007fff35a7c236 -[NSApplication(NSEvent) sendEvent:] + 2462
	73  AppKit                              0x00007fff352dc87d -[NSApplication run] + 812
	74  AppKit                              0x00007fff352aba3a NSApplicationMain + 804
	75  libdyld.dylib                       0x00007fff5fd53015 start + 1
)

 

 

 

Edited by vladistone
Link to comment
Share on other sites

result:

2023-03-17 10:37:20: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

2023-03-17 10:37:20: -- Lazy extension loading enabled
2023-03-17 10:37:21: -- Loading ~/.hammerspoon/init.lua
2023-03-17 10:37:21: -- Loading extension: hotkey
2023-03-17 10:37:21: 10:37:21     hotkey: Enabled hotkey ⌘⌃⌥W
2023-03-17 10:37:21: -- Done.

> local virtualSources = hs.midi.virtualSources()
2023-03-17 10:37:46: -- Loading extension: midi


> print(hs.inspect(virtualSources))
2023-03-17 10:37:59: -- Loading extension: inspect
2023-03-17 10:37:59: nil


> virtualSources = hs.midi.virtualSources()

> print(hs.inspect(virtualSources))
2023-03-17 10:40:29: { "Port 1", "Port 2", "Port 3", "Port 4", "Port 5", "Port 6" }

if I understood everything correctly, then these values are global for lua?!

Edited by vladistone
Link to comment
Share on other sites

after 12 hour to study of Hammerspoon docs: hs.midi I can't made the new virtual Source:

2023-03-17 23:03:13: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

2023-03-17 23:03:13: -- Lazy extension loading enabled
2023-03-17 23:03:13: -- Loading ~/.hammerspoon/init.lua
2023-03-17 23:03:13: -- Loading extension: inspect
2023-03-17 23:03:13: -- Loading extension: midi
2023-03-17 23:03:13: MIDI devices: { "network", "Bluetooth", "ipMIDI" }
2023-03-17 23:03:13: Virtual Sources   1:{ "Port 1", "Port 2", "Port 3", "Port 4", "Port 5", "Port 6" }
2023-03-17 23:03:13: Virtual Sources new: nil
2023-03-17 23:03:13: *** ERROR: /Users/vladistone/.hammerspoon/init.lua:6: attempt to index a nil value (global 'midiDevice')
stack traceback:
	/Users/vladistone/.hammerspoon/init.lua:6: in main chunk
	[C]: in function 'xpcall'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:722: in function 'hs._coresetup.setup'
	(...tail calls...)

used by this script:

-- Checking the open midi devices and virtual port name of ipMIDI:

print("MIDI devices: " .. hs.inspect(hs.midi.devices()))
midiDevice = hs.midi.virtualSources()
print("Virtual Sources   1:" .. hs.inspect(midiDevice))

-- Creating the virtual var.:

midiDevice = hs.midi.new(hs.midi.virtualSources()[1])
print("Virtual Sources new: " .. hs.inspect(midiDevice))

-- Callback function for watching of receive MIDI events from ipMIDI Controller:

midiDevice:callback(function(object, deviceName, commandType, description, metadata)
           print("object: " .. tostring(object))
           print("deviceName: " .. deviceName)
           print("commandType: " .. commandType)
           print("description: " .. description)
           print("metadata: " .. hs.inspect(metadata))
           end)

also was fails to receive MIDI messages from ports other than "port 1" in real midiDevice mode (but I should to reached to "Port 3" of controller...

notes:

---

Port 1 - left panel of controller is seted as MCU mix controling (using "note on/off" generation)

Port 2 - right panel as XT midi control in mix mode...

Port 3 - left panel of controller as CC# generation for "channel strip & LPX smart control mode"

Port 4 - right panel as CC# gen. mode

Port 5; 6 - external devices control (Sysex generation)

---

2023-03-17 23:19:35: Welcome to the Hammerspoon Console!
You can run any Lua code in here.

2023-03-17 23:19:35: -- Lazy extension loading enabled
2023-03-17 23:19:35: -- Loading ~/.hammerspoon/init.lua
2023-03-17 23:19:35: -- Loading extension: inspect
2023-03-17 23:19:35: -- Loading extension: midi
2023-03-17 23:19:35: MIDI devices: { "network", "Bluetooth", "ipMIDI" }
2023-03-17 23:19:35: Virtual Sources   1:{ "Port 1", "Port 2", "Port 3", "Port 4", "Port 5", "Port 6" }
2023-03-17 23:19:35: Virtual Sources new: <userdata 1> -- hs.midi: ipMIDI (0x60c00007ddf8)
2023-03-17 23:19:35: -- Done.
2023-03-17 23:19:44: object: hs.midi: ipMIDI (0x60c000069378)
2023-03-17 23:19:44: deviceName: ipMIDI
2023-03-17 23:19:44: commandType: noteOn
2023-03-17 23:19:44: description: <MIKMIDINoteOnCommand: 0x600000248160> time: 23:19:44.345 command: 159 channel 0 note: 24 velocity: 127 
	data: <90187f>
2023-03-17 23:19:44: metadata: {
  channel = 0,
  data = "90187f",
  isVirtual = false,
  note = 24,
  timestamp = "23:19:44.345",
  velocity = 127
}
2023-03-17 23:19:44: object: hs.midi: ipMIDI (0x60000006aff8)
2023-03-17 23:19:44: deviceName: ipMIDI
2023-03-17 23:19:44: commandType: noteOn
2023-03-17 23:19:44: description: <MIKMIDINoteOnCommand: 0x600000247b90> time: 23:19:44.545 command: 159 channel 0 note: 24 velocity: 0 
	data: <901800>
2023-03-17 23:19:44: metadata: {
  channel = 0,
  data = "901800",
  isVirtual = false,
  note = 24,
  timestamp = "23:19:44.545",
  velocity = 0
}

used script:

-- Checking the open midi devices and virtual port name of ipMIDI:

print("MIDI devices: " .. hs.inspect(hs.midi.devices()))
midiDevice = hs.midi.virtualSources()
print("Virtual Sources   1:" .. hs.inspect(midiDevice))

-- Creating the virtual var.:

midiDevice = hs.midi.new(hs.midi.devices()[3])
print("Virtual Sources new: " .. hs.inspect(midiDevice))

-- Callback function for watching of receive MIDI events from Controller ipMIDI port 1:

midiDevice:callback(function(object, deviceName, commandType, description, metadata)
           print("object: " .. tostring(object))
           print("deviceName: " .. deviceName)
           print("commandType: " .. commandType)
           print("description: " .. description)
           print("metadata: " .. hs.inspect(metadata))
           end)

 

Edited by vladistone
Link to comment
Share on other sites

So,

You have redundant code in your files (for example, my handleMidi function replaces the midiDevice callback, so you don't need that in init.lua), and your init.lua is not requiring (importing) the code from the other file so that code is not being used at all.

See this post for an explanation on how to deal with that (basically you can have all in your init.lua or require the code from another file):

J.

Edited by Jordi Torres
  • Like 1
Link to comment
Share on other sites

 

29 minutes ago, Jordi Torres said:

So,

You have redundant code in your files (for example, my handleMidi function replaces the midiDevice callback, so you don't need that in init.lua), and your init.lua is not requiring (importing) the code from the other file so that code is not being used at all.

See this post for an explanation on how to deal with that (basically you can have all in your init.lua or require the code from another file):

J.

 

I skimmed through the discussion without downloading the code files. and if I understand you - the essence of this method is in the organization of the "Master" file init.lua with the request for the necessary part of the code from other files of an individually configured repository when certain keystroke events appear...

cool!

necessary to stady lua exsamles

 

Edited by vladistone
Link to comment
Share on other sites

What you have right now could be put in the init.lua and be done with it. Since I have a bunch of scripts that do different things I started using the require function to import them into the init.lua depending on which one I wanted to use at any given time (I just comment out the ones I don't need).

Anyway, the files you shared above not only had redundant code but also had typos, but funnily enough, what you shared on the Hammerspoon discussion on Github doesn't contain those errors (because it's basically 99% what I had shared with you initially,).

Have a look at the attachment using the init.lua plus a separate file for the script. ipMIDI stopped working on my Mac mini for some reason so I could test properly but should work.

 

 

23 minutes ago, vladistone said:

I skimmed through the discussion without downloading the code files.

Good, the idea was to read what I wrote about how to set things up using the require function.

J.

 

TogglePluginCompareW_SSLMidi.zip

Edited by Jordi Torres
Link to comment
Share on other sites

14 minutes ago, Jordi Torres said:

What you have right now could be put in the init.lua and be done with it. Since I have a bunch of scripts that do different things I started using the require function to import them into the init.lua depending on which one I wanted to use at any given time (I just comment out the ones I don't need).

Anyway, the files you shared above not only had redundant code but also had typos, but funnily enough, what you shared on the Hammerspoon discussion on Github doesn't contain those errors (because it's basically 99% what I had shared with you initially,).

Have a look at the attachment using the init.lua plus a separate file for the script. ipMIDI stopped working on my Mac mini for some reason so I could test properly but should work.

Good, the idea was to read what I wrote about how to set things up using the require function.

J.

TogglePluginCompareW_SSLMidi.zip 3.06 kB · 0 downloads

downloaded and launched into action ... deathly silence ...
but then I changed the name of the running process from 'Logic pro' to 'Logic pro X' and it worked!!! hooray! you made my day!

-- print available Virtual MIDI Sources to the Hammerspoon Console
local virtualSources = hs.midi.virtualSources()
print("Virtual Sources: " .. hs.inspect(virtualSources))

-- Create a new hs.midi object for the desired MIDI device by passing in the device name
local virtControl =  hs.midi.newVirtualSource("Port 3")
local windowFilter = hs.window.filter
local runScript = hs.osascript


-- AppleScript to click plugin Compare button
local clickCompareButton = [[
  tell application "System Events"
	  tell process "Logic Pro X"
        click checkbox "Compare" of window 1
	  end tell
  end tell
]]

-- Callback function for the Hammerspoon MIDI object created above (hs.midi.new)
-- Parameters: object, deviceName, commandType, description, metadata
-- Here we listen for incoming Control Change message that will trigger the AppleScript when received
local handleMidi = function(...)
  local commandType = select(3, ...)
  local metaData = select(5, ...)
  if commandType == 'controlChange' then
      if metaData.controllerNumber == 79 and metaData.controllerValue == 127 then
        runScript.applescript(clickCompareButton)
      end
  end
end


-- Create Window Filter for Logic Pro window
local logicWindowFilter = windowFilter.new('Logic Pro X')

-- Subscribe to events when Logic Pro window is in focus (or not)
logicWindowFilter:subscribe(windowFilter.windowFocused, function()
  -- Sets the callback for the Hammerspoon MIDI object when Logic Pro is in focus
  virtControl:callback(handleMidi)
  print('Logic in focus...')
end):subscribe(windowFilter.windowUnfocused, function()
  -- Removes the callback when Logic Pro loses focus
  virtControl:callback(nil)
  print('Logic not in focus...')
end)

 

  • Like 1
Link to comment
Share on other sites

Just now, vladistone said:

but then I changed the name of the running process from 'Logic pro' to 'Logic pro X' and it worked!!! hooray! you made my day!

Ah, that. Now I remember you said you're in High Sierra, so then your version of Logic is most likely called "Logic Pro X" and not "Logic Pro" as it's been renamed recently with newer versions.

Glad to hear it's working! 👍

J.

Link to comment
Share on other sites

2 minutes ago, Jordi Torres said:

Ok, ipMIDI is working again, not sure what went wrong, and what I shared in my previous post works as expected. Should work in your system too unless ipMIDI craps out for you too 😅

J. 

something else is strange - why did my script show the exactingness of the "Logic pro X" process, and you swallow "Logic pro"? perhaps from different versions of macOS?

Regards, Vladistone!

Link to comment
Share on other sites

My first implementation of my own queries:

On 16.03.2023 at 09:33, vladistone said:
  1.  
  2. how would you implement feedback to match the controller's scrabble strip?
  3. how the behavior of the keys and modification keys too is described (instant action? toggle? track the behavior of the modifier or "Follow key state first" soft-switch? responce for fire-mode?) in general, perhabce all is this  determined by the syntax of the functions?...

important for me - recieve a "fishing rod", examples of code injection in LPX!

And I will try to learn how to catch and "fry fish" as needed and the tasks set for myself.

 

Today I created a send message to use MCU LCD feedback about the information about assigning V-select to the LPX "compare on / off" button:

-- Create message feedback for MCU LCD "compare on/off" (real Device variation)
local midiDevice = hs.midi.new("ipMIDI")
print(string.format("myMidiDevice: %s", midiDevice))
midiDevice:sendSysex("F0 00 00 66 10 12 00 43 6F 6D 70 61 72 3A F7 F0 00 00 66 10 12 38 6F 6E 2F 6F 66 66 F7")

result at LCD into first track column as is:

|Compar:|
|on/off |

MIDI Sysex sends to the MCU midiDevice a string according to the Logic control MIDI Implementation:

  • Received: <Hdr>, 12, oo, yy, ..., F7 Update LCD
    • oo Display offset to write from: 00 thru 37 for upper line and 38 thru 6F for lower line.
    • yy Data: ASCII equivalents for display characters written from left to right,
      including line wrapping between upper and lower lines. Up to 100 data bytes
      may be sent in one message.
  • Transmitted: None

  The only thing that does not satisfy is that information is displayed both on the MCU and on the XT compartment (it is displayed simultaneously as virtualControl "Port 1" and "Port 2")
When I trying to assign output to specific one virtual port - "Port 2"

But - with no results...🤔

-- Create message feedback for MCU LCD "compare on/off" for Virtual Port:
local midiDevice = hs.midi.newVirtualSource("Port 2")
print(string.format("myVirtualPort: %s", midiDevice))
midiDevice:sendSysex("F0 00 00 66 10 12 00 43 6F 6D 70 61 72 3A F7 F0 00 00 66 10 12 38 20 6F 6E 2F 6F 66 66 F7")

 

Edited by vladistone
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...