What's new

Sending Messages From Instrument to Multiscript (Without User's Interaction)

Hi,

first I thought this would be an easy task but after some attempts, I decided to ask for some advice here. It is very easy to send a message from an instrument to multiscript with a user's interaction, but I can't find a way to do so without it.

My attempts:
- I tried loading nka: that doesn't work as it can only happen in pgs_changed (not possible in multi), persistence_changed (can't be triggered multiple times within the script) or ui_control (learn midi automation is not possible in multi).
- Moreover, midi_in doesn't work as play_note or set_controller doesn't trigger the callback.

Is there another approach I forgot about?
I'd be grateful for any information.

Best,
Patrik
 
Can you show us a short example?

Sure! It depends what you consider a user interaction, but the solution works for my purposes :) Here I made two short scripts for you:

sender.ksp:
Code:
on init
    make_perfview
    message("")
    declare ui_switch sent
        set_text(sent, "Send C to ch:")
    declare pers ui_value_edit channel (1,10,1)
        move_control(channel, 2,1)

    set_listener(NI_SIGNAL_TIMER_MS, 100000)
end on
on persistence_changed
    set_controller(119, channel-1)
end on

on listener
    if (sent = 1)
        set_controller(109, 60) // C3
        set_controller(110, 65) // velocity
        sent := 0
    end if
end on

on ui_control(channel)
    set_controller(119, channel-1)
end on

receiver.ksp (multiscript):
Code:
on init
    message("")
    declare ui_button cycle_on
    set_text(cycle_on, "Enable")
    declare pers ui_value_edit sender_ch (1,16,1)
end on

function receiver
    while (cycle_on = 1)
        if (CC[109] > 0)
            set_midi(CC[119], MIDI_COMMAND_NOTE_ON, CC[109], CC[110])
            set_midi(sender_ch-1, MIDI_COMMAND_CC, 109, 0)
            wait(100000)
            set_midi(CC[119], MIDI_COMMAND_NOTE_ON, 60, 0)
        end if
        wait_ticks(ms_to_ticks(10000))
    end while
end function

on ui_control(cycle_on)
    call receiver
end on

on midi_in
    if (MIDI_CHANNEL = sender_ch-1 and cycle_on = 0)
        cycle_on := 1
        call receiver
    end if
end on

1. First, make a new instrument and insert the sender code there.
2. Open the instrument which you want to control, set the midi channel to something else than sender's.
3. Paste the second script to a multiscript slot.

There are two ways to enable the receiver:
- Either you click the "Enable" button and set the sender's instrument midi channel to 1, or
- You press a key or use any controller - that starts the loop.

Note: I wouldn't consider clicking of the button in sender being user interaction because the sending happens in LCB.

Obviously you can build a whole event system for sending messages or multiple events at the same time from your instrument to the multi :)

I'd also like to mention that I tried many many ways to try to send the message and this was the only way I could make it work. Multiscripts are very very limited.

Best of luck!
Patrik
 
Last edited:
Interesting. What I find strange here is that the receiver "on midi_in" is indeed being triggered by an NKI scripted "set_controller", enough to call the function "receiver". But not triggered enough to actually do anything else in the "on midi_in" itself. Very odd.
 
Well, kind of. "on midi_in" is actually not being triggered by "set_controller" at all, which is the whole issue which I was pulling my hair out for :laugh: That's where "receiver" comes from and watches for CC change to happen.

Here is also a video showing how to set up the receiver for both cases:
 
Top Bottom