Jump to: main library, tunepad.chords, tunepad.constants

playNote(note, beats = 1.0, velocity = 100, sustain = 0)

Play a note with a pitch value greater than 0. You can also call playNote with a list of notes that will be played at the same time. The optional parameter beats sets how long the note will last, and the optional parameter velocity sets how hard/loud the note sounds. Velocity can be any number between 0 and 127. The optional sustain parameter allows a note to ring out longer than the value given by the beats parameter. The value of the parameter is the number of beats the note should sustain in beats.
playNote(32)
playNote(55, beats = 0.5, velocity = 20)
playNote(0, beats = 2, velocity = 80)
playNote(0, beats = 2, velocity = 80, sustain = 2)
playNote([36, 40, 43])
playNote([36, 40, 43], beats = 2)

playSound(sound, beats = 1.0, pitch = 0, velocity = 100, sustain = 0)

Play a custom sound using its ID number. You can also call playSound with a list of sounds that will be played at the same time. The optional parameter beats sets how long the note will last, and the optional parameter velocity sets how hard/loud the note sounds. Velocity can be any number between 0 and 127. The optional pitch parameter changes the pitch of the sound by the given number of semi-tones. For example, a pitch value of 3.0 would be the same as the difference from a C to a D♯ on the piano keyboard. The optional sustain parameter allows a note to ring out longer than the value given by the beats parameter. The value of the parameter is the number of beats the note should sustain in beats.
playSound(1203)
playSound(1203, beats = 0.5, velocity = 20)
playSound(1203, beats = 0.5, velocity = 20, sustain = 4)
playSound(1203, beats = 2, pitch = 3, velocity = 80)
playSound([1203, 559, 43])

rest(beats = 1)

Add a pause between notes. The length of the pause can be set using the optional beats parameter.
rest()
rest(2)
rest(beats = 1.5)

moveTo(time)

Moves the playhead forward or backward in time to an arbitrary position. In TunePad, the playhead marks the current time. For example, after calling playNote(32, beats = 2), the playhead will have advanced by 2 beats. The time parameter is given in beats and specifies the point that the playhead will be placed. For example, a value of 0 would move the playhead to the beginning of a track.
moveTo(0)
moveTo(4)
moveTo(0.5)

rewind(beats)

Moves the playhead backward in time by an amount relative to its current position. This can be a useful way to play multiple notes at the same time. The beats parameter specifies the number of beats to move the playhead. Negative values of beats move the playhead forward.
rewind(1)
rewind(-2)
rewind(0.5)

fastForward(beats)

Moves the playhead forward in time by an amount relative to its current position. This can be a useful way to play multiple notes at the same time. The beats parameter specifies the number of beats to move the playhead. Negative values of beats move the playhead backward.
fastForward(1.5)
fastForward(-2)

getPlayhead()

Returns the current value of the playhead as a float. This value is zero-indexed, therefore the first beat will be zero rather than one.
getPlayhead() # returns 0.0
playNote(0, beats = 1)
getPlayhead() # returns 1.0

getMeasure()

Returns an integer of the value of the current measure. This value is zero-indexed, therefore the first measure will be zero rather than one.
getMeasure() # returns 0
playNote(0, beats = 4)
getMeasure() # returns 1

getBeat()

Returns a decimal of the value of the current beat of the measure. This value is zero-indexed, therefore the first beat will be zero rather than one.
getBeat() # returns 0

playNote(0, beats = 2)
getBeat() # returns 2

playNote(0, beats = 1)
getBeat() # returns 3

playNote(0, beats = 1)
getMeasure() # returns 0

for loop

You can repeat something over and over using a for loop. In the first example, the variable called i counts from 0 to 7. In the second example, i counts from 36 to 45.
for i in range(0, 8):
   playNote(50)
   rest()

for i in range(36, 46):
   playNote(i)
   rest()

with bend(cents = 0, beats = -1, start = 0):

