parseInput - % piano key. So. .. vec = ; %initializes the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function vec = parseInput(ca) %Write a function, parseInput, that takes in a cell array of strings, %each representing a note on the piano. The function should return a %vector of half steps, up (+) or down (-), from middle C (C4). %Notes will be in one of two formats: either of length 2, with the note %name and octave (F3) or of length 3 with note name, sharp/flat, and %octave (G#4). Note names go in the following order: C,D,E,F,G,A,B. %When going from B to C, the octave number is incremented (so B3 and C4 %are 1 half step away, where E3 and F4 are an octave and a half step %away). %For the less musically inclined, here's a quick rundown of how you %should approach each piece of data. Refer to Piano Notes.jpg as you %read this: % - In this example we will compute how far away G#3 is from C4. % - First add the number of half-steps that seperate your note from % C- don't worry about octaves or sharps/flats. A half-step is one
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % piano key. So. .. vec = ; %initializes the output for ndx = 1:length(ca) if length(ca{ndx})==2 %determines if the chord is whole switch ca{ndx}(1) case 'C' step = 0; case 'D' step = 2; case 'E' step = 4; case 'F' step = 5; case 'G' step = 7; case 'A' step = 9; case 'B' step = 11; end %depending on the chord, the steps are calculated to get from C4 to %that particular letter octnum = str2double(ca{ndx}(2)); octave = 12.*(octnum-4); vec = [vec octave+step]; elseif length(ca{ndx})==3 switch ca{ndx}(1) case 'C' step = 0; case 'D' step = 2; case 'E' step = 4; case 'F' step = 5; case 'G' step = 7; case 'A' step = 9; case 'B' step = 11; end if strcmp(ca{ndx}(2),'#') num = 1; elseif strcmp(ca{ndx}(2),'b') num = -1; end octnum = str2double(ca{ndx}(3)); octave = 12.*(octnum-4); vec = [vec octave+step+num]; end end end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Page1 / 2

parseInput - % piano key. So. .. vec = ; %initializes the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online