If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Altering Midi Events in Ruby.
13 posts
• Page 1 of 2 • 1, 2
Altering Midi Events in Ruby.
Hello Everyone,
I'll try to say this as clear as possible. I'm splitting a midi event and catching it in ruby. What I need to do is change the midi note into a random note from a given note pool. So far I manage to pick the random note and place it into the output midi event but it doesn't respond to note off. Is there a fairly simple way to do this? I think my problem is that I can't hold the current note so to be able to stop it later...
Thank for any reply!
I'll try to say this as clear as possible. I'm splitting a midi event and catching it in ruby. What I need to do is change the midi note into a random note from a given note pool. So far I manage to pick the random note and place it into the output midi event but it doesn't respond to note off. Is there a fairly simple way to do this? I think my problem is that I can't hold the current note so to be able to stop it later...
Thank for any reply!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Altering Midi Events in Ruby.
FS - USER - GUIDE
pag. - 219 -
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Altering Midi Events in Ruby.
Thanks for the response Tronic, but I got all my variables in place. I split the midi event and work with the status, data1 and data2 values.
This is my logic:
prvNote = @oldNote # Here I try to catch the note that went out last.
if @status == 144
rndNote = @data1[rand(@data1.lenght)] # Here I pick a random note from the note pool to replace the incoming note
output 0, Midi.new 144,1,rndNote,@data2
prvNote = rndNote
output 1, prvNote # To catch it with oldNote
elsif @status == 128
output 0, Midi.new 128,1,prvNote,@data2 # Here I try to stop that last note
end
The problem is that it doesn't stop. it keeps playing.
This is my logic:
prvNote = @oldNote # Here I try to catch the note that went out last.
if @status == 144
rndNote = @data1[rand(@data1.lenght)] # Here I pick a random note from the note pool to replace the incoming note
output 0, Midi.new 144,1,rndNote,@data2
prvNote = rndNote
output 1, prvNote # To catch it with oldNote
elsif @status == 128
output 0, Midi.new 128,1,prvNote,@data2 # Here I try to stop that last note
end
The problem is that it doesn't stop. it keeps playing.
Last edited by aefa on Mon Feb 01, 2016 7:26 pm, edited 1 time in total.
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Altering Midi Events in Ruby.
You have to schedule the output event with some relative duration time, to generate the NOTE off event.
see pag. -221- example
see pag. -221- example
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Altering Midi Events in Ruby.
I forgot to mention that I'm quite the noob at this. I can see how the processing is being made but fail to see how it would help me send note off event. Can you give me an example related to a midi event? please...
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Altering Midi Events in Ruby.
shedule events?
trig -> ruby process -> output trig happen only when the process is finisched
so in the event method you have some methods variables
trig -> ruby process -> output trig happen only when the process is finisched
so in the event method you have some methods variables
- Code: Select all
def event( input_index, value_at_index, time_at_trig)
# so to schedule an event time that happen an bit later you have to use the method:
# output [index of output], [value to send], [current_time + waiting_delay_time]
# [current_time + waiting_delay_time]
# -> schedule this event only when current_time is > of current_time+waiting_delay_time
@note_length = 1 # in seconds
output 0, @yourNoteoff_midi_object, time_at_trig + @note_length
end
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Altering Midi Events in Ruby.
Thank you very much Tronic. I'll try that and let you know!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Altering Midi Events in Ruby.
Hi Trinic, I did try the way you suggested (though not exactly) I wanted to get the input note from a keyboard or piano roll and change it to a random one and it had to last as long as the key/p-r note was on. How did I fix it? I split the output midi event, got the data 1, fed it through a loop back and that took care of the problem. The random note generator event was generating a different note on the note-off that's why I couldn't catch it before.
Thank you very much for the insights!
Thank you very much for the insights!
- aefa
- Posts: 48
- Joined: Wed Mar 26, 2014 12:52 pm
Re: Altering Midi Events in Ruby.
if I understand correctly, you want to simply replace the current note with a random note, right?
then the only thing to do is replace the data1 coming with that random, leaving intact the rest of the data.
EDIT: this work only with sequencially midi mote played and released
then the only thing to do is replace the data1 coming with that random, leaving intact the rest of the data.
- Code: Select all
### assign to this var the first input connector
@midi_in = @ins[0]
### midi note pool container
### note the "||" operator that mean:
### initialize it only if is nil, after that it is not modified anymore
@midi_Pool ||= []
### replace and add note random to the pool only if note_on
@random_note_range = (32..64)
@midi_Pool << @midi_in.data1 = rand(@random_note_range) if @midi_in.status == 144
### set to note_off the last played note in the pool
@midi_in.data1 = @midi_Pool.last if @midi_in.status == 128
### remove the released note from the pool
@midi_Pool.pop if @midi_in.status == 128
### output the current modified midi object to the output
output 0, @midi_in
EDIT: this work only with sequencially midi mote played and released
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Altering Midi Events in Ruby.
This work with an correct midi pool order.
The code is for learning purpose, conditional used anyware...
The code is for learning purpose, conditional used anyware...
- Code: Select all
def init
@midi_pool = {};
@note_on = 144
@note_off = 128
end
def event i
@midi = @ins[0]
@rnd_note = rand(32..64)
@midi_pool[@midi.data1] = @rnd_note if @midi.status == @note_on && @midi_pool[@midi.data1].nil?
@note_released = @midi_pool.delete(@midi.data1) if @midi.status == @note_off
@midi.data1 = @midi_pool[@midi.data1] if @midi.status == @note_on && @note_released
@midi.data1 = @note_released if @midi.status == @note_off && @note_released
output 0, @midi if @note_released
watch [@midi_pool,@note_released]
end
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
13 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: Google [Bot] and 109 guests