pitchr package

Submodules

pitchr.df_import module

pitchr.df_import.measures_from_ml_output(pitches, durations, time_signature)[source]

Transform an array of Pitch Numbers into a list of measures

Parameters
  • pitches – Numpy.array of int32

  • durations – a list of float detailing corresponding durations of each row in harmony_df

  • time_signature – string. Example: ‘4/4’

Returns measures

list of measures

pitchr.harmony_maker module

pitchr.helper module

pitchr.helper.center_txt(msg, row, window)[source]
pitchr.helper.dialog1_box(prompt)[source]
pitchr.helper.explanation(title, text1, text2, stdscr)[source]

Outputs explanation of a specific data structure

Parameters
  • title – title of DS

  • text – explanation

  • stdscr – curses background

pitchr.helper.export_sample_song(stdscr)[source]

Exports sample song to Python code

Parameters

stdscr – curses background

pitchr.helper.main()[source]
pitchr.helper.run_gui(stdscr)[source]

Runs curses GUI

Parameters

stdscr – curses background

pitchr.helper.show_menu(stdscr)[source]

Shows menu of options

Parameters

stdscr – curses background

Returns menu

curses window

pitchr.helper.window_border()[source]

Draws border around windows :returns window: curses window

pitchr.lyexport module

pitchr.lyexport.save_string_and_execute_LilyPond_silent(ly_string, filename, command)[source]

A helper function for to_png and to_pdf. Should not be used directly. :param ly_string: :param filename: :param command: :return: true if export was successful, false if failed :rtype: bool

pitchr.lyexport.show_score_png(score)[source]

Reveals the score in an image form. Image will block the current process until it is closed in non-interactive scripts.

Parameters

score

pitchr.lyexport.to_ly(score)[source]

convert score to lilypond string :param score: :return: lilypond string :rtype: string

pitchr.lyexport.to_pdf(ly_string, filename)[source]

write lilypond string to PDF using lilypond executable :param ly_string: :param filename: :return: whether export was successful :rtype: bool

pitchr.lyexport.to_png(ly_string, filename)[source]

write lilypond string to PNG using lilypond executable :param ly_string: :param filename: :return: whether export was successful :rtype: bool

pitchr.lyexport.write_to_pdf(score, output_file)[source]

write score to PDF :param score: :param output_file:

pitchr.lyexport.write_to_png(score, output_file)[source]

write score to PNG :param score: :param output_file:

pitchr.model_maker module

pitchr.music module

class pitchr.music.Chord(notes=None)[source]

Bases: pitchr.music._Music

Class representing an organized group of notes.

Parameters

notes – [Note]

property accidentals

Get the accidentals of a Chord

Returns

accidentals (string)

append(note)[source]

Append a note to a Chord

Parameters

note – Note

static augmented_triad(note)[source]

Get the augmented triad of a Note

Parameters

note – Note

Returns

Chord

clear()[source]

Clears all notes from a Chord

determine()[source]

Used to determine the type of chord

static diminished_triad(note)[source]

Get the diminished triad of a Note

Parameters

note – Note

Returns

Chord

property duration

Get the duration of a Chord

Returns

duration

static get_chord(note)[source]
static get_triads(key)[source]

Returns all triads in a given key

Parameters

key – String

property letter

Get the letter of a Chord

Returns

letter

static major_triad(note)[source]

Get the major triad of a Note

Parameters

note – Note

Returns

Chord

static mingusChord_to_chord(mingus_chord, root)[source]
static minor_triad(note)[source]

Get the minor triad of a Note

Parameters

note – Note

Returns

Chord

property notes

Get the notes of a Chord

Returns

[Note]

property octave

Get the octave of a Chord

Returns

octave

property pitch

Get the pitch of a Chord

Returns

String of letter-note, accidentals, and octave

play()[source]

Plays music

remove(note)[source]

Remove a note from a Chord

Parameters

note – Note

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

static suspended_triad(note)[source]

Get the suspended triad of a Note

Parameters

note – Note

Returns

Chord

class pitchr.music.Clef(value)[source]

Bases: enum.Enum

An enumeration.

BASS = 1
TREBLE = 0
class pitchr.music.Interval[source]

Bases: object

Stores Pitch Intervals.

M2 = 2
M3 = 4
M4 = 5
M5 = 7
M6 = 9
M7 = 11
M8 = 12
m2 = 1
m3 = 3
m5 = 6
m6 = 8
m7 = 10
class pitchr.music.Key(flats=0, sharps=0)[source]

Bases: object

Class representing the Key the Score is played in

Parameters
  • flats – number of flats in the Key

  • sharps – number of sharps in the Key

