MIDI input experiment

First test at trying to control the music with MIDI. This controls the cutoff with a knob on the controller:

    use_bpm 100

    co = 0 #cutoff

    live_loop "starp" do
      with_synth :dpulse do
        with_fx :reverb, room: 0.8 do
          play_pattern_timed [:c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4], [0.25],
            attack: 0.1,
            release: 0.25,
            cutoff: co
        end
      end
    end

    loop do
      ctrl, co = sync "/midi/mpkmini2/0/1/control_change"
    end

The first thing I’ve noticed is that the cutoff value doesn’t change until the next iteration of the play_pattern_timed, which isn’t exactly what I want, suppose that I could change it to 8 individual plays and sleeps.

Any other pointers?

EDIT: oops, should point out that this is not my composition. Y’all probably recognize it right off.

EDIT Shouldn’t try and do something quickly just before going to bed :slight_smile:
Some errors and unnecessary bits in the original now corrected.
The program below will work (based on yours)

use_bpm 100

co = 0 #cutoff

live_loop "starp" do
  n=(ring :c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4)
  d=knit 0.25,8)
  with_synth :dpulse do
    with_fx :reverb, room: 0.8 do
      play n.tick,
        attack: 0.1,
        release: 0.25,
        cutoff: co
      sleep d.look
    end
  end
end

live_loop :cl do
  ctrl,co = sync  "/midi/*/*/*/control_change"
  puts co
end

Notes:
I have used wild cards in the midi sync function.
I have removed the play pattern as this introduces a long delay before you can change the cutoff value, and instead used separate rings for the note and durations so that you can alter the cutoff for each note. {The knit function here produces (ring 0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25) }
It would be better to use set and get to pass the co value between the loops ie

set :c0,0 at the beginning and then
get(:co) wherever you want to retrieve the co value and
set :co,co
in the second loop :cl to store the co value read in the second loop.
You could set up individual values in d for more complex rhythms instead of all the same values.

2 Likes

Robin’s done the technical ‘fixy’ bit… so my turn… :slight_smile:

I dont know where you got your example from, but if you expand
it just a little, it becomes really nice.

Eli…

use_bpm 100

co = 0 #cutoff

with_fx :reverb, room: 0.8 do
  live_loop "starp2" do
    with_synth :dpulse do
      
      with_transpose -32 do
        play_pattern_timed [:c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4], [2],
          attack: 0.1,
          release: 2,
          cutoff: co
      end
    end
  end
  
  sleep 8
  
  live_loop "starp1" do
    with_synth :dpulse do
      with_transpose -12 do
        if rand() < 0.65
          sleep 4
        else
          play_pattern_timed [:c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4], [0.5],
            attack: 0.1,
            release: 0.5,
            cutoff: co
        end
      end
    end
  end
  
  sleep 4
  
  live_loop "starp" do
    with_synth :dpulse do
      if rand() > 0.65
        sleep 4
      else
        play_pattern_timed [:c4, :e4, :g4, :b4, :c5, :b4, :g4, :e4], [0.25],
          attack: 0.1,
          release: 0.25,
          cutoff: co
      end
    end
  end
  
end
1 Like