Adds a pitch bend effect that changes the value of notes over time. The cents parameter represents the total change in pitch. One cent is equal to 1/100 of a semitone (the distance between two adjacent notes). Using a value of 500 for the cents parameter would bend the note by five semitones (the same as the distance from a C to an F on the piano keyboard). The beats parameter specifies how long it takes for the note to bend. If you don't provide the beats parameter, the effect will be constant. An optional start parameter specifies how long to wait (in beats) before starting the effect. You can also provide a list of values instead of a single number for the cents parameter. These values represent the change in cents over time. Each number will be evenly distributed over the duration of the effect.
# apply a constant pitch bend
with bend(cents = 100):
    playNote(36)

# bend a note from 48 to 53 over one beat
with bend(cents = 500, beats = 1):
    playNote(48)

# bouncy spring effect
with bend(cents = [0, 500, -500, 500, -500, 500, 0], beats = 1):
    playNote(42, beats = 2)

with transpose(steps):

Shifts the pitch of a section of music by a constant amount. This is equivalent to adding or subtracting a constant number from the note parameter of playNote. The steps parameter represents the change in pitch. One step is equal the distance between two adjacent notes. Using a value of 12 for the steps parameter would shift every note up by an octave.
# shifts each note up 7 steps
with transpose(7):
    playNote(36)
    playNote(36)
    playNote(39)
    playNote(41)

# shifts each note down 12 steps (an octave)
with transpose(-12):
    playNote(36)
    playNote(36)
    playNote(39)
    playNote(41)

with gain(value = 0, beats = 1, start = 0):

Changes the volume of notes. The value parameter represents the change in volume (for example a value of 0.5 would reduce the volume by 50%). If a single number is provided, a constant change in volume will be applied—there will be no change over time. You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect given by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.
# cut the volume by half
with gain(0.5):
    playNote(48)

# fade in
with gain(value = [ 0, 1 ], beats = 2):
    playNote(48, beats = 2)

# fade out after one beat
with gain(value = [ 1, 0 ], beats = 2, start = 1)
    playNote(42, beats = 3)

with pan(value = 0, beats = 1, start = 0):

Applies a stereo pan effect, shifting the sound more towards the left or right speaker. The value parameter ranges from -1.0 (full left speaker) to 1.0 (full right speaker). A value of 0.0 evenly splits the sound. If a single number is provided, the effect will be constant—there will be no change over time. You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect given by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.
# slowly pan from the left speaker to the right over three beats
with pan(value = [-1.0, 1.0], beats = 3):
    playNote(35, beats = 3)

with lowpass(frequency = 1000, beats = 1, start = 0):

Applies a lowpass filter effect that reduces the energy of high frequency sounds while leaving low frequency sounds below a cutoff point unaffected. The frequency parameter specifies the cutoff frequency for the effect (between 10 Hz and 22 kHz). You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect given by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.
# creates a wha-wha effect after one beat by quickly changing
# the frequency cutoff of a lowpass filter between 200 and 800hz
with lowpass(frequency = [200, 800, 200, 800, 200, 800], beats=1):
    playNote(47, beats=3)


# adds a rhythmic pulse to piano notes
for i in range(0, 4):
    with lowpass(frequency = [ 50, 800, 50 ], beats = 0.25, start = 1):
        playNote(33, 2) 

with highpass(frequency = 1000, beats = 1, start = 0):

The highpass filter reduces the energy of low frequency sounds while allowing frequencies above the cutoff point to pass through unaltered. The frequency parameter specifies the cutoff frequency for the effect (between 10 Hz and 22 kHz). You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect specified by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.

with bandpass(frequency = 1000, beats = 1, start = 0):

The bandpass filter allows frequencies near the cutoff point to pass through unaltered while reducing the energy of frequencies above and below. The frequency parameter specifies the cutoff frequency for the effect (between 10 Hz and 22 kHz). You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect specified by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.
# carving out frequencies for a clap sound in the drums
clap = 10
with bandpass(frequency = [100, 11000], beats=4):
    for i in range(0, 16):
        playNote(clap, beats = 0.25)

with notch(frequency = 1000, beats = 1, start = 0):

