onNoteOn || Trigger UI Button with Midi Note?
-
Am I doing this right?
function onNoteOn() { var n = Message.getNoteNumber(); var Button1 = Content.getComponent("Button1"); Message.ignoreEvent(false); Console.print(n); n == 60 ? Button1.setValue(1) : Button1.setValue(0); }
-
@Chazrox Nearly.
References to components (and modules) should only be created in
on init
and stored in aconst
.Within the MIDI callbacks you should use
local
instead ofvar
- in general, never usevar
unless it's the only choice.Message.ignoreEvent(false);
This isn't needed, Messages are not ignored by default.
You can shorten this too if you want:
n == 60 ? Button1.setValue(1) : Button1.setValue(0);
to
Button1.setValue(n == 60);
-
@d-healey alllmost! ha. Thanks.
@d-healey said in onNoteOn || Trigger UI Button with Midi Note?:
Button1.setValue(n == 60);
so slick.
-
@d-healey this isnt triggering the button. Is there a step I might be missing somewhere else? This is on the main interface script onNoteOn. Its triggering a sinewave generator right now but I plan to delete the sinwave generator and just use it as a midi player. 1 note/chord player.
-
@Chazrox If you want to trigger the button's action you need to call the
.changed()
function after setting the value -
@d-healey that works but I get stuck notes. Im trying to achieve a while-key-down effect. Im rewatching your "While Key Pressed" video but I dont think thats exactly what I need. What should I be looking for as far as apis?
-
@Chazrox what does your button do?
-
@d-healey my button is triggering a chord. I have everything scripted out and it works fine with mouse clicking the button. Just need the '1-note' part to work.
this is what my buttons callback looks like. ugly...but for some reason this works best for my use.
//! CHORD 2 BUTTON CONTROLS inline function onButton2Control(component, value) { local Chord2Choice = cmbChord2.getValue(); local chord2 = ChordLibrary[cmbChordType2.getValue() - 1]; local Octave2 = Knob2.getValue() * 12; if (value) { eventId3 = Synth.playNote(chord2[0] + 72 + Octave2 + Chord2Choice - 1, 64); eventId4 = Synth.playNote(chord2[1] + 72 + Octave2 + Chord2Choice - 1, 64); eventId5 = Synth.playNote(chord2[2] + 72 + Octave2 + Chord2Choice - 1, 64); eventId14 = Synth.playNote(chord2[3] + 72 + Octave2 + Chord2Choice - 1, 64); eventId16 = Synth.playNote(chord2[4] + 72 + Octave2 + Chord2Choice - 1, 64); eventId17 = Synth.playNote(chord2[5] + 72 + Octave2 + Chord2Choice - 1, 64); eventId18 = Synth.playNote(chord2[6] + 72 + Octave2 + Chord2Choice - 1, 64); Engine.setKeyColour(chord2[0] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[1] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[2] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[3] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[4] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[5] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); Engine.setKeyColour(chord2[6] + 72 + Octave2 + Chord2Choice - 1, SetKeyColour); } else { Synth.noteOffByEventId(eventId3); Synth.noteOffByEventId(eventId4); Synth.noteOffByEventId(eventId5); Synth.noteOffByEventId(eventId14); Synth.noteOffByEventId(eventId16); Synth.noteOffByEventId(eventId17); Synth.noteOffByEventId(eventId18); Engine.setKeyColour(chord2[0] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[1] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[2] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[3] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[4] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[5] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); Engine.setKeyColour(chord2[6] + 72 + Octave2 + Chord2Choice - 1, NoKeyColour); } }; Content.getComponent("Button2").setControlCallback(onButton2Control);
...12 Buttons mapped over 1 octave.
-
@Chazrox You need to trigger the button in the note off callback in addition to note on
-
@d-healey I must have wrote a funky code because I tried some stuff on onNoteOff but it was not off'ing. lol. Can you give me an example of that line please?
and theres a weird 'Blip' sound upon triggering my chords now.
can I pm you this snippet?
-
@Chazrox just the same as you have in the note on yes.
-
@d-healey Sorry I made a mess in your inbox.
-
@Chazrox You filthy bugger :p