Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kenny_g.rb: Making Ruby Write Smooth Jazz (Open...

kenny_g.rb: Making Ruby Write Smooth Jazz (Open Source Bridge 2015)

For too long, computers have been shut out of the red-hot music-to-listen-to-while-relaxing-in-the-bathtub genre. Today, that all changes. Our smooth-jazz-as-a-service startup is primed to disrupt this stale industry. All we need is a little Ruby and we'll make automated musical magic.

Avatar for Tim Krajcar

Tim Krajcar

June 24, 2015
Tweet

More Decks by Tim Krajcar

Other Decks in Technology

Transcript

  1. TimKrajcar Jason Clark - Testing the Multiverse Wednesday 3:45pm -

    B301 Zoe Kay - Venturing into the Spooky Science of Ruby Thursday 3:45pm - B301 Ward Cunningham - Learning and Knowing with Federated Wiki Jonan Scheffler - Hacking Minecraft
  2. TimKrajcar strategy inspiration: reddit™ (reddit doesn't like it if you

    use their logo without a license so I'm not using it) REDDIT and the ALIEN Logo are registered trademarks of reddit inc.
  3. TimKrajcar "[...]when logged in as an admin, a third field

    appeared that allowed the team to enter a custom user name that would automatically be registered for an account upon hitting submit." http://venturebeat.com/2012/06/22/reddit-fake-users/
  4. TimKrajcar we need to record a "phrase" a short bit

    of music that transitions from "zero" to an interval
  5. TimKrajcar [ { "note": 60, "velocity": 80, "starting_time_offset": 0.677646, "duration":

    0.248938 }, { "note": 67, "velocity": 65, "starting_time_offset": 0.920729, "duration": 0.27753 }, { "note": 64, "velocity": 72, // ...
  6. TimKrajcar MIDI.using(@output) do @notes = JSON.parse(File.read("sample.notejs")) @offset = 0 @notes.each

    do |note| sleep(note["starting_time_offset"] - @offset) play note["note"], note["duration"] @offset += note["duration"] end end
  7. TimKrajcar MIDI.using(@output) do @notes = JSON.parse(File.read("sample.notejs")) @offset = 0 @notes.each

    do |note| sleep(note["starting_time_offset"] - @offset) play note["note"], note["duration"] @offset += note["duration"] end end
  8. TimKrajcar MIDI.using(@output) do @notes = JSON.parse(File.read("sample.notejs")) @messages = @notes.flat_map do

    |note| [ {type: :note_on, note: note["note"], velocity: note["velocity"], at: note["starting_time_offset"]}, {type: :note_off, note: note["note"], at: note["starting_time_offset"] + note["duration"]} ] end @messages.sort! do |a, b| a[:at] - b[:at] end
  9. TimKrajcar @offset = 0 @messages.each do |message| sleep(message[:at] - @offset)

    if message[:type] == :note_on note message[:note], velocity: message[:velocity] else note_off message[:note] end @offset += sleep_duration end