A_MAJOR = <pitchr.music.Key object>
A_MINOR = <pitchr.music.Key object>
Ab_MAJOR = <pitchr.music.Key object>
B_MAJOR = <pitchr.music.Key object>
B_MINOR = <pitchr.music.Key object>
Bb_MAJOR = <pitchr.music.Key object>
Bb_MINOR = <pitchr.music.Key object>
C_MAJOR = <pitchr.music.Key object>
C_MINOR = <pitchr.music.Key object>
C_SHARP_MAJOR = <pitchr.music.Key object>
C_SHARP_MINOR = <pitchr.music.Key object>
Cb_MAJOR = <pitchr.music.Key object>
D_MAJOR = <pitchr.music.Key object>
D_MINOR = <pitchr.music.Key object>
Db_MAJOR = <pitchr.music.Key object>
E_MAJOR = <pitchr.music.Key object>
E_MINOR = <pitchr.music.Key object>
Eb_MAJOR = <pitchr.music.Key object>
Eb_MINOR = <pitchr.music.Key object>
F_MAJOR = <pitchr.music.Key object>
F_MINOR = <pitchr.music.Key object>
F_SHARP_MAJOR = <pitchr.music.Key object>
F_SHARP_MINOR = <pitchr.music.Key object>
G_MAJOR = <pitchr.music.Key object>
G_MINOR = <pitchr.music.Key object>
G_SHARP_MINOR = <pitchr.music.Key object>
Gb_MAJOR = <pitchr.music.Key object>
property fifths

Returns number of fifths that defines this key signature.

Returns

number of fifths that defines this key signature.

property flat

Returns True if this key signature contains flats :returns: this key signature contains flats

property ly

Returns a lilypond string representation of this key signature. Consists of the tonic in lowercase with “-is” or “-es” if sharp or flat respectively, and then “major”. :returns: lilypond string representation of this key signature

property major_scale

Returns the index of the tonic of this key signature.

Returns

list of strings of the 8 letters representing the major scale associated with this major key

property major_tonic

Returns the tonic/root of this key signature, assuming a major key.

Returns

returns the letter of the key signature’s tonic

property major_tonic_offset

Returns the index of the tonic of this key signature.

Returns

the related offset (in half steps) of this tonic from middle C

property sharp

Returns True if this key signature contains sharps :returns: this key signature contains sharps

class pitchr.music.Keyboard[source]

Bases: object

Simulates a piano keyboard. Useful for calculating scales.

static key(i, sharps=True)[source]

Given a number, returns the letter of an associated key on the keyboard. Middle C is defined to be 0.

Parameters
  • i – index of key on keyboard

  • sharps – if True, gives accidentals in sharp form rather than flat form.

Returns

letter note of associated key

class pitchr.music.Measure(notes=None, time_signature=None)[source]

Bases: pitchr.music._Music

Class representing a collection of notes.

Parameters

notes – []

append(item)[source]

Adds new note to current measure

Parameters

item – Note

property duration

Returns the total duration of notes in this measure

extend(notes)[source]
play()[source]

Plays music

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

property time_signature

Get time signature of the Measure

Returns

time signature

class pitchr.music.Note(pitch, duration, dynamic=None, articulation=None, tie=False)[source]

Bases: pitchr.music._Music

Class representing the smallest unit for the Pitcher.

Parameters
  • pitch – string with letter name, accidentals, and octave, such as ‘A#4’

  • duration – note duration

  • dynamic – dynamic, such as piano, forte, crescendo, etc

  • articulation – articulation, such as staccato, accent, fermata, etc

  • tie – when true will play this note continuously into the next note

property accidentals

Get the accidentals of a Note

Returns

accidentals (string)

property articulation

Get the articulation of a Note

Returns

duration

augment()[source]

Raises the note by a half step

diminish()[source]

Lowers the note by a half step

property duration

Get the duration of a Note

Returns

duration

property dynamic

Get the dynamic of a Note

Returns

dynamic

get_accidentals_wrt_key(key)[source]
property letter

Get the letter of a Note

Returns

letter

static mingusNote_to_note(mingus_note, note)[source]
property mingus_note

Returns mingus note

property octave

Get the octave of a Note

Returns

octave

octave_down()[source]

Lowers the Note an octave

octave_up()[source]

Raises the Note an octave

property pitch

Get the pitch of a Note

Returns

String of letter-note, accidentals, and octave

property pitch_number
play()[source]

Plays music

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

property tie

Get the tie status of a Note

Returns

tie

transpose(half_steps)[source]

Transpose the Note by half_steps

Parameters

half_steps – string of +/- and number of half-steps, ex: ‘+11’ or ‘-4’

class pitchr.music.Part(staffs=None, tempo=60, time_signature=None, key_signature=None)[source]

Bases: pitchr.music._Music

Class representing a collection of staffs. Add effects / stanza-chorus / key/time changes to parts. Should affect its children.

Parameters
  • staffs – from Staff()

  • tempo – int

  • time_signature – instance of Time

  • key_signature – instance of Key

add_staff(staff)[source]

Adds a staff to the current Part

Parameters

