CHRISTOPHER HODDINOTT.COM
Menu

Sonic Pi - Lesson 2

8/11/2015

0 Comments

 
Learning Objective 

  • Understand that computers don’t know what to do with an error.
  • Write a simple program using text and identify any errors.
  • Iterate/repeat some code a number of times to create a 'bass line'.

Lesson Brief
  • A short exercise to recap the notion of statements and control flow within a program.
  • A debugging exercise.
  • Starting the Sonic Pi application.
  • Iteration as a repeating structure.
  • Syntax punctuating structure.


  1. With just one group acting and with the rest of the class watching, introduce the two error cardsinto the deck of computer program cards; shuffle them up and repeat the exercise described in the previous lesson. Observe what the pupil with the foreign language error card does, and then have a short discussion with the class about what perhaps should happen. Then point out that there’s another error card, but with a subtle error in the spelling. Explain that to the computer they are both as unintelligible as each other. The computer isn’t clever enough to read through the subtle error.

  2. The pupils are then separated into pairs and are given their own set of Sonic Pi equipment. Pupils follow the instructions to connect the various parts of the Raspberry Pi together and once it has booted, they start the Sonic Pi program by clicking on the menu item under start -> programming -> sonic-pi.

  3. Next, the pupils are given their first introduction to debugging. They are asked to type in the following one-line program which is incorrect: pllay 42. They are then asked to observe what happens when they run the program. At this point it’s important to emphasise that this is a typical situation for real programmers. It means that they have done something that the computer doesn’t understand; because the computer is not very clever, this is very easy to do. The students are invited to correct (debug) the program by removing the extra l. They are then asked to observe the output of the program.

  4. A selection of pupils are asked to form a line with the computational cards, and to act out the program as carried out in the previous lesson. The class is then asked how we can repeat this program twice. One of the answers might be to duplicate the line, forming a line twice as long as the original with the original sequence of statements duplicated twice. Now, ask the class to act out this new longer program. Once this has been completed ask how we might repeat the original program 10 times, or 100 times. What about 1000 times? Clearly, we’d run out of people!

  5. Introduce the iteration cards: 1.times, do and end. Wrap the original program in the do andend cards, and prefix everything with the 1.times card. Explain that this is just a long-winded way of doing the same thing as the original program. The new cards are extra syntax which should be thought of as the same as punctuation; capital letters, commas, full stops and so on. Like punctuation, this syntax helps the computer structure the program. However, with this extra syntax, we have actually formed a circle out of our code. The syntax defines the start and the end points of the loop: the do and end. In this case we only loop round the circle once, but if we replace the first card with 3.times we loop round our program 3 times. If you have enough space, try forming a circle and enact the loop. Explain that this loop structure is called iteration.Pupils are asked to enter the following ‘bass line’ code into the Sonic Pi application:
  • To Compose your BassLine
  1. Try this command to start you off. 
  2. play 42 sleep 0.5 play 45 sleep 0.85 play 54 sleep 1 play 54 sleep 0.7 play 45 sleep 0.2 play 49 sleep 1
  3. They are then asked to repeat this line 5 times. They do this by writing:

    5.times do play 42 sleep 0.5 ... rest of code ... sleep 1 end

  4. You can choose to play around with this, modifying it as they feel fit, for the remainder of the time. For the adventurous pupils, you can suggest that they nest the iterations; in other words, have one iteration inside another.

Use this link to help you. 
https://www.raspberrypi.org/learning/sonic-pi-2-taster/worksheet.md

Homework;

Write out your own Bass Line and submit it on the form below.

  • Create your own bass melody 
  • Change the synth 
  • Needs to repeat or loop

Submit your code here

http://goo.gl/forms/Bsta7cUN82

https://www.raspberrypi.org/learning/getting-started-with-sonic-pi/worksheet/


Any issues email MR Hoddinott


0 Comments

Sonic Pi - Lesson 4

8/10/2015

0 Comments

 
Lesson Objectives 

  • Know that numbers can be aggregated into data structures such as lists.
  • Understand that algorithms are a series of steps or instructions for solving a problem such as sorting and shuffling a list of numbers.
  • Be able to use data structures and built-in algorithms as part of Sonic Pi composition, using comments to explain what is happening.


Lesson Summary 
  • Numbers as a kind of data.
  • Introduction to lists.
  • Playing a list of numbers.
  • Introduction to sorting.
  • Sorting and shuffling a list of numbers.


  1. Pupils should be asked what kind of information they have been using in the previous lessons; in other words, the things they’ve been able to change. They have been able to change the time to sleep and the note to play. Ask them what kind of information this is, the answer being that they are all numbers. Explain that a number is a kind of data, and there are many others that computers may understand.

  2. Explain to the pupils that although numbers are one of the most useful forms of data, it’s also very handy to represent a list of numbers. Ask them if they can think of any things that could be represented by a list of numbers; for example, the finish times of runners in a race, the numbers drawn in the lottery and the notes of a bass line.

  3. Invite the pupils to enter the following code into a new worksheet and press play:

    play_pattern [40, 25, 45, 25, 25, 50, 50]

  4. Explain that play_pattern is similar to play except instead of taking a number representing the note to play, it takes a list of numbers to play one after the other. This list of numbers has special syntax to tell the computer that it’s a list. Firstly, it has to start with a [ and end with a ]. Secondly, each number in the list has to be separated from the other numbers with a comma.

  5. Invite the pupils to write their own lists, choosing different numbers and different lengths of numbers, for example:

    [43, 24, 60, 57, 30] [60] [48, 48, 48, 60]

  6. Once they’ve had a short play with this, invite them to form a line and hand out the number cards (in no particular order), so each pupil in the line holds just one card. Explain that they have formed a list of numbers and that there are useful things that you can do with this. One example is sorting the numbers numerically, so that the smallest numbers are first and the largest last. Introduce the word 'algorithm' as a method for solving such problems.

  7. Next, explain that we will explore a simple sorting algorithm: bubble sort. Start at the left hand side of the line and ask the first two pupils to compare their numbers. If they are in the right order do nothing, otherwise ask the pupils to swap. Then continue to the second and third pupils, and compare and swap again if necessary. Continue down the line. If at least one pair has swapped, start at the beginning of the line and repeat. If no pairs have swapped, the list is sorted.

  8. Explain that most programming languages provide many such algorithms to make programming easier, and to reduce the amount of work you have to do as a programmer. Ask the pupils to type the following code:

    play_pattern [40, 25, 45, 25, 25, 50, 50].sort play_pattern [40, 25, 45, 25, 25, 50, 50].shuffle

  9. Pupils are invited to play around with the constructs of this lesson, in addition to everything they’ve learned so far, to design a simple musical program.


Homework 

Create a sorting algorithm in Scratch to explain how one would shuffle the notes in a list.



For this task you have include 
  • Sample
  • FX
  • Change in Synth
  • and a shuffle pattern

ML
0 Comments

Sonic Pi - Lesson 5

8/10/2015

0 Comments

 
Lesson Objectives
  • Know that computers can multitask (do many things at once).
  • Understand that a simple program has one flow of control; in other words, it has one thread of execution. Programs can, however, have multiple such threads.
  • Be able to program multiple threads that work at the same time (concurrently).


Lesson Overview

  1. Try out the following code:
  2. in_thread do 10.times do play 60 sleep 0.25 end end play 60 sleep 0.5 play 62 sleep 0.5 play 64 sleep 0.5 play 65 sleep 0.5 play 67 sleep 0.5 play 69 sleep 0.25 play 72
  3. The code within the in_thread block gets its own control flow, and therefore runs at the same time as the play &sleep code below.



Picture
Picture
This video link is also a great tutorial on Sonic Pi

https://youtu.be/ixn6d4qSK5I?t=6m55s


Task and finish for homework.

Create a short passage with a drum loop, a bass line and a melody.

Upload to Managebac by wav or Mp3
0 Comments

Sonic Pi - Lesson 3

8/9/2015

0 Comments

 
Lesson Objectives 
  • Be able to add effects to your track.
  • Modify Effects and set parameters that the computer can work between


Modern synthesizers have the ability to add effects to sounds. Sonic Pi is no different: you are able to add studio effects such as reverb, echo and distortion. Of course you have to use code to add the effects!

  1. In a new worksheet find a sample that you like, for example sample :guit_e_fifths

  2. Wrap the sample in an effects block like this:

    with_fx :reverb do sample :guit_e_fifths end

  3. You can add effects on top of effects like this:

    with_fx :reverb do with_fx :distortion do sample :guit_e_fifths end end

  4. Play around with some effects and add them to your music. Remember that a complete list of effects can be found in the help section of Sonic Pi under FX.



MODIFYING PARAMETERS

On occasion, you might like to make sounds play for a longer time or at a different rate. This can be achieved easily by modifying the parameters of the code you are using.

Take play 60, for example.

  1. Click on help to open the help documents, then select lang on the left hand side, and scroll down toplay. You will see some examples of its use. So far you have used play without any parameters; let's use some now.
  2. In a new worksheet type:

    play 60, attack: 1, release: 3

  3. Press the play button to hear how that one note sounds. Attack and release control the amplitude of a note over time.

  4. Now change the values for attack and release to see how those parameters affect the note.
There are lots of parameters that can also change the way samples or synths sound. Try changing the values for cutoff:, pan:, rate: or amp:.

For a full list of parameters for each sample, click on the Help icon, followed by Samples. Select a sample and scroll down to see a full explanation for each type of parameter that can be used with that sample. The same applies for synths!

USING RRAND

Sonic Pi includes a number of functions that can add more interesting elements to your music. A really fun function is rrand, which will return a value between two specified numbers. For a cool effect, use rrand to make the cutoff bounce around.

  1. In a blank worksheet type:

    loop do play chord(:a3, :minor).choose, attack: 0, release: 0.3, cutoff: 80 sleep 0.2 end

  2. Instead of passing a number like 80 to the cutoff value, try rrand(40, 120) like this:

    loop do play chord(:a3, :minor).choose, attack: 0, release: 0.3, cutoff: rrand(40, 120) sleep 0.2 end

  3. Then you can start to experiment using rrand with other parameters. For example, add pan: rrand(-1, 1) to the play chord line and then press play.

Homework 

Electronic Music Analysis

Find an electronic music track of your choosing.

You can find some Electronic music here. http://www.last.fm/tag/electronic

Answer the Questions here

http://goo.gl/forms/ULIOwzgtXS


0 Comments

Sonic Pi - Project 

8/8/2015

0 Comments

 
In the next 3 weeks you will take the skills you have learnt to create a piece of music using Sonic Pi you can work in pairs for this project. 

You will perhaps need to download an additional program

http://audacityteam.org/download/

This program is a sound editor. It will allow you to record sounds and visualise the waveform and cut and splice the sound together. 

You can use Garageband, or Logic or any other DAW if you have access to the program. Otherwise Sonic Pi and Audacity are adequate for this project. 

You must meet the following criteria. 

  • It must be at least 2:30s in length. 
  • It must have a change or modulation in the music. 
  • You must use Sonic Pi at some point in the music.


Deadline: Wednesday 7th October 
0 Comments

Sonic Pi - Lesson 1

8/7/2015

0 Comments

 
Picture
Lesson Objectives
  • Know that there are many different types of computing devices.
  • Understand how a computer uses a sequence of statements to do something, and that this sequence is called a program.
  • Be able to give the Raspberry Pi some instructions to make some music

Below is an example of what the program looks like. 

  1. Split the class into groups again and give each group a deck of the computer program cards. Ask each group to take out the statement cards and the control card from the deck. Then ask each group to form a line and to give each member of the group a statement card after shuffling them. The person at the start of the line should be given the control card. Explain that the person holding the control card should carry out the instructions on the statement card, and then pass the control card to the next person in the line like a relay baton. When the control card has reached the end of the line, they should stop. This should be repeated for a number of random orderings, after which the groups could be invited to create their own orderings. A helpful analogy might be cooking, where collections of statements are recipes and the control flow is which stage of the recipe you're at.

  2. Start the Sonic Pi software. First, invite the students to log into their Raspberry Pi and start the graphical environment. It might help to display instructions on how to achieve this on a projector for all to see.

  3. Explain to them that they can use the same statements on the cards in the computer program:play and sleep. Invite them to spend the remaining time writing their own programs and listening to the results.

To Finish

Groups should be invited to choose card orderings for other groups to act out. Following this, a discussion should be held about how this relates to a computer. A computer works by executing statements one after another in a specific order. A given order of statements is called a program. Each program executes with a given control flow; this describes which statement we are executing and what the next statement will be.
0 Comments

    Archives

    September 2015
    August 2015
    July 2015

    Categories

    All
    Lesson 1
    Lesson 2
    Lesson 3
    Lesson 4
    Lesson 5
    Project
    Sonic Pi

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • Home Page
  • About Me
  • LinkedIn
  • Extended Essay
  • Social Media
    • Pinterest
    • Twitter Feed
    • Mr Hoddinott's Awesome Music Video of the week
  • Contact
  • MLI
  • Contact
  • Home Page
  • About Me
  • LinkedIn
  • Extended Essay
  • Social Media
    • Pinterest
    • Twitter Feed
    • Mr Hoddinott's Awesome Music Video of the week
  • Contact
  • MLI
  • Contact