Making Chord Progressions using Sonic Pi

Music

I have to confess that I love music and code. When I get to share my two favorite things in one package, it gets me excited. In previous blog posts, I had talked about an amazing tool called Sonic-Pi for introducing music theory and computer science. While preparing this blog post, I had forgotten how much I enjoy generative music through code.

For the post today, we’re going to focus on making chord progressions and generating arpeggios. Let’s define a few terms before we dive into code.

  • Chords – In music theory, we define a chord as a named collection of notes.  In western music, there are two major flavors of chords. (Major and minor)  Major chords feel happy.   Minor chords are often used in movie scores to represent darker moments or points of anticipation.  For a more formal discussion of chords, check out this article from Wikipedia.  For the purpose of this blog post, keep in mind that a chord has three notes: the root, third, and fifth.
  • Chord progressions – Chord progressions define a sequence of chords that make up a song.    This sequence of chords represents a major component of the soul or emotional thread of a song.
  • Arpeggios – An arpeggio represents a way to play the notes of a chord over time.

We should note that chord progressions for the western ear follow patterns.   The human ear enjoys hearing chord changes according to the circle shown below.  To keep things simple, you can make small transitions between one area of this circle.   You can execute the following chord progression and your eye will believe that it’s pleasing: G,C,D,C.    If your song moves from a G major chord to a D flat major, your ear will not find this automatically pleasing.  It will probably sound weird.

 

Circle of fifths

Circle of fifths

 

With this brief overview of music theory, I wanted to share a small Sonic-Pi program I’m using to enable students to play with chords, chord progressions, and arpeggios. You can inspect the code here.

Let’s break down the major ideas:

In the following code, we configure Sonic-Pi to the tempo of 130 beats per minute(BPM). We also create a Ruby array to hold the list of chords. Sonic-Pi already has a function to generate major and minor chords. We add the chord to the array using a push method.


use_bpm(130)

chord_list = []

chord_list.push(chord(:D4,:minor))
chord_list.push(chord(:A4,:major))
chord_list.push(chord(:D4,:minor))
chord_list.push(chord(:c4,:major))
chord_list.push(chord(:F4,:major))
chord_list.push(chord(:c4,:major))
chord_list.push(chord(:D4,:minor))
chord_list.push(chord(:A4,:major))

We need some way to loop over the chord_list and play each of them. The following code accomplishes this. We place the loop in a thread so that this music idea can exist in parallel with other musical ideas. We configure Sonic-Pi to use the “dtri” synth because it’s cool. The “pick_pattern2” function is something I’ve written to render out our arpeggio.


in_thread do
use_synth :dtri
loop do
for c in chord_list
pick_pattern2(c)
end
end
end

Let’s define “pick_pattern2”. In the following Ruby function, we’re giving a small collection of code a name. We pass in a chord to be played. In Sonic-Pi, a chord is simply an array of notes. In the first part of the code, we generate 6 notes based on the chord. Element zero represents the root of the chord. Element 1 represents the third. Element 3 represents the fifth. We generate notes 4 to 6 to be one octave above the ones previously mentioned. The rest of the code plays out notes in a timed manner. In general, we’re placing each note a half beat away from each other. The sequence is more artistic than technical.

def pick_pattern2(chord)
note1 = chord[0]
note2 = chord[1]
note3 = chord[2]
note4 = chord[0] + 12
note5 = chord[1] + 12
note6 = chord[2] + 12

play(note1)
sleep(0.5)
play(note2)
sleep(0.5)

play(note3)
sleep(0.5)
play(note4)
sleep(0.5)

play(note5)
sleep(0.5)
play(note6)
sleep(0.5)

play(note3)
sleep(0.5)
play(note4)
sleep(0.5)

end

There’s a few other functions for generating arpeggios. Feel free to play with them and edit them. If you make something cool, leave us a comment below. I’d love to hear what you’re making!!

Photo credit to Trey Jones.

7 Free Apps for 3D Design and Building Cool Stuff

Chess graphic

AutoDesk TinkerCAD – This web-based application has become my favorite way to introduce 3D design to makers of all ages.  It comes with accessible tutorials to help you understand the software quickly.  I have used TinkerCAD.com to engage students as early as 3rd grade due to the high usability of this product.   You can quickly export your 3D modeling content for 3D printing or online 3D printing services.   Students LOVE being able to export their work to Minecraft too!  Autodesk just added a “Minecraft” preview feature too!  We also export “obj” files that we can use in Unity 3D.

Shape Shifter – ShapeShifter.io enables you to build artistic 3D structures with just a few clicks.   While this app isn’t your traditional 3D modeling tool, some of the art forms that you can build are impressive.   You might find this application helpful in building a decorative cup holder, vase, or home decor.

Sketchup – This application has become a standard in 3D modeling for home decor and building structures.   Sketchup has content viewers for iOS, Android, and HoloLens. (not free)   This mature 3D building tool comes with a robust set of tutorials and support community.