staff – Staff

property key_signature

Get the key signature of the current Part

Returns

key signature

play()[source]

Plays music

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

property tempo
property time_signature

Get the time signature of the current Part

Returns

time signature

exception pitchr.music.PitcherException[source]

Bases: Exception

Exceptions related to Pitcher issues

class pitchr.music.Rest(duration)[source]

Bases: pitchr.music.Note

Class representing a Rest Note. Has no pitch. Only duration.

Parameters

duration – float

property accidentals

Get the accidentals of a Note

Returns

accidentals (string)

augment()[source]

Raises the note by a half step

diminish()[source]

Lowers the note by a half step

property letter

Get the letter of a Note

Returns

letter

property octave

Get the octave of a Note

Returns

octave

octave_down()[source]

Lowers the Note an octave

octave_up()[source]

Raises the Note an octave

property pitch

Get the pitch of a Note

Returns

String of letter-note, accidentals, and octave

property pitch_number
transpose(half_steps)[source]

Transpose the Note by half_steps

Parameters

half_steps – string of +/- and number of half-steps, ex: ‘+11’ or ‘-4’

class pitchr.music.Score(parts=None, title=None, subtitle=None, author=None, author_email=None)[source]

Bases: pitchr.music._Music

Class representing a collection of parts

Parameters
  • parts – [Part]

  • title – str

  • subtitle – str

  • author – str

  • author_email – str

add_part(part)[source]

Adds a new Part to the current Score

Parameters

part – Part

property author

Get the author of the current Score.

Returns

Author

property composer

Alias for author of the score

play()[source]

Plays music

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

property title

Get the title of the current Score.

Returns

title

class pitchr.music.Staff(measures=None, clef=<Clef.TREBLE: 0>, voice=<Voice.PIANO: 0>, time_signature=None)[source]

Bases: pitchr.music._Music

Class representing a collection of measures.

Parameters
  • clef – from Clef()

  • voice – from Voice()

  • measures – Measure()

property clef

Get clef of the Staff

Returns

clef

play()[source]

Plays music

save(filename)[source]

Saves music to a PDF

show()[source]

Shows a graphic of music

property time_signature

Get time signature of the Staff

Returns

time signature

property voice

Get voice of the Staff

Returns

voice

class pitchr.music.Time(time)[source]

Bases: object

Class representing the Time signature the Score is played in

Parameters

time – String representing the time signature

COMMON_TIME = <pitchr.music.Time object>
CUT_TIME = <pitchr.music.Time object>
property beat_definition

Get the beat definition of the Score

Returns

beat definition

property beats_per_measure

Get the beats per measure of the Score

Returns

beats per measure

class pitchr.music.Voice(value)[source]

Bases: enum.Enum

An enumeration.

PIANO = 0
pitchr.music.key(key_signature)[source]

Sets the global key signature

Parameters

key_signature – Key Signature object

pitchr.music.time(time_signature)[source]

Sets the global time signature

Parameters

key_signature – Time Signature object

pitchr.pitch_tagger module

pitchr.pitch_tagger.tag_accidentals(notes_df)[source]

Tag accidentals to a dataframe of notes

Parameters

notes_df – dataframe of notes

pitchr.pitch_tagger.tag_pitch(notes_df)[source]

Tags pitch information to a dataframe of notes from XML file

Parameters

notes_df – dataframe of notes

pitchr.pitch_tagger.tag_pitch_interval(notes_df)[source]

Tag pitch intervals to a dataframe of notes

Parameters

notes_df – dataframe of notes

pitchr.playing module

class pitchr.playing.Event(event_type, pitch_number, velocity, time)[source]

Bases: object

Represents a MIDI keyon/keyoff event.

Parameters
  • event_type – a MIDI message type of “note_on” or “note_off”

  • pitch_number – int representing the pitch of the key”

  • velocity – int representing the velocity of keypress

  • time – number of ticks after the previous event

property event_type
property pitch_number
property time
property velocity
class pitchr.playing.EventType(value)[source]

Bases: enum.Enum

Enumeration of Event types

KEY_OFF = 'note_off'
KEY_ON = 'note_on'
pitchr.playing.play_score(score)[source]

Plays a score. :param score: instance of Pitchr.Score :returns: True

pitchr.predict module

class pitchr.predict.Predict(measure)[source]

Bases: object

Class representation of a bigram model

find_in_tuples(note_tuple, tuples)[source]
novel()[source]

Determines how novel a sequence of notes is :returns novelty: value from 0 to 1

qtd_in_tuples(note_tuple, tuples)[source]
class pitchr.predict.PredictDF(dataframe)[source]

Bases: pitchr.predict.Predict

A version of the bigram modeller that consumes dataframes

pitchr.predict.novelty(measure)[source]
pitchr.predict.tag_predictability(notes_df)[source]

pitchr.utils module

pitchr.xml_parser module

Module contents