Laptop Instrument Meeting 14 March 12, 2018.

Slides:



Advertisements
Similar presentations
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Advertisements

Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
Games and Simulations O-O Programming in Java The Walker School
Let’s Look At: Notes & Rests Notes & Rests (When the arrow turns red, click for the next page)
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1!  And before that…  Review!  And before that…  Arrays and strings.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
CS305j Introduction to Computing Parameters and Methods 1 Topic 8 Parameters and Methods "We're flooding people with information. We need to feed it through.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
From TOPIC to MAIN IDEA A process exercise. Go to the number that matches your number! 1. Read the article. Write the TOPIC! 2. Read the article. Fix.
Arrays Chapter 7.
Modular Decomposition, Abstraction and Specifications
Chapter VII: Arrays.
Arrays Chapter 7.
Building Java Programs
Formatting Output.
Computer Programming BCT 1113
C programming---Arrays
Containers and Lists CIS 40 – Introduction to Programming in Python
Week 7 - Wednesday CS 121.
Quiz 11/15/16 – C functions, arrays and strings
Write code to prompt for 5 grades, read them in, print “Thank you”, then reprint the 5 grades and their average. cout >
Practical example of C programming
JavaScript Functions.
Chapter-7 part3 Arrays Two-Dimensional Arrays The ArrayList Class.
Java Arrays. Array Object An array :a container object holds a fixed number of values of a single type. The length of an array is established when the.
Lecture 6 C++ Programming
CSC 253 Lecture 8.
Programming for Art: Algorithms
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Arrays & Functions Lesson xx
Starting Out with Java: From Control Structures through Objects
The relational operators
Visual Basic .NET BASICS
CSC 253 Lecture 8.
Music Notes and their Values.
© Akhilesh Bajaj, All rights reserved.
Laptop Instrument Meeting 22 April 11, 2018.
Arrays And Functions.
CSE 143 Lecture 1 Review: Arrays and objects
Lesson 16: Functions with Return Values
Chapter 8 Slides from GaddisText
Laptop Instrument Meeting 4 January 29, 2018.
Object Oriented Programming
Laptop Instrument Meeting 7 February 7, 2018.
Functions Chapter 9 Copyright © 2008 W. W. Norton & Company.
Object Oriented Programming in java
C-to-LC3 Compiler Over the course of the next two weeks, you will build a program that will compile C code to LC-3 assembly language Don't panic! You.
CS2011 Introduction to Programming I Arrays (I)
MSIS 655 Advanced Business Applications Programming
Arrays Chapter 7.
Arrays and Array Lists CS 21a.
Arrays ICS2O.
Laptop Instrument Programming a Tune.
Building Java Programs
EECE.2160 ECE Application Programming
Processing Sound Ranges
Suggested self-checks: Section 7.11 #1-11
Java SE 7 One and Multi Dimensional Arrays Module 6
Chapter 9: Pointers and String
Why are arrays useful? We can use arrays to store a large amount of data without declaring many variables. Example: Read in a file of 1000 numbers, then.
Methods/Functions.
CSCE 206 Lab Structured Programming in C
Presentation transcript:

Laptop Instrument Meeting 14 March 12, 2018

Plan for the Day Mid-term exam comments next time Spring break and snow have interfered Expanding note specification Capturing input Simultaneous playing

Rests We’ve set up a tune as an array of arbitrary length whose elements are arrays of integers of length 2 whose first element is the MIDI number of the note and whose second element is the index of the duration of the note in the duration array

Rests (2) Let’s extend the note pairs to allow 0 in the first slot (remember the first slot has index 0). We’ll fix the tune player to interpret this 0 as a rest. Example: If tune[23] = [ 0, 8 ], this means an eighth rest at position 23 (the 24th element) of the tune.

Tune Player Adjustments for (0 => int i; i < tune.cap(); i++) Note: tune.cap() gives the capacity of the tune array. If there are 140 notes and rests in the tune, the capacity is 140 and the elements are indexed from 0 through 139.

