musicianstructured
- an API for using the musicianstructured superclass to design your musicians
- musicianstructured musicians are designed to consider an entire measure at a time (that is, what will be played in this measure)
Data:
instrument
- string
- name of the instrument (eg. 'metronome', 'acousticguitar')
_energy
- integer
- the energy variable of the instrument, ranges between 0 and 100
- this corresponds to the instrument location on the screen with respect to the x-axis
- further to the right (on the screen) means higher energy
- energy should determine roughly how many notes are played per measure and how much emphasis (dynamics) should be placed on a note
_complexity
- integer
- the complexity variable of the instrument, ranges between 0 and 100
- this corresponds to the instrument location on the screen with respect to the y-axis
- further towards the top (on the screen) means higher complexity
- complexity should determine roughly how many of the notes are on off beats, the higher the complexity is the more complicated the rythum should sound
_my_tone
- integer
- the base tone of the instrument
- mainly applicable for monotone instruments (eg. drums)
_notes
- integer
- an optional variable holding the number of notes to be played
- modified by addNote and addChord to help you keep track of how many notes have been played with respect to how many notes should be played
- use of the variable is completely optional, it exists as a convenience
_key
- string
- the key the instrument is playing in
- mainly applicable for multi-tone instruments (eg. guitars)
_time
- tuple of (integer, integer)
- the time signature of the measure being played
- this tells the musician how many beats there are (first integer), and what type they are (second integer)
_plans
- tuple of (number, list of (notes))
- the internal data structure for musicians of this type
- the purpose of this is to allow the musician to decide note locations, lengths, dynamics, etc independantly
- the number is the location in the measure the following notes are (eg. 0 => beat 1, 1.5 => & of beat 2)
- the list is a list of notes (list allows for chords), all notes in the list are played at this point in the measure (determined by number)
- if this structure is followed, the notes will automatically be printed to the score at the end of the _write method
- must be reset to empty whenever _changed becomes True and new notes are being added.
_changed
- boolean
- true if a variable has been changed since the last time the measure was written
- false if no change has been made since the last time the measure was written
_durations
- dictionary
- a dictionary of types of notes and their lengths
- this is a short-cut to the dictionary note.Note.note_values
Methods:
compose(measure, window_start, window_duration)
- called by the composer to tell the musician to generate notes
- measure is a score measure, window_start is a number, window_duration is a number
- measure is the present measure being composed to
- window_start is the location in the measure that needs to be written (this is the last chance to write notes at this part of the measure and still have them played)
- window_duration is the length of time (in the measure) which needs to be written (last chance to be played)
- compose depends on decide, write, and _print
energy
- property to change the _energy variable of the musician
- sets self._changed to True if used as setter
complexity
- property to change the _complexity variable of the musician
- sets self._changed to True if used as setter
time
- property to change the _time variable of the musician
- sets self._changed to True if used as setter
key
- property to change the _key variable of the musician
- sets self._changed to True if used as setter
_print(measure)
- prints self._plans to the given measure
- measure is a score measure
- measure is the measure in the score presently being written to
- as long as the rules of plans have been obeyed, all of the notes in plans are added to the measure
_getStart(val)
- returns where in the measure the given val should be
- val is a number, returns an integer
- val indicates a point in a measure (ex. 1.5 => the & of 2)
- computes how far through the measure (in accordance with note.Note) the given val is
_addNote(location, tone)
- adds a note to _plans at the given location with the given tone
- location is a number, tone is an integer
- the note is automatically generated from the given information and is automatically added to self._plans
- decrements self._notes to keep track the number of notes that have been played
- notes are defaulted to be a QUARTER_NOTE in length and have a dynamic of Forte
_addChord(location, chord, chordlist)
- adds a chord to _plans at the given location with tones determined by the given chord in the given chordlist
- location is a number, chord is a string (eg. 'A', 'F#'), chordlist is a string (eg. major, minor)
- retrieves the series of tones for the given chord from the given chordlist and adds those tones at the given location using addNote
- manipulates self.notes so that adding a chord only decrements notes once (indicates that one note is played)
_decide()
- decides if notes need to be added to the measure
- this method should be overwritten by all subclasses, how often you decide to write should be dependant upon your musician's structure
_write()
- determines what notes are played when, the core of the AI goes here
- this method should be overwritten by all subclasses, determine how your musician will play!
Suggested Structure:
_genNotes()
- returns the number of notes to be played this measure
_locations()
- determines where each note should be placed
_lengths()
- determines how long each note should be
- should be determined after locations so that notes dont accidentally overlap
_dynamics()
- determines how intense (eg. Forte, Piano, Mezzo-forte) each note is
sample _write() method for suggested structure:
def _write(self)
self.plans = {}
self.notes = self.getNotes()
self.locations()
self.lengths()
self.dynamics()
self._changed = False