""" Authors: Consulted: Purpose: CS111 Lab For loops and wavesynth music Date: Fall 2023 Filename: notes.py """ from wavesynth import * import random def randomPitch(): '''Returns random pitch''' return random.choice([P3, P4, P5, P6, P7, P8, P9, P10]) def randomDuration(shortest, longest): """Returns a random duration between shortest a longest.""" return shortest + (longest - shortest) * random.random() def clear(): """ Clears the track so you can start over. """ resetTracks() # Write your functions below this line: # ------------------------------------- def randomNotes(number, minDuration, maxDuration): ''' Randomly sequences notes and rests into a "tune." ''' for i in range(number): # generate note and rest durations: noteDur = randomDuration(minDuration, maxDuration) restDur = randomDuration(minDuration, maxDuration) # Pick random pitch setPitch(randomPitch()) # Add note addNote(noteDur) # Add rest addRest(restDur) def makeScale(number, duration): "Adds notes at increasing pitches. Returns to starting pitch at end." for i in range(number): addNote(duration) climbUp(1) climbDown(number) def makeGapScale(number, duration, gap): """ Adds notes at increasing pitches, with gaps in between. Returns to the starting pitch at end. """ for i in range(number): addNote(duration) climbUp(1 + gap) climbDown(number) # Testing code: clear() # randomNotes(5, 0.1, 0.6) #makeScale(8, 0.2) makeGapScale(8, 0.3, 1) saveTrack('scale.wav') playTrack()