Adjustments (2) Check for a rest, { if (tune[i][0] > 0) { Std.mtof(Tune[i][0]) => Benny.freq; 1.0 => Benny.noteOn; } else { 1.0 => Benny.off } duration[tune[i][1]] => now; }

Adjustments (3) Separating notes: Include a really short pause between notes Can’t be added to the duration of a note. Why? How long is “really short”? How long is a 32nd note when the tempo is 144?

Adjustments (4) duration[tune[i][1]] - ns => now; Solution: Define a note separation duration 5::ms => dur ns; and subtract this value from the playing time of a note duration[tune[i][1]] - ns => now; Then add two statements to play the silence 1.0 => Benny.noteOff; ns => now;

Test Program Write a program to play a C major scale, one octave, four quarter notes on each pitch, both ascending and descending. Write a program to play an F major scale, one octave, quarter note, quarter rest, quarter note, quarter rest on each pitch, both ascending and descending.

Capturing Input Explored functions already fun int plus3 (int x) { return x+3 }; <<< plus3(84) >>>; 84 is captured as the value of the parameter x in the function plus3

Capturing Input (2) Example: Setting the tempo outside the program, so that the tune player will play at the specified tempo without having to change the program each time. chuck playtune:128

Capturing Input (3) We’re passing the value 128 to the program playtune, intending to use it as the tempo. Where does the 128 appear in the program? In the secret variable me.arg(0) BUT it is NOT an integer, it’s a string.

Capturing Input (4) // Shows getting command line arguments // chuck args:1:2:foo

Capturing Input (4) // Shows getting command line arguments // chuck args:1:2:foo // print number of args <<< "number of arguments:", me.args() >>>;

Capturing Input (4) // Shows getting command line arguments // chuck args:1:2:foo // print number of args <<< "number of arguments:", me.args() >>>; // Declare an array to hold the argument values int a[5]; for(0=>int i;i<me.args();i++) {<<<me.arg(i)>>>; Std.atoi(me.arg(i)) => a[i]; <<<a[i]>>>; }

Capturing Input (5) Adjust your scale player to accept the tempo as a command line argument.

Note Playing Ideas Original patch SinOsc => dac; oops SinOsc s => dac; Two notes simultaneously require two generators, so we add one SinOsc t => dac; problem 1 + 1 = 2

Note Playing (2) Effects to the rescue Gain first SinOsc s => Gain gn => dac;

Note Playing (2) Effects to the rescue Gain first SinOsc s => Gain gn => dac; Unit generator class

Note Playing (2) Effects to the rescue Gain first SinOsc s => Gain gn => dac; Unit generator class Effect class

Note Playing (2) Effects to the rescue Gain first SinOsc s => Gain gn => dac; Unit generator class Effect class Why gn?

Note Playing (2) Effects to the rescue Gain first SinOsc s => Gain gn => dac; Turn down the volume 0.5 => gn.gain; Unit generator class Effect class Why gn?

Note Playing (3) Second note SinOsc t => gn;

Note Playing (3) Second note SinOsc t => gn; Where’s Gain?

Note Playing (3) Second note SinOsc t => gn; Where’s dac?

Note Playing (3) Second note SinOsc t => gn; Adjust the volume individually 1.0 => gn.gain; 0.4 => s.gain; 0.6 => t.gain; Where’s dac?

Note Playing (4) Simultaneous parts chuck soprano.ck alto.ck synchronizes the players but make sure the volume adds to 1 or less

New Player (5) Your turn: Write two ChucK programs The first plays an ascending two-octave scale The second plays a descending two-octave scale Play the scales simultaneously Write a four-part tune, one part per ChucK program, and play the tune. Use Wait for the Lord Use a Taize piece for the two-part tune

New Player (6) Create a two-part round and have your tune player play it. You may want to modify your tune player into one that is a round player. Modify your tune player to handle a classic barber shop song, such as Lida Rose and Will I Ever Tell You, that matches the women’s parts against the men’s