Off to the Races!

Typing this feeling extremely excited - setting up serial OSC was very straight forward, my first code is really just to test out osc message passing to and from the Monome - doing nothing special other than turning the 8x8 into a sample pad to explore the built in samples (I am loving the :tabla group) .

I am most excited and impressed about how comparatively simple it was getting and using input from OSC and Midi - I am genuinely giddy with the ability to use and reference 2 separate control surfaces to tap out some fun sounding beats.

# Welcome to Sonic Pi
# Setup Serial OSC for Monome

use_osc "localhost", 11117

### Shamelessly stolen from Forum
define :c2n do | x, y |
  num = x.to_i + 8 * y.to_i
  puts num
  return num
end

define :n2c do | n |
  x = n % 8
  y = n / 8
  coords = [x.to_i, y.to_i]
  return coords
end


#### Blinky lights on the Monome:
#### Simulating 4x16 step tracks

live_loop :test_monomes do
  use_real_time
  x,y = n2c(look)
  osc "/monome/grid/led/set",x,y,1
  osc "/monome/grid/led/set",x,y+2,1
  osc "/monome/grid/led/set",x,y+4,1
  osc "/monome/grid/led/set",x,y+6,1
  
  sleep 0.125
  
  #### Testing rotating the blinky light orientation
  
  if look == 15
    tick_reset
    ##| osc "/sys/rotation", (ring 90,180,270,0).tick(:rotate)
  end
  osc "/monome/grid/led/set",x,y,0
  osc "/monome/grid/led/set",x,y+2,0
  osc "/monome/grid/led/set",x,y+4,0
  osc "/monome/grid/led/set",x,y+6,0
  tick
end

#### Sync messages from the Nano and set thread-safe variables
live_loop :listen_kontrol do
  use_real_time
  a, b = sync "/midi:nanokontrol_slider_knob:1/control_change"
  case a
  when 2
    set :kontrol_1, b
  when 3
    setter = (b/127.0)*0.99
    puts setter
    set :kontrol_2, setter
  end
end

#### Play samples based on button press
live_loop :listen_monome do
  use_real_time
  x, y, s = sync "/osc:127.0.0.1:11117/monome/grid/key"
  
  pressed = c2n(x, y)
  #### Only play on 'press' message
  if s == 1
    k1 = get[:kontrol_1]
    k2 = get[:kontrol_2]
    puts k1,k2
    with_fx :hpf, cutoff: k1 do
      with_fx :distortion, distort: k2 do
        case pressed
        when 0..7
          sample sample_names(:tabla)[pressed+16]
        when 8..12
          puts pressed
          sample sample_names(:sn)[pressed-7]
        when 13..22
          sample sample_names(:perc)[pressed-13]
        when 23..34
          sample sample_names(:bd)[pressed-22]
        when 35..43
          sample sample_names(:bass)[pressed-34]
        when 44..63
          sample sample_names(:hat)[pressed-43]
        else
          puts "It's something else"
        end
      end
    end
  end
end
1 Like