Blender:  To be honest, I’m still in the process of learning Blender.  According to Wikipedia, Blender is a “professional free and open-source 3D computer graphics software product used for creating animated films, visual effects, art, 3D printed models, interactive 3D applications and video games.”  This open source software supports impressive features including soft body simulation, sculpting, rendering, and an integrated game engine.  While this is one of the most challenging 3D modeling tools to learn, you can leverage a robust community of YouTube tutorials for Blender or the Blender manual.

Onshape: This relatively new 3D modeling tool has become a favorite for adult makers and professionals.   Many of my maker space friends celebrate the robust tutorial system and standard parts collection.  The tool can model the movement of assemblies of 3D parts.  The OnShape team has designed their product to serve distributed professional teams who enjoy working an online cloud solution.  You can learn more about on their YouTube channel.

Sculptris: This application by Pixologic provides an introduction to CG 3D modeling especially for artists.   This product focuses on the “sculpture” metaphor of building 3D content.  It seems very appropriate for building organic 3D structures, animals, or characters.    Learn more at http://pixologic.com/sculptris/.

OpenJSCAD: I came across a tool called OpenJSCAD.org that empowers programmers to build 3D models using the popular JavaScript programming language or OpenSCAD language.  It’s pretty fun!   The tool enables you to export your creations to STL format for 3D printing or editing.   Code and build 3D stuff!  It’s that easy!

Keep in mind that this blog post only scratches the surface of free products.  AutoDesk offers free products for hobbyists, students, and educators.

This blog post outlines 20 additional free 3D modeling tools.

 

We enjoy hearing from you!  Let us know if you make anything cool.  Leave a comment below.

 

Photo credit: NoxicTonic – https://flic.kr/p/drEc9F

 

 

Applications of HoloLens in Education and Training

HoloLens and a brain

The Microsoft HoloLens has become the leading device in heads-up augmented reality. You can think of the HoloLens as a Windows 10 computer that you wear on your head with amazing context awareness of your room, your location, and direction of focus. The location and mapping capabilities of this device enable users to place 3D content or holograms in your work environment. As you place holograms in your work environment, the objects feel like they are physically fixed, stable, and present. As I have had the opportunity to study this device, I have become interested in ways that trainers or educators might use this technology. At a price point of $3000, the Microsoft Hololens will not be showing up in your K-12 classroom anytime soon. I believe it’s interesting to anticipate how educators will use it. In this post, I believe that trainers and educators will use devices like HoloLens to engage their students with visualizations of complex structures and processes. I would hope that students someday use the device as a platform to learn through their creativity.

Hololens

It should be noted that the Microsoft HoloLens has a way to capture the point of view of the user. This feature, entitled Mixed Reality capture, enables HoloLens users to record videos or transmit a live video feed of their session. From a training point of view, the mixed reality capture enables a single teacher to explore holographic content while sharing the experience with the rest of the class. In the future, we will be able to transmit this mixed reality capture view in the classroom or over the Internet.

Enabling Students to Learn Through Building

I believe that students learn best when they can build stuff. As I have had the opportunity to build applications for the HoloLens, I built a ‘proof of concept’ application showing how students might build in a Minecraft environment using HoloLens.   This video was recorded using the HoloLens mixed reality capture.

The HoloLens already comes with Holo Studio which enables users to build playful 3D structures. While this scenario is exciting for students, the price of Windows Holographic devices will need to decline in order for this use case to become common. We are looking forward to Lenovo and Acer to ship Windows Holographic platforms at a price point closer to $300 to $400 later this year.

Visualization of Complex Structures and Processes

In the short term, I can imagine professors, teachers, and trainers using the HoloLens as a platform for student engagement.   Instead of showing students slides of complex structures or processes during a lecture, the holographic applications of the future will bring this content to life.   My wife teaches microbiology and biology at a local college.   She has become very curious about ways to use HoloLens to teach internal cell processes and biology structures.   You can check out an early cell exploration app here.   I have included a few tweets below to share other visions or use cases in medical education / digital health.  In the medical market, there’s great interest in using Microsoft HoloLens to practice or simulate medical procedures.

Providing Training and Education at a Distance

Given that the Microsoft HoloLens enables teachers to share their perspective in videos or video streaming, I predict there will be a new ecosystem of holographic apps for remote learning and teaching.   Suppose that a remotely located student needs support from a trainer, the student can initiate some form of video chat application to connect to the trainer.    For example, a biology professor needs to remotely support lab techs back at the campus research lab.   In this case, the research tech needs help to complete a procedure in the lab.    In the ideal case, the remote trainer should have the ability to place helpful annotations to focus attention and place 3D content/pictures to coach the student.    In this scenario, the HoloLens can transmit the view and perspective of student to the trainer.  The trainer can provide mentorship or coaching using a remote view.   In a similar fashion, teachers may use the Microsoft HoloLens in recording lectures for their classroom or transmit live video over the internet.

We enjoy hearing from our readers.   If you got an idea for a Windows HoloLens application, leave a comment below.   The possibility for Windows Holographic computing is out of this world.