Please be advised that due to scheduled infrastructure maintenance, we anticipate downtimes for the Native Instruments websites and Native Access on February 28, 2024 starting at 06:00 CET. For more details, click here.

Choking previous sample played when same MIDI note is struck again.

JordonBeal
JordonBeal Member Posts: 11 Member

I'm working on a drum instrument, and I've been driving myself crazy trying to implement this functionality.

Say I have a set of random round-robins for Tom 1 in one group tied to a MIDI note, in this case 42. This is working perfectly, however, I would like to choke the previous Tom 1 sample played when MIDI note 42 is struck again, so that the previous sample does not sustain through the next.

I've tried working with EVENT_ID and fade_out, but I'm a bit stuck. This is the code that I have so far:


on note

{*Tom1 RR*}

if ($EVENT_NOTE=$ART_Tom1)

fade_out(ALL_EVENTS, 1, 1) {*This is what I would like to change*}

change_note($EVENT_ID,%RRobin[$RRCount])

ignore_event($EVENT_ID)

disallow_group($ALL_GROUPS)

call rr_random

allow_group(find_group("Tom1"))

play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)

end if

end on


Let me know if more information is needed, or if I haven't explained this properly. I know what I'm after, I'm just not sure how to articulate it properly.

Tagged:

Best Answer

  • Reid115
    Reid115 Member Posts: 47 Member
    edited January 2022 Answer ✓

    Make an array where the indexes are the note numbers and the values are the last event IDs that played those note numbers. In my experience it's also a good idea to use a fadeout time of 1000-4000 microseconds, as a single microsecond fadeout will likely result in a pop sound.

    on init
        declare %note_ID[128] := (0)
        declare $new_id
    end on
    
    on note
        ignore_event($EVENT_ID)
        if ($EVENT_NOTE = 60)
            fade_out(%note_ID[60], 10, 1)
            $new_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
            %note_ID[60] := $new_id
        end if
    end on
    

Answers

  • Reid115
    Reid115 Member Posts: 47 Member
    edited January 2022 Answer ✓

    Make an array where the indexes are the note numbers and the values are the last event IDs that played those note numbers. In my experience it's also a good idea to use a fadeout time of 1000-4000 microseconds, as a single microsecond fadeout will likely result in a pop sound.

    on init
        declare %note_ID[128] := (0)
        declare $new_id
    end on
    
    on note
        ignore_event($EVENT_ID)
        if ($EVENT_NOTE = 60)
            fade_out(%note_ID[60], 10, 1)
            $new_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
            %note_ID[60] := $new_id
        end if
    end on
    
  • JordonBeal
    JordonBeal Member Posts: 11 Member
    edited January 2022

    Something like this?

    on init

      declare %note_ID[128] := (0)

    end on


    on note

    ignore_event($EVENT_ID)

    if ($EVENT_NOTE = 42)

      fade_out(%note_ID[42], 10, 1)

      %note_ID[42] := $EVENT_ID

    if ($EVENT_NOTE=$ART_Tom1)

    change_note($EVENT_ID,%RRobin[$RRCount])

    ignore_event($EVENT_ID)

    disallow_group($ALL_GROUPS)

    call rr_random

    allow_group(find_group("Tom1"))

    play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)

    end if

    end if

    end on


    I thought it was working at first, but it seems that the previous note is still ringing out. Maybe I've got this all screwed up. And apologies for the bad code formatting, I'm not sure how to get it to display properly here.

  • Reid115
    Reid115 Member Posts: 47 Member
    edited January 2022

    Oh sorry I messed up. The note ID I was putting in the array was $EVENT_ID which gets ignored, so fading that out does nothing. The note you actually hear (triggered by play_note()) will have a different ID, so put that ID in the array. By the way, you can enter code with the paragraph symbol on the left of the comment box.

    on init
        declare %note_ID[128] := (0)
        declare $new_id
    end on
    
    on note
        ignore_event($EVENT_ID)
        if ($EVENT_NOTE = 60)
            fade_out(%note_ID[60], 10, 1)
            $new_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
            %note_ID[60] := $new_id
        end if
    end on
    
  • EvilDragon
    EvilDragon Moderator Posts: 1,019 mod

    @JordonBeal How to post code blocks here:



Back To Top