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

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

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.

2fad1f0f6ab9b2a4ed6699e2c96c9a45?s=128

Tim Krajcar

June 24, 2015
Tweet

Transcript

  1. kenny_g.rb: Making Ruby write smooth jazz Tim Krajcar

  2. TimKrajcar https://www.flickr.com/photos/can_eldem/6929385615

  3. TimKrajcar https://www.flickr.com/photos/can_eldem/6929385615

  4. –Johnny Appleseed https://www.dropbox.com/s/8t7mg4gikhx0d5p/Screenshot %202015-06-09%2019.12.34.png?dl=0

  5. –Johnny Appleseed

  6. –Johnny Appleseed bit.ly/ OSBridgeNRJobs

  7. 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
  8. TimKrajcar Tim Krajcar's twitter handle is: @TimKrajcar

  9. TimKrajcar

  10. TimKrajcar story time

  11. TimKrajcar https://www.flickr.com/photos/gruenewiese/15668094425

  12. TimKrajcar https://www.flickr.com/photos/vironevaeh/4494702797/

  13. TimKrajcar audience participation!

  14. https://www.flickr.com/photos/kimli/1879624559/

  15. TimKrajcar IS HE A WIZARD??

  16. TimKrajcar https://www.flickr.com/photos/mhx/16419218393

  17. TimKrajcar https://www.flickr.com/photos/mhx/16419218393 I could do that

  18. TimKrajcar can it be automated?

  19. TimKrajcar can it be automated?

  20. TimKrajcar can it make me lots of money without me

    doing any work?
  21. TimKrajcar some background

  22. TimKrajcar MIDI Musical Instrument Digital Interface

  23. TimKrajcar MIDI = protocol for control

  24. TimKrajcar MIDI ≠ audio

  25. TimKrajcar MIDI is messages

  26. TimKrajcar note on (note, velocity 0-127)

  27. TimKrajcar note off (note)

  28. TimKrajcar also lots of other things
 (program and control changes,

    aftertouch, pitch bend, sysex, ...)
  29. TimKrajcar

  30. None
  31. None
  32. TimKrajcar

  33. TimKrajcar MIDI is fun!

  34. –Johnny Appleseed

  35. TimKrajcar the challenge: build a tool that plays delightful piano

    music based on a series of four notes
  36. TimKrajcar the challenge: build a tool that plays delightful piano

    music based on a series of four notes
  37. TimKrajcar the challenge: build a STARTUP that plays delightful piano

    music based on a series of four notes
  38. –Johnny Appleseed

  39. TimKrajcar first strategy: algorithmic harmony

  40. –Johnny Appleseed

  41. –Johnny Appleseed

  42. TimKrajcar algorithmic music = not very relaxing https://www.youtube.com/watch?v=TAHamdXqTTI

  43. TimKrajcar this is really hard

  44. TimKrajcar user persona!!

  45. https://www.flickr.com/photos/santheo/531632789

  46. https://www.flickr.com/photos/santheo/531632789 STEVE

  47. https://www.flickr.com/photos/santheo/531632789 STEVE STEVE'S DUCK

  48. TimKrajcar what to do?

  49. 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.
  50. 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/
  51. TimKrajcar like any good startup, we will CHEAT!

  52. TimKrajcar like any good startup, we will CHEAT!

  53. TimKrajcar like any good startup, we will utilize pre-recorded interactions

    to simulate real- time generative algorithms!
  54. TimKrajcar play back pre-recorded "transitions" between chords

  55. –Johnny Appleseed

  56. –Johnny Appleseed

  57. –Johnny Appleseed

  58. –Johnny Appleseed

  59. –Johnny Appleseed

  60. –Johnny Appleseed we need to write transitions for all of

    these?!
  61. TimKrajcar BIG MUSIC SECRET!!!

  62. TimKrajcar THE SECRET: you just need the relative intervals

  63. TimKrajcar transpose using the first note as "zero"

  64. TimKrajcar we need to record a "phrase" a short bit

    of music that transitions from "zero" to an interval
  65. TimKrajcar play back and repeat as needed

  66. TimKrajcar let's do it

  67. TimKrajcar https://github.com/tkrajcar/kenny_g.rb

  68. TimKrajcar tech demo 1: all the keys

  69. TimKrajcar require "midi" @output = UniMIDI::Output.use(:first) MIDI.using(@output) do velocity 64

    (0..127).each do |n| play n, 0.01 end end
  70. TimKrajcar tech demo 2: recording our phrases

  71. TimKrajcar saving notes! sounds like a job for MIDI!

  72. –Johnny Appleseed

  73. –Johnny Appleseed

  74. –Johnny Appleseed

  75. TimKrajcar we'll just make up our own standard

  76. TimKrajcar big news!!

  77. None
  78. TO HACKER NEWS!!

  79. 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, // ...
  80. TimKrajcar tech demo 3: playback!

  81. 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
  82. TimKrajcar https://www.flickr.com/photos/deivis/2300233581/

  83. TimKrajcar https://www.flickr.com/photos/deivis/2300233581/ DO NOT SHIP IT

  84. 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
  85. TimKrajcar tech demo 4: playback better!

  86. 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
  87. 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
  88. TimKrajcar tech demos complete! almost ready for funding!

  89. TimKrajcar the patent-pending kenny_g.rb algorithm

  90. TimKrajcar step 1: convert user-provided chords to relative intervals, with

    the first chord as 0
  91. TimKrajcar input: F, A, C, D relative intervals: [0, 4,

    7, 9]
  92. TimKrajcar step 2: convert list of intervals to list of

    phrase transitions
  93. TimKrajcar input: [0, 4, 7, 9] phrase transitions: {0, +4},

    {4, +3}, {7, +2}
  94. TimKrajcar step 3: play back pre-recorded phrases, transposed into starting

    key
  95. TimKrajcar DEMO!

  96. TimKrajcar thanks!