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

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.
Best 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
0
Answers
-
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
0 -
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.
0 -
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
0 -
1
Categories
- All Categories
- 19 Welcome
- 1.5K Hangout
- 65 NI News
- 797 Tech Talks
- 4.1K Native Access
- 16.8K Komplete
- 2K Komplete General
- 4.4K Komplete Kontrol
- 5.8K Kontakt
- 1.6K Reaktor
- 386 Battery 4
- 854 Guitar Rig & FX
- 433 Massive X & Synths
- 1.3K Other Software & Hardware
- 5.8K Maschine
- 7.4K Traktor
- 7.4K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators