API Documentation for functions in media.py _ setMediaPath|setMediaPath():
Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\"
Example:
def openBobsSong():
  setMediaPath()
  song = makeSound("BobsSong.wav")
  return song
This will let the user set a folder to look for files in, and then open the file "BobsSong.wav" in that folder. _ setMediaFolder|setMediaFolder():
Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\"
Example:
def openBobsSong():
  setMediaFolder()
  song = makeSound("BobsSong.wav")
  return song
This will let the user set a folder to look for files in, and then open the file "BobsSong.wav" in that folder. _ blockingPlay|blockingPlay(sound):
sound: the sound that you want to play.
Plays the sound provided as input, and makes sure that no other sound plays at the exact same time. (Try two playÕs right after each other.)
Example:
def playSoundTwice():
  sound = makeSound(r"C:\My Sounds\preamble.wav)
  blockingPlay(sound)
  blockingPlay(sound)
This will play the preamble.wav twice, back-to-back. _ getLength|getLength(sound):
sound: the sound you want to find the length of.
returns: the number of samples in sound.
Takes a sound as input and returns the number of samples in that sound.
Example:
def songLength():
  sound = makeSound(r"C:\My Sounds\2secondsong.wav")
  print getLength(sound)
This will print out the number of samples in the sound. For a 2 second song at 44kHz, it will print out 88000. _ getSample|getSample(A Sample):
argument1: A Sample, a sample of a sound.
returns: The integer value of that sample.
Takes a Sample object and returns its value (between -32000 and 32000)
Example:
def sampleToInt(sample):
  return getSample(sample)
This will convert a sample object into an integer. _ getSampleObjectAt|getSampleObjectAt(A Sound, An Integer):
argument1: A Sound, the sound you want to get the sample from.
argument2: An Integer, the index value of the sample you want to get.
returns: The sample object at that index.
Takes a sound and an index (an integer value), and returns the Sample object at that index.
Example:
def getTenthSample(sound):
  samp = getSampleObjectAt(sound, 10)
  return samp
This takes a sound, and returns the 10th sample in the sound. _ getSamples|getSamples(A Sound):
argument1: A Sound, the sound you want to extract the samples from
returns: A collection of all the samples in the sound
Takes a sound as input and returns the Samples in that sound.
Example:
def printFirstTen(sound):
  samps = getSamples(sound)
  for num in range(0, 10):
    print samps[num]
This will take in a sound and print the first 10 samples in that sound _ getSampleValueAt|getSampleValueAt(A Sound, An Integer):
argument1: A Sound, the sound you want to use the sample from.
argument2: An Integer, the index of the sample you want to get the value of.
Takes a sound and an index (an integer value), and returns the value of the sample (between -32000 and 32000) for that object.
Example:
def getTenthSampleValue(sound):
  num = getSampleValueAt(sound, 10)
  return num
This will take in a sound and return the integer value of the tenth sample _ getSamplingRate|getSamplingRate(A Sound):
argument1: A Sound, the sound you want to get the sampling rate from.
returns: An Integer representing the number of samples per second.
Takes a sound as input and returns the number representing the number of samples in each second for the sound.
Example:
def getDoubleSamplingRate(sound):
  rate = getSamplingRate(sound)
  return (rate * 2)
This will take in a sound an return the sampling rate multiplied by 2. _ getSound|getSound(A Sample):
argument1: A Sample, a sample belonging to a sound.
return: A Sound, the sound the sample belongs to.
Takes a Sample object and returns the Sound that it remembers as its own.
Example:
def getSamplesFromAnySample(sample):
  sound = getSound(sample)
  return getSamples(sound)
This will take in a sample and return a collection of samples from the original sound. _ makeSound|makeSound(A String):
argument1: A String, a path to a wav file.
returns: A Sound, created from the file at the given path.
Takes a filename as input, reads the file, and creates a sound from it. Returns the sound.
Example:
def openAnySound():
  file = pickAFile()
  return makeSound(file)
This opens up a file selector dialog. The user picks a file, and the function returns it as a sound. _ pickAFile|pickAFile():
returns: A String, the path to the file chosen in the dialog box.
Lets the user pick a file and returns the complete path name as a string. No input.
Example:
def openAnySound():
  file = pickAFile()
  return makeSound(file)
This opens up a file selector dialog. The user picks a file, and the function returns it as a sound. _ playNote|playNote(note, duration, intensity):
argument1: the note (a number > 0) you want to be played.
argument2: the duration you want the note to be played in milliseconds.
argument3: the intensity (a number between 0 and 127) you want the note to be played.
Plays a note. No return value.
Example:
        # this plays a scale
        intensity = 64
        dur = 1000
        playNote(60, dur, intensity)
        playNote(62, dur, intensity)
        playNote(64, dur, intensity)
        playNote(65, dur, intensity)
        playNote(67, dur, intensity)
        playNote(69, dur, intensity)
        playNote(71, dur, intensity)
        playNote(72, dur, intensity)
_ play|play(A Sound):
argument1: the sound you want to be played.
Plays a sound provided as input. No return value.
Example:
def playAnySound():
  file = pickAFile()
  sound = makeSound(file)
  play(sound)
This will open up a file selector box, make a sound from the chosen file, and then play that sound back. _ playAtRate|playAtRate(A Sound, A Number):
argument1: A Sound, the sound you want to be played.
argument2: A Number, the rate you want the sound to be played.
Takes a sound and a rate (1.0 means normal speed, 2.0 is twice as fast, and 0.5 is half as fast), and plays the sound at that rate. The duration is always the same, e.g., if you play it twice as fast, the sound plays twice to fill the given time.
Example:
def playHalfSpeed(sound):
  playAtRate(sound, 0.5)
This will take in a sound, and then play it at half speed. _ playAtRateDur|playAtRateDur(A Sound, A Number, An Integer):
argument1: A Sound, the sound you want to be played.
argument2: A Number, the rate at which you want the sound to be played.
argument3: A Number, the number of samples you want to be played.
Takes a sound and a rate (1.0 means normal speed, 2.0 is twice as fast, and 0.5 is half as fast), and plays the sound at that rate. The duration is the number of sample to play.
Example:
def playCompletelyAtHalfSpeed(sound):
  size = getLength(sound)
  playAtRateDur(sound, 0.5, size)
This takes in a sound and plays the entire sound a half speed. _ playInRange|playInRange(sound, start, stop):
sound: A Sound, the sound you want to play a piece of.
start: A Number, the index of the sound you want the playback to start.
stop: A Number, the index of the sound you want the playback to stop.
Take a sound, a start index, and a stop index and plays a selection of the sound defined by the start and stop indexes. Example:
def playFirstHalf(sound):
  stop = getLength(sound) / 2
  playInRange(sound, 1, stop)
This takes in a sound and plays the first half of it. _ blockingPlayInRange|blockingPlayInRange(sound, start, stop):
sound: A Sound, the sound you want to play a piece of.
start: A Number, the index of the sound you want the playback to start.
stop: A Number, the index of the sound you want the playback to stop.
Take a sound, a start index, and a stop index and blocking plays a selection of the sound defined by the start and stop indexes. Example:
def blockingPlayFirstHalf(sound):
  stop = getLength(sound) / 2
  blockingPlayInRange(sound, 1, stop)
This takes in a sound and blocking plays the first half of it. _ playAtRateInRange|playAtRateInRange(sound, rate, start, stop):
sound: A sound, the sound that you want to play.
rate: A Number, the rate at which you want the sound to be played.
start: A Number, the index of the sound you want the playback to start.
stop: A Number, the index of the sound you want the playback to stop.
Takes a sound, a rate (1.0 means normal speed, 2.0 is twice as fast, and 0.5 is half as fast), and a range (start and stop indexes) and plays the sound in that selection at that rate.
Example:
def playFirstHalfChipmunk(sound):
  stop = getLength(sound) / 2
  playAtRateInRange(sound, 1.4, 1, stop)
This takes in a sound and plays the first half of it back at 1.4 normal speed (Chipmunk speed). _ blockingPlayAtRateInRange|blockingPlayAtRateInRange(sound, rate, start, stop):
sound: A sound, the sound that you want to play.
rate: A Number, the rate at which you want the sound to be played.
start: A Number, the index of the sound you want the playback to start.
stop: A Number, the index of the sound you want the playback to stop.
Takes a sound, a rate (1.0 means normal speed, 2.0 is twice as fast, and 0.5 is half as fast), and a range (start and stop indexes) and plays the sound in that selection at that rate while blocking the program.
Example:
def blockingPlayFirstHalfChipmunk(sound):
  stop = getLength(sound) / 2
  playAtRateInRange(sound, 1.4, 1, stop)
This takes in a sound and blocking plays the first half of it back at 1.4 normal speed (Chipmunk speed). _ setSample|setSample(A Sample, An Integer):
argument1: A Sample, the sound sample tou want to change the value of.
argument2: An Integer, the value you want to set the sample to.
Takes a Sample object and a value, and sets the sample to that value.
Example:
def setTenthSample(sound, value):
  samp = getSampleObjectAt(sound, 10)
  setSample(samp, value)
This takes a sound and an integer, and then sets the value of the 10th sample in the sound to the passed in value. _ setSampleValueAt|setSampleValueAt(A Sound, An Integer, An Integer):
argument1: A Sound, the sound you want to change a sample in.
argument2: An Integer, the index of the sample you want to set.
argument3: An Integer, the new value of the sample you want to set.
Takes a sound, an index, and a value (should be between -32000 and 32000), and sets the value of the sample at the given index in the given sound to the given value.
Example:
def setTenthToTen(sound):
  setSampleValueAt(sound, 10, 10)
This takes in a sound and sets the value of the 10th sample to 10. _ writeSoundTo|writeSoundTo(A Sound, A String):
argument1: A Sound, the sound you want to write out to a file.
argument2: A String, the path of the location you want to write the sound.
Takes a sound and a filename (a string) and writes the sound to that file as a WAV file. (Make sure that the filename ends in Ò.wavÓ if you want the operating system to treat it right.)
Example:
def writeTempSound(sound):
  writeSoundTo(sound, 'C:\temp\temp.wav')
This takes in a sound and writes it out to a file called temp.wav in c:\temp\. _ addLine|addLine(picture, startX, startY, endX, endY):
picture: the picture you want to draw the line on
startX: the x position you want the line to start
startY: the y position you want the line to start
endX: the x position you want the line to end
endY: the y position you want the line to end
Takes a picture, a starting (x, y) position (two numbers), and an ending (x, y) position (two more numbers, four total) and draws a black line from the starting point to the ending point in the picture.
Example:
def drawDiagonal(picture):
  addLine(picture, 0, 0, 100, 100)
This will take in a picture and draw a black diagonal line on it from (0,0) to (100, 100). _ addRect|addRect(picture, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws a black rectangle in outline of the given width and height with the position (x, y) as the upper left corner.
Example:
def addSquare(picture, startX, startY, edge):
  addRect(picture, startX, startY, edge, edge)
This will take in a picture, start coordinates, and a edge length and call addRect to draw a rectangle with all sides the same length. _ addRectFilled|addRectFilled(picture, startX, startY, width, height):
picture: the picture you want to draw the rectangle on
startX: the x-coordinate of the upper left-hand corner of the rectangle
startY: the y-coordinate of the upper left-hand corner of the rectangle
width: the width of the rectangle
height: the height of the rectangle
Takes a picture, a starting (x, y) position (two numbers), and a width and height (two more numbers, four total) then draws a black-filled rectangle of the given width and height with the position (x, y) as the upper left corner.
Example:
def addSquareFilled(picture, startX, startY, edge):
  addRectFilled(picture, startX, startY, edge, edge)
This will take in a picture, start coordinates, and a edge length and call addRectFilled to draw a solid rectangle with all sides the same length. _ addText|addText(picture, xpos, ypos, text):
picture: the picture you want to add the text to
xpos: the x-coordinate where you want to start writing the text
ypos: the y-coordinate where you want to start writing the text
text: s string containing the text you want written
Takes a picture, an x position and a y position (two numbers), and some text as a string, which will get drawn into the picture.
Example:
def addDate(picture):
  str = "Today is the first day of the rest of your life."
  addText(picture, 0, 0, str)
This takes in a picture and adds a date stamp to the upper left corner. _ distance|distance(color1, color2):
color1: the first color you want compared
color2: the second color you want compared
Takes two Color objects and returns a single number representing the distance between the colors. The red, green, and blue values of the colors are taken as a point in (x, y, z) space, and the cartesian distance is computed.
Example:
def showDistRedAndBlue():
  red = makeColor(255, 0, 0)
  blue = makeColor(0, 0, 255)
  print distance(red, blue)
This will print the distance between red and blue, 360.62445840513925. _ getColor|getColor(pixel):
pixel: the pixel you want to extract the color from
returns: a color, the color from the pixel
Takes a Pixel and returns the Color object at that pixel.
Example:
def getDistanceFromRed(pixel):
  red = makeColor(255, 0, 0)
  col = getColor(pixel)
  return distance(red, col)
This takes in a pixel and returns that pixel's color's distance from red. _ setColor|setColor(pixel, color):
pixel: the pixel you want to set the color of
color: the color you want to set the pixel to
Takes in a pixel and a color, and sets the pixel to the provided color. Example:
def makeMoreBlue(pixel):
  myBlue = getBlue(pixel) + 60
  newColor = makeColor(getRed(pixel), getGreen(pixel), myBlue)
  setColor(pixel, newColor)
This will take in a pixel and increase its level of blue by 60. _ getRed|getRed(pixel):
pixel: the pixel you want to get the amount of red from
returns: the red value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of redness in that pixel.
Example:
def getHalfRed(pixel):
  red = getRed(pixel)
  return red / 2
This takes in a pixel and returns the amount of red in that pixel divided by two. _ getGreen|getGreen(pixel):
pixel: the pixel you want to get the amount of green from
returns: the green value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of greenness in that pixel.
Example:
def getHalfGreen(pixel):
  green = getGreen(pixel)
  return green / 2
This takes in a pixel and returns the amount of green in that pixel divided by two. _ getBlue|getBlue(pixel):
pixel: the pixel you want to get the amount of blue from
returns: the blue value of the pixel
Takes a Pixel object and returns the value (between 0 and 255) of the amount of blueness in that pixel.
Example:
def getHalfBlue(pixel):
  blue = getBlue(pixel)
  return blue / 2
This takes in a pixel and returns the amount of blue in that pixel divided by two. _ getHeight|getHeight(picture):
picture: the picture you want to get the height of
returns: the height of the picture
Takes a picture as input and returns its length in the number of pixels top-to-bottom in the picture.
Example:
def howTall(picture)
  height = getHeight(picture)
  print "The picture is " + str(height) + " pixels tall."
This takes in a picture and prints a descriptive message about its height. _ getPixels|getPixels(picture):
picture: the picture you want to get the pixels from
returns: a list of all the pixels in the picture
Takes a picture as input and returns the sequence of Pixel objects in the picture.
Example:
def getTenthPixel(picture):
  pixels = getPixels(picture)
  return pixels[10]
This takes in a picture and returns the 10th pixel in that picture. _ getPixel|getPixel(picture, xpos, ypos):
picture: the picture you want to get the pixel from
xpos: the x-coordinate of the pixel you want
ypos: the y-coordinate of the pixel you want
Takes a picture, an x position and a y position (two numbers), and returns the Pixel object at that point in the picture.
Example:
def getUpperLeftPixel(picture)
  return getPixel(picture, 0, 0)
This will take in a picture and return the pixel in the upper left-hand corner, (0, 0). _ getWidth|getWidth(picture):
picture: the picture you want to get the width of
returns: the width of the picture
Takes a picture as input and returns its length in the number of pixels left-to-right in the picture.
Example:
def howTall(picture)
  width = getWidth(picture)
  print "The picture is " + str(width) + " pixels wide."
This takes in a picture and prints a descriptive message about its width. _ getX|getX(pixel):
pixel: the pixel you want to find the x-coordinate of
returns: the x-coordinate of the pixel Takes in a pixel object and returns the x position of where that pixel is in the picture.
Example:
def getHalfX(pixel):
  pos = getX(pixel)
  return pos / 2
This will take in a pixel and return half of its x-coordinate. _ getY|getY(pixel):
pixel: the pixel you want to find the y-coordinate of
returns: the y-coordinate of the pixel
Takes in a pixel object and returns the y position of where that pixel is in the picture.
Example:
def getHalfY(pixel):
  pos = getY(pixel)
  return pos / 2
This will take in a pixel and return half of its y-coordinate. _ makeColor|makeColor(red, green, blue):
red: the amount of red you want in the color
green: the amount of green you want in the color
blue: the amount of blue you want in the picture
returns: the color made from the inputs
Takes three inputs: For the red, green, and blue components (in order), then returns a color object.
Example:
def makeGrey(amount):
  return makeColor(amount, amount, amount)
This will take in an amount and make a grey color based on that. _ makeDarker|makeDarker(color):
color: the color you want to darken
returns: the new, darker color
Takes a color and returns a slightly darker version of the original color.
Example:
def makeMuchDarker(color):
  return makeDarker(makeDarker(makeDarker(color)))
Takes in a color and returns a much darker version of it by calling makeDarker three times. _ makeLighter|makeLighter(color):
color: the color you want to lighten
returns: the new, lighter color
Takes a color and returns a slightly lighter version of the original color.
Example:
def makeMuchLighter(color):
  return makeLighter(makeLighter(makeLighter(color)))
Takes in a color and returns a much lighter version of it by calling makeLighter three times. _ makePicture|makePicture(path):
path: the name of the file you want to open as a picture
returns: a picture object made from the file
Takes a filename as input, reads the file, and creates a picture from it. Returns the picture.
Example:
def makePictureSelector():
  file = pickAFile()
  return makePicture(file)
This function will open a file selector box and then return the picture object made from that file. _ makeEmptyPicture|makeEmptyPicture():
Creates a blank (all black) picture object and returns it. _ pickAColor|pickAColor():
returns: the color selected in the picker
Takes no input, but puts up a color picker. Find the color you want, and the function will return the Color object of what you picked. _ pickAFile|pickAFile():
returns: a string containing the path to the file selected in the file picker
Lets the user pick a file and returns the complete path name as a string. No input. _ pickAFolder|pickAFolder():
returns: a string containing the path to the folder selected in the folder picker
Lets the user pick a folder and returns the complete path name as a string. No input. _ quit|quit():
Quitters never win. _ setRed|setRed(pixel, redValue):
pixel: the pixel you want to set the red value in.
redValue: a number (0 - 254) for the new red value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the redness of that pixel to the given value.
Example:
def zeroRed(pixel):
  setRed(pixel, 0)
This will take in a pixel and set its amount of red to 0. _ setGreen|setGreen(pixel, greenValue):
pixel: the pixel you want to set the green value in.
greenValue: a number (0 - 254) for the new green value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the greenness of that pixel to the given value.
Example:
def zeroGreen(pixel):
  setGreen(pixel, 0)
This will take in a pixel and set its amount of green to 0. _ setBlue|setBlue(pixel, blueValue):
pixel: the pixel you want to set the blue value in.
blueValue: a number (0 - 254) for the new blue value of the pixel
Takes in a Pixel object and a value (between 0 and 254) and sets the blueness of that pixel to the given value.
Example:
def zeroBlue(pixel):
  setBlue(pixel, 0)
This will take in a pixel and set its amount of blue to 0. _ show|show(picture):
picture: the picture you want to see
Shows the picture provided as input. _ repaint|repaint(picture):
picture: the picture you want to repaint
Repaints the picture if it has been opened in a window from show(picture). _ writePictureTo|writePictureTo(picture, path):
picture: the picture you want to be written out to a file
path: the path to the file you want the picture written to
Takes a picture and a file name (string) as input, then writes the picture to the file as a JPEG. (Be sure to end the filename in Ò.jpgÓ for the operating system to understand it well.)
Example:
def writeTempPic(picture):
  file = r"C:\Temp\temp.jpg"
  writePictureTo(picture, file)
This takes in a picture and writes it to C:\Temp\temp.jpg. _ openPictureTool|openPictureTool(picture)
picture: the picture that you want to examine
Opens the Picture Tool explorer, which lets you examine the pixels of an image. _ openSoundTool|openSoundTool(sound)
sound : the sound that you want to examine
Opens the Sound Tool explorer, which lets you examine the waveform of a sound. _ makeMovieFromPictures|makeMovieFromPictures(frames, path, framerate):
frames: a list of pictures to write out as frames of the movie
path: the path to the file where you want the movie written
framerate: OPTIONAL the framerate in frames per second you want the movie to play. If not given, it will default to 30.
Takes a list of frames and writes them out to a quicktime movie. Make sure that the file you write out to ends in ".mov". The movie will be created from the frames in order by index from the first to last. The speed of the movie may be specified or default to 30. _ openMovie|openMovie(filename):
filename: the path to the movie you wish to open in the player
Opens the movie at the given path into a movie player. _