The notch filter reduces the energy of sounds near the cutoff frequency, while allowing higher and lower frequencies to pass through unaltered. The frequency parameter specifies the cutoff frequency for the effect (between 10 Hz and 22 kHz). You can also pass a list of numbers to create a change over time. Each number will be evenly distributed over the duration of the effect specified by the beats parameter. An optional start parameter specifies how long to wait (in beats) before starting the effect.

with swing(value, beats = None, start = 0, rate= 0.5):

The swing effect introduces delays in rhythmic patterns which adds a bounce to the rhythm's timing. This can make the performance sound more human by removing the mechanical precision. The value parameter is a number between 0.0 and 1.0 which specifies how pronounced this effect should be. The rate parameter specifies which note value should be swung.
# partly swing a 8th note snare pattern
snare = 2
with swing(0.5):
    for i in range(0, 16):
        playNote(snare, beats = 0.5)


# fully swing a 16th note highhat pattern
highhat = 4
with swing(1.0, rate=0.25):
    for i in range(0, 16):
        playNote(highhat, beats = 0.25)

tunepad.chords module

Import this module into your code using from tunepad.chords import *
For more information on each function and examples, see the playChord tutorial Jam Session.

changeKey(key)

In TunePad, we can specify the key of a cell with the changeKey function, which changes the global key of that cell. This function accepts a string from the set of possible keys, with the default key being specified by the project.

playChord(chord, beats=1, velocity=90, sustain=0, playType='block', octave=3, inversion=0)

The playChord function plays a specified diatonic or chromatic chord for a given key. The chord is specified as a Roman Numeral string. The beats, velocity, and sustain parameters all work identically to playNote. Using the octave parameter, we can specify the octave in which the chord is played. This octave parameter is an integer in the range [-1, 9]. The inversion parameter controls the ordering of the pitches in the chord and has a range of [0, 3]. Using the playType argument allows us to choose from one of five methods of playing our chord:

buildChord(chord, octave=3, inversion=0)

The buildChord function returns a list of integers of an inputted diatonic or chromatic chord the global key corresponding to the notes of specified by a Roman Numeral string and inputted octave. Unlike playChord, buildChord does not play the chord. The octave can be specified using an integer value in the range [-1, 9]. The inversion parameter controls the ordering of the pitches and has a range of [0, 3].

buildScale(tonic, octave, mode, direction="ascending")

The buildScale function returns a list of integers corresponding to the notes of an inputted musical scale starting on an inputted note and octave. The starting note is specified with the tonic parameter. Valid inputs for this parameter are the same as the valid keys for changeKey. The octave can be specified using an integer value in the range [-1, 9]. The direction parameter supports "ascending" and "descending" and dictates whether the scale is in increasing order of pitch or decreasing order of pitch. The mode parameter accepts a string equivalent to:

transpose(pitchSet, origKey, newKey)

The transpose function accepts a pitch set in the form of a list of integers that is in one key and returns that set shifted to a new key. The origKey parameter is the original key that the pitch set belongs to and newKey is the key that will be transposed to; both origKey and newKey are specified using the same valid keys for changeKey function.

tunepad.constants module

Import this module into your code using from tunepad.constants import *
This module defines variables for note names and beat values.

For note names, these are defined using the scheme root_note + accidental + octave. Root notes are any valid musical note. Accidentals can be blank, b (representing flats), or s (representing sharps). Octave is represented by numbers 0-9.
  from tunepad.constants import *

  print(A3)  # prints 57
  print(Cs2) # prints 37
  print(Bb4) # prints 70

  playNote(C5)
  playNote(D5)
  playNote([C5, E5, G5], 4)


For beat values, these are represented by the traditional note type (e.g. quarter or half) followed by _NOTE:
  from tunepad.constants import *

  print(WHOLE_NOTE)          # prints 4.0
  print(QUARTER_NOTE_DOTTED) # prints 1.5
  print(TRIPLET_NOTE)        # prints 0.33333

  playNote(C5, HALF_NOTE)

  for _ in range(6):
      playNote(A4, beats = SEXTUPLET_NOTE)

  playSound(123, EIGHTH_NOTE)