Transcription

2 Controls In our last chapter, we began to create something more musical by playing every note in a scale, although out of order. Sometimes, we might just want to skip a note. We need a way to make decisions. One such way is with if. if has it's own helpfile. Highlight lowercase if and press apple-shift-?. If is also explained briefly in the helpfile for Boolean. A Boolean is a value that is either true or false. true and false are reserved words in SuperCollider. We can send an if message to Booleans. [true, false].choose.if { } ; If you run the above code several times, true and false shout print out about the same number of times in a random order, because [true, false].choose ought to be true half the time and false the other half. The result of that expression is a Boolean. We send an if message to the Boolean, which has two arguments, both functions. The first function is evaluated if the Boolean is true. The second function is evaluated if the Boolean is false. boolean.iftruefunction, falsefunction;

3 You can omit the false function if you want. This syntax that we've been using, object.messageargument1, argument2,... argumentn;, is the most commonly used syntax in SuperCollider programs. It's called receiver notation. However, there is more than one correct syntax in SuperCollider. There also exists a syntax called functional notation. It is more commonly used with if messages than receiver notation. When you see if in the helpfiles, the examples almost always use functional notation. Functional notation is: messageobject, argument1, argument2,... argumentn; The two notations are equivalent. You can replace one with the other at any place in any program and it will not change the program. What this means for if, is that you very commonly see: ifboolean, truefunc, falsefunc; So our example would change to: if[true, false].choose, { It works in exactly the same way.

4 Why are there multiple correct notations? It's confusing! SuperCollider is based on many other programming languages, but the language that it borrows most heavily on is one called Smalltalk. Smalltalk, like SuperCollider, is an object-oriented language. When I took Programming Languages, my teacher said that Smalltalk was the best object oriented language and the only reason it wasn't the most popular was that the syntax was insane. James McCartney, the author of SuperCollider perhaps was trying to spare us from the horrors of Smalltalk syntax and let us use receiver notation, which is common across many object-oriented languages. Functional notation, however, persists in if, probably because other languages have different ways of thinking about if. Let's go back to our musical program and give it a 50% chance of playing a note and a 50% chance of resting: var func, arr; func = { arg ratio_arr, basefreq = 440, detune = 10; var pitch; Routine.new{ ratio_arr.scramble.do{ arg ratio, index; if [true, false].choose, { pitch = ratio * basefreq + detune; Synth.new"example3", [\freq, pitch, \dur, 1];

5 1.wait; }; arr = [ 1/1, 3/2, 4/3, 9/8, 16/9, 5/4, 8/5]; func.valuearr, 440, 10.play; If we want to give it a 33.3% chance of resting a 66% chance of playing, we could change out if to look like if [true, true, false].choose, { and expand our array every time we want to change the probability. But what if we want something to play 99% of the time? We would have to have 99 trues and one false. Fortunately, there is a message you can use that returns a Boolean based on percentage. To play 66% of the time, we would change our if to if 0.66.coin, { var func, arr; func = { arg ratio_arr, basefreq = 440, detune = 10; var pitch; Routine.new{ ratio_arr.scramble.do{ arg ratio, index; if 2/3.coin, { pitch = ratio * basefreq + detune; Synth.new"example3", [\freq, pitch, \dur, 1];

6 1.wait; }; arr = [ 1/1, 3/2, 4/3, 9/8, 16/9, 5/4, 8/5]; func.valuearr, 440, 10.play; coin is a message you can pass to SimpleNumber. It returns a true or false value. The number that receives the message is the percent likelihood that it will return true. Boolean Expressions Many arithmetic operations return Booleans. equivalency with == For example, we can test for a = 3; if a == 3, { Note that is two equal signs next to each other when we're testing for equivalency. If you just use one equal sign, it means assignment. I often accidentally type one equals sign when I mean to type two.

7 We can test for greater than or less than: a = 3; if a > 4, { a = 3; if a < 4, { We can do Boolean operations. Some of the most important ones are not, and, and or. The easiest way to illustrate these is with truth tables. A truth table shows you all possible combinations of true and false variables and what the results would be. Any Boolean variable can be either true or false. This is a truth table for not: Not:

8 true false false true Not is a unary operator. That means it only involves one object. The top of the table shows a true input and a false input. The bottom of the table shows the result. true.not returns false and false.not returns true. And is a binary operator. Like +, -, *, / and %, it operates on two objects. Lets say we have two variables, a and b, and either of them can be true or false. We can put a along the top of the table and b down the left side. In the middle we put the possible results of a and b. true false true true false false false false Or is also binary: true false true true true false true false So how do we code these? Let s look again at not. Not is represented as! a = 2;

9 if!a == 4, { Not just negates. It turns a false into a true and a true into a false. It can also be combined with equivalency to test for not equals. a = 2; if a!= 4, { The last two examples are the same. And is represented by &&: a = 3; b = 4; if a > 2 && b < 5, {

10 Both a > 2 and b < 5 must be true for this expression to evaluate as true. If one of them is false, the whole thing is false. Or is represented by Those are vertical lines. On your Macintosh with an American keyboard, they're over the slash \: a = 3; b = 4; if a > 2 b < 5, { a = 3; b = 4; if a < 2 b < 5, {

11 a = 3; b = 4; if a > 2 b == 5, { For these expressions to evaluate to true, only one part of it needs to be true. If neither part of an or is true, then the whole thing is false. While We ve used Boolean expressions to control the flow of execution of a program with if. Another control structure is while. While is a message passed to a function. The function must return either true or false. It is a test function. There is another function passed in as an argument. test_function.whileloop_function; If the test function is true, the loop function gets run. Then the test function is run again. If it returns true again, the loop function is run again. This continues until the test function returns false. While the condition is true, the loop is executed. var add_amt, max_add, total; max_add = 0.5; total = 0;

12 {total < 1}.while{ add_amt = max_add.rand; //... total = total + add_amt; "in while loop".postln; While is a message sent to a function. Remember that receiver notation and functional notation are equivalent. The following two lines are the same: test_func.whilebody_func; whiletest_func, body_func; There are other Control Structures detailed in a help file called Control- Structures. Highlight "Control-Structures" and press shift-apple-? Problems 1. Re-write hello world from the first chapter using functional notation. 2. Write if statements using and or and not using Boolean values of true and false to illustrate the truth tables, using all possible combinations of true and false. For example: if! true, {

13 What do you expect each of them to print? Did the results you got from running them match your expectations? 3. Write a function with returns a Routine. The function should take three arguments: an array of pitches to chose from, and array of durations to chose from and a total duration for the Routine. Play pitches in rhythm for the duration and then stop. You may wish use arrays of arrays to create rhythmic motifs or repeating pitch themes. Project Some songs, like Bingo or some German drinking songs, leave out particular pitches on repetitions. Write a one or two minute piece that repeats a short phrase but leaves notes out on the repeats.

Sample Entrance Test for CR125-129 (BA in Popular Music) A very exciting future awaits everybody who is or will be part of the Cork School of Music BA in Popular Music CR125 CR126 CR127 CR128 CR129 Electric

How to Read Music Notation The New School of American Music IN JUST 30 MINUTES! C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E 1. MELODIES The first thing to learn about reading

Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

Programming LEGO NXT Robots using NXC This text programming language derived from C language is bended together with IDE BricxCC on standard firmware LEGO Mindstorms. This can be very convenient for those,

The Smalltalk Programming Language Beatrice Åkerblom beatrice@dsv.su.se 'The best way to predict the future is to invent it' - Alan Kay. History of Smalltalk Influenced by Lisp and Simula Object-oriented

Boolean Logic in MATLAB When programming, there will be times when you want to control the flow of your code based on certain events occurring or certain values being reached. Primarily, this is handled

VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...

ADMINISTRATIVE MENU HOME LOG IN Course Syllabus for MUSI 1306 Section 047 Music Appreciation 2010 Fall Standard Semester Note to Students: Syllabi are the most recent available at the time they were posted

Python for Rookies Example Examination Paper Instructions to Students: Time Allowed: 2 hours. This is Open Book Examination. All questions carry 25 marks. There are 5 questions in this exam. You should

LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

GCSE Music Unit 4 (42704) Guidance (There are recordings to accompany this document.) The Task Students will be required to compose one piece of music which explores two or more of the five areas of study.

Subnetting Basics You learned previously how to define and find the valid host ranges used in a Class A, Class B, and Class C network address by turning the host bits all off and then all on. This is very

GCSE Music Unit 3 (42703) Guidance Performance This unit accounts for 40% of the final assessment for GCSE. Each student is required to perform two separate pieces of music, one demonstrating solo/it skills,

Chapter 9 Xylophone It s hard to believe that using technology to record and play back music only dates back to 1878, when Edison patented the phonograph. We ve come so far since then with music synthesizers,

CS 40 Computing for the Web Art Lee January 20, 2015 Announcements Course web on Sakai Homework assignments submit them on Sakai Email me the survey: See the Announcements page on the course web for instructions

Antonín Dvořák Life Dates: 1841-1904 Nationality: Czech Period: Late Romantic I should be glad if something occurred to me as a main idea that occurs to Dvořák only by the way. Johannes Brahms (1833-97)

Section Arithmetic in Other Bases Arithmetic in Other Bases The operations of addition, subtraction, multiplication and division are defined for counting numbers independent of the system of numeration

6 Creating the Animation Now that the animation can be represented, stored, and played back, all that is left to do is understand how it is created. This is where we will use genetic algorithms, and this

Chapter 5: Sequential Circuits (LATCHES) Latches We focuses on sequential circuits, where we add memory to the hardware that we ve already seen Our schedule will be very similar to before: We first show

A Conversation with Edwin Gordon by Mary Ellen Pinzino (Musicstaff.com 1998) Edwin Gordon is one of the great masters in the field of music education. His lifetime of research has led to an extensive investigation

CHAPTER 2 Logic 1. Logic Definitions 1.1. Propositions. Definition 1.1.1. A proposition is a declarative sentence that is either true (denoted either T or 1) or false (denoted either F or 0). Notation:

ROI 1 Return on Investment (ROI) Prepared by Sarah Major What is ROI? Return on investment (ROI) is a measure that investigates the amount of additional profits produced due to a certain investment. Businesses

Free Cash Flow Overview When you re valuing a company with a DCF analysis, you need to calculate their Free Cash Flow (FCF) to figure out what they re worth. While Free Cash Flow is simple in theory, in

Singing Folk Songs in the Classroom For the Musically Challenged By Lynn Arthur Koch Originally published as Choosing and Using Folk Songs with Children: Keeping the Children in Mind in Folk Song in the

WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

Chapter 5 Instance Creation We've now covered enough material to look more closely at creating instances of a class. The basic instance creation message is new, which returns a new instance of the class.

Music Programme of study for key stage 3 and attainment target (This is an extract from The National Curriculum 2007) www.qca.org.uk/curriculum Crown copyright 2007 Qualifications and Curriculum Authority

By Judy Hunter Grinnell College A citation is both a signpost and an acknowledgement. As a signpost, it signals the location of your source. As an acknowledgement, it reveals that you are indebted to that

Main Effects & Interactions page 1 Main Effects and Interactions So far, we ve talked about studies in which there is just one independent variable, such as violence of television program. You might randomly

UML 2.0 in a Nutshell Appendix B. The Object Constraint Pub Date: June 2005 Language The Object Constraint Language 2.0 (OCL) is an addition to the UML 2.0 specification that provides you with a way to

Calculating Abandoned Calls in the light of the Ofcom 2008 Statement Summary This document has been produced for operators of Predictive Dialling equipment to clarify the calculations required when determining

- FAVORITE SONGS AND MUSIC ACTIVITIES FOR ELEMENTARY TEACHERS AND THEIR STUDENTS Sponsored by the FINE ARTS division of the Utah State Office of Education Featuring practical music lessons coffelated to

The Written Notation of Medieval Music Nigel Horne Introduction When visiting a collection of old music such as those held at the British Museum in London, I am often struck by the beauty and painstaking

Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

Chapter 11. Talk To Your Computer One of the more interesting things about the Logo language is list processing. Early computer languages were known as "number crunchers." Everything was represented by

Parameters for Session Skills Improvising Initial for all instruments If you choose Improvising, you will be asked to improvise in a specified style over a backing track that you have not seen or heard

A Comprehensive Guide to Attracting Prospects with Video Why would you want to use video to attract prospects? It's easier (and cheaper) to write a blog or post on Facebook. But it's a proven fact that

St. Michael-Albertville Middle School East Teacher: Tina Lajko Choir 6 September 2014 A: Rehearsal Skills A: Rehearsal Skills CEQ: WHAT ARE THE ESSENTIAL COMPONENTS OF CHORAL MUSIC THAT SHOULD CONSISTENTLY

University application essays (or personal statements ) What to say, and what not to say! Essays are an important part of your application The less important your GPA and test scores, the more important

1 Music Theory for Cajun Accordionists Right off the bat, I need to make clear that I m no expert; far from it. I ve had to piece together what little I know about music theory from here and there, mostly

The Soul of Korean Arirang Music from Korea in the Middle School Band Designed by: Vince Fejeran Summary: This lesson is designed to enhance the music of John Ployhar s well-known Korean Folksong Medley

Introduction to the BackgroundWorker Component in WPF An overview of the BackgroundWorker component by JeremyBytes.com The Problem We ve all experienced it: the application UI that hangs. You get the dreaded

National Standards for Music Education 1. Singing, alone and with others, a varied repertoire of music. 2. Performing on instruments, alone and with others, a varied repertoire of music. 3. Improvising

This lesson assumes that you are using a ukulele tuned to the notes G, C, E and A. Ukulele Notes In lesson 1, we introduced the sequence of 12 notes, which repeats up and down the full range of musical

Algorithm & Flowchart & Pseudo code Staff Incharge: S.Sasirekha Computer Programming and Languages Computers work on a set of instructions called computer program, which clearly specify the ways to carry

Basic instructions In each domain there are a fixed number of basic instructions you may use to write a program. You're only allowed to use this instructions directly when writing the script. For our robot

In this chapter Find out why it s important to put finishing touches on a slide show Learn how to use the slide sorter Explore the use of slide transitions Learn how to change slide color schemes and backgrounds

Writing a Press Release A press release is a written statement to the media. It can announce a range of news items, including scheduled events, personal promotions, awards, new products and services, sales

University of Tennessee, Knoxville Trace: Tennessee Research and Creative Exchange University of Tennessee Honors Thesis Projects University of Tennessee Honors Program 4-2002 A Comparison of Programming

UNDERGRADUATE MUSIC THEORY PLACEMENT TEST INFORMATION The theory placement test is designed to determine whether you are ready to enroll in MUS 121 (Music Theory I) or whether you must first take MUS 120

STATS 1000 / STATS 1004 / STATS 1504 Statistical Practice 1 Practical Week 5 2015 Practical Outline In this practical, we will look at how to do binomial calculations in Excel. look at how to do normal

What Do You Know About Performance Appraisals? Performance appraisals need to be formal and highly-scripted affairs Employees need to be very involved in their performance appraisals Supervisors should

Guidance from HMI for teachers, headteachers, and music hub leaders when observing musical teaching and learning Schools, all other funded providers of music education, and providers of Continuing Professional

AP MUSIC THEORY SUMMER ASSIGNMENT AP Music Theory Students and Parents, You are receiving this letter because you or your son/daughter is enrolled in AP Music Theory for this next school year. Please take

FREE Article! FEATURE Swift for PHP Developers Ricky Robinett If you haven t heard, Swift is Apple s new programming language that developers can use to build native ios and OSX apps. When Apple announced

Making Connections with Music and Technology By James Frankel, Ed.D. Over the past twenty years many research studies have shown that there is a strong connection between music, the brain, and other subject

Hello, and welcome to Lesson 21. In Lesson 19 you learned Drink To Me Only With Thine Eyes, using just four chords. In this lesson we ll be using substitution chords to create a more professional sounding

Lesson 2 Alcohol: What s the Truth? Overview This informational lesson helps students see how much they know about alcohol and teaches key facts about this drug. Students complete a True/False quiz about