What's new

Displaying note event IDs and Engine Uptime values for each key pressed

KrisY

Noob in frenzy loop
Hello. I wanted to set the [ENGINE_UPTIME] for all the events [on note], then display one line of text for each [EVENT_ID] along with the engine uptime value for each event.

The aim is to calculate timings (later on) for a release sound. But that is not included yet. Now it´s just getting the correct engine uptime value for each event id.

Here is my script:


Code:
on init

  declare const $ARRAY_SIZE := 500
  declare %test_array[$ARRAY_SIZE]
  declare $a
  declare $note_count

  declare ui_label $label (2,6)
  set_text ($label,"")

end on


on note

  set_text($label,"")

  get_event_ids(%test_array)
  $a := 0
  $note_count := 0
  while($a < $ARRAY_SIZE and %test_array[$a] # 0)

    set_event_par(%test_array[$a],$EVENT_PAR_1,$ENGINE_UPTIME)

    add_text_line($label, "Event ID for this one is: " & %test_array[$a] & " and the engine uptime for this one is: " & get_event_par(%test_array[$a],$EVENT_PAR_1))

    inc($note_count)
    inc($a)
  end while

end on
The EVENT_ID:s are showing up okay in the label UI box, but the ENGINE_UPTIME entries are all the same. I mean, for each time I hold a few notes they are the same. When I release the keys and start over, they display a new number. But still all the same for all newly pressed keys.

Why is that?

Thanks for any help.
 
OP
K

KrisY

Noob in frenzy loop
Hi, there.
I think i talked about something like this in this thread:

https://vi-control.net/community/threads/question-about-on-note.75261/#post-4284474

Let me know if this is similar to what you're trying to do. (i may have spare code for this)

Cheers
Hey. Thanks a lot for the reply! :) The thread is pretty close to my application needs. The thing about release timing depending on engine uptime is interesting. I am working on a bigger script that will be including those things as well. Your reply on the other thread had good bits for me, except for the main issue in that thread, the "release variable" that Claud9 was referring to. The fixed slider part. I do not need that part.

But the part about entering on note ENGINE_UPTIMEs and storing them until a note_off event. That part I need. It´s kind of the basics of creating customized release times for manipulating change_vol and other things on release. Lord knows this part is unnecessarily complex :/ (for a software that has adequate release group functions already).

Any help there would be fantastic! :).

As for the above (this thread). The problem here is how to correlate an EVENT_ID inside of an array and use both the EVENT_ID and the corresponding ENGINE_UPTIME to set and retrieve values. I suppose your script parts might have something on that.
 

EvilDragon

KSP Wizard
You could probably use %NOTE_HELD array in your release callback, it's much simpler. That one will report how long each key was held down before release (in microseconds).
 

P.N.

Senior Member
You could probably use %NOTE_HELD array in your release callback, it's much simpler. That one will report how long each key was held down before release (in microseconds).
I don't get it - that (important) information is nowhere to be found in either K5 or K6 manuals...
That command actually stores the hold times automatically? Just like that?...
 

P.N.

Senior Member
Here's the engine uptime method anyway...

Code:
on init
    declare %start_time[128]
    declare %end_time[128]
end on

on note
    %start_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    %end_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " released. Held for " & %end_time[$EVENT_NOTE] - %start_time[$EVENT_NOTE] & " miliseconds.")
end on
 

EvilDragon

KSP Wizard
I don't get it - that (important) information is nowhere to be found in either K5 or K6 manuals...
That command actually stores the hold times automatically? Just like that?...

I misspoke. It's %NOTE_DURATION array ($NOTE_HELD is an integer var, not an array). K5 KSP reference, page 203, at the bottom. :)


And yes, it's just like that. It's been there in KSP since a long time ago. :) Note that it's key based, not event based - but key based is what you'd need anyways. And of course, it only makes sense when used in RCB.
 

P.N.

Senior Member
I misspoke. It's %NOTE_DURATION array
Ah, yes - that one does exist. :)

Basic example for the OP.

Code:
on note
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    message("Note: " & $EVENT_NOTE & " released. Held for " & %NOTE_DURATION[$EVENT_NOTE] / 1000 & " miliseconds.")
end on
 
OP
K

KrisY

Noob in frenzy loop
Here's the engine uptime method anyway...

Code:
on init
    declare %start_time[128]
    declare %end_time[128]
end on

on note
    %start_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    %end_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " released. Held for " & %end_time[$EVENT_NOTE] - %start_time[$EVENT_NOTE] & " miliseconds.")
end on

Thanks a lot!! Very helpful.
 
OP
K

KrisY

Noob in frenzy loop
I misspoke. It's %NOTE_DURATION array ($NOTE_HELD is an integer var, not an array). K5 KSP reference, page 203, at the bottom. :)


And yes, it's just like that. It's been there in KSP since a long time ago. :) Note that it's key based, not event based - but key based is what you'd need anyways. And of course, it only makes sense when used in RCB.
Okay, thanks. I had forgotten about NOTE_DURATION, silly of me. But Event base is probably what I´d need, cause i could hit the same key twice. Well of course, if the "on release" that is the trigger is triggered twice always that would be great. For on release, I guess it will. But for a release being triggered by a pedal off message / CC64 off, that would be better with EVENT_NOTE. We would not need 2 released notes for that. That would just produce phasing issues.

Will for sure tinker with that. Thanks a lot.
 
OP
K

KrisY

Noob in frenzy loop
Here's the engine uptime method anyway...

Code:
on init
    declare %start_time[128]
    declare %end_time[128]
end on

on note
    %start_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    %end_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " released. Held for " & %end_time[$EVENT_NOTE] - %start_time[$EVENT_NOTE] & " miliseconds.")
end on

Thanks a lot to both of you.

My aim is now to use %NOTE_DURATION in the on controller CC64 note off messages (just one per key), when the pedal releases the notes. Then on release, for note off messages generated if the pedal is not pressed and was not “%CC_TOUCHED“, use EVENT_ID:s with the $ENGINE_UPTIME instead, to get the correct amount of release messages. I´ll be using: (from this entry)
(I mean for the on release, no pedal used at release)

Code:
on init
    declare %start_time[128]
    declare %end_time[128]
end on

on note
    %start_time[$EVENT_ID] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    %end_time[$EVENT_ID] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " released. Held for " & %end_time[$EVENT_NOTE] - %start_time[$EVENT_NOTE] & " miliseconds.")
end on

Also, I will need a fade_out in there too to take care of prior notes. Perhaps a $previous_release variable to do that. Will try it.

Thanks again.
 
OP
K

KrisY

Noob in frenzy loop
Here's the engine uptime method anyway...

Code:
on init
    declare %start_time[128]
    declare %end_time[128]
end on

on note
    %start_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " held.")
end on

on release
    %end_time[$EVENT_NOTE] := $ENGINE_UPTIME
    message("Note: " & $EVENT_NOTE & " released. Held for " & %end_time[$EVENT_NOTE] - %start_time[$EVENT_NOTE] & " miliseconds.")
end on

Great piece of code there. Wrote a little script that shows the notes held, the IDs and the ms on release here:

(just to be able to see if things are doing what they´re supposed to)


Code:
on init

  declare %start_time[128]
  declare %start_time_event_id[128]
  declare %end_time[128]
  declare %end_time_event_id[128]

  declare $f
  declare ui_label $label3 (3,6)
  set_text ($label3,"")

  declare $g
  declare ui_label $label4 (3,6)
  set_text ($label4,"")

end on

on note

    %start_time[$EVENT_NOTE] := $ENGINE_UPTIME
    %start_time_event_id[$EVENT_NOTE] := $EVENT_ID

    message("Note nr " & $EVENT_NOTE & " with Engine Uptime of " & %start_time[$EVENT_NOTE] & " with Event-ID " & %start_time_event_id[$EVENT_NOTE] & " is held now.")

    set_text ($label3,"")
    $f := 0
    while($f < 128)
 
        if (%start_time_event_id[$f] = 0)
     
          add_text_line($label3, "Note nr: " & $f & " is not held!")

        else

          add_text_line($label3, "Note nr: " & $f & " with Event-ID " & %start_time_event_id[$f] & " and the timestamp " & %start_time[$f] & " is held.")

        end if
   
      inc($f)
    end while

end on

on release

    %end_time[$EVENT_NOTE] := $ENGINE_UPTIME
    %end_time_event_id[$EVENT_NOTE] := $EVENT_ID

    message("Note nr " & $EVENT_NOTE & " with Engine Uptime of " & %start_time[$EVENT_NOTE] & " with Event-ID " & %start_time_event_id[$EVENT_NOTE] & " is held now.")

    set_text ($label4,"")
    $g := 0
    while($g < 128)
 
        if (%start_time_event_id[$g] = 0)
     
          add_text_line($label4, "Note nr: " & $g & " wasn´t held!")

        else

          add_text_line($label4, "Note nr: " & $g & " with Event-ID " & %end_time_event_id[$g] & " was released after " & %end_time[$g] - %start_time[$g] & " ms.")

        end if
   
      inc($g)
    end while

end on
It does this:

Screen Shot 2019-02-07 at 00.05.21.png

The script produces a list for note on and on release, although it does it everytime a note event occurs. Perhaps there is a better way to "update" each line there. But still, for whomever reads this issue.

note: in the image there is an error that I fixed in the code now. The part in the right column, "... and the timestamp...", is removed in the script for on release.
 
Top Bottom