idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
47,400
def find_frets ( self , note , maxfret = 24 ) : result = [ ] if type ( note ) == str : note = Note ( note ) for x in self . tuning : if type ( x ) == list : base = x [ 0 ] else : base = x diff = base . measure ( note ) if 0 <= diff <= maxfret : result . append ( diff ) else : result . append ( None ) return result
Return a list with for each string the fret on which the note is played or None if it can t be played on that particular string .
47,401
def frets_to_NoteContainer ( self , fingering ) : res = [ ] for ( string , fret ) in enumerate ( fingering ) : if fret is not None : res . append ( self . get_Note ( string , fret ) ) return NoteContainer ( res )
Convert a list such as returned by find_fret to a NoteContainer .
47,402
def get_Note ( self , string = 0 , fret = 0 , maxfret = 24 ) : if 0 <= string < self . count_strings ( ) : if 0 <= fret <= maxfret : s = self . tuning [ string ] if type ( s ) == list : s = s [ 0 ] n = Note ( int ( s ) + fret ) n . string = string n . fret = fret return n else : raise RangeError ( "Fret '%d' on string ...
Return the Note on string fret .
47,403
def load_img ( name ) : fullname = name try : image = pygame . image . load ( fullname ) if image . get_alpha ( ) is None : image = image . convert ( ) else : image = image . convert_alpha ( ) except pygame . error , message : print "Error: couldn't load image: " , fullname raise SystemExit , message return ( image , i...
Load image and return an image object
47,404
def play_note ( note ) : index = None if note == Note ( 'B' , 2 ) : index = 0 elif note == Note ( 'A' , 2 ) : index = 1 elif note == Note ( 'G' , 2 ) : index = 2 elif note == Note ( 'E' , 2 ) : index = 3 elif note == Note ( 'C' , 2 ) : index = 4 elif note == Note ( 'A' , 3 ) : index = 5 elif note == Note ( 'B' , 3 ) : ...
play_note determines which pad was hit and send the play request to fluidsynth
47,405
def play_note ( note ) : global text octave_offset = ( note . octave - LOWEST ) * width if note . name in WHITE_KEYS : w = WHITE_KEYS . index ( note . name ) * white_key_width w = w + octave_offset playing_w . append ( [ w , tick , note ] ) else : i = BLACK_KEYS . index ( note . name ) if i == 0 : w = 18 elif i == 1 : ...
play_note determines the coordinates of a note on the keyboard image and sends a request to play the note to the fluidsynth server
47,406
def add_composition ( self , composition ) : if not hasattr ( composition , 'tracks' ) : raise UnexpectedObjectError ( "Object '%s' not expected. Expecting " "a mingus.containers.Composition object." % composition ) self . compositions . append ( composition ) return self
Add a composition to the suite .
47,407
def set_author ( self , author , email = '' ) : self . author = author self . email = email
Set the author of the suite .
47,408
def set_title ( self , title , subtitle = '' ) : self . title = title self . subtitle = subtitle
Set the title and the subtitle of the suite .
47,409
def set_range ( self , range ) : if type ( range [ 0 ] ) == str : range [ 0 ] = Note ( range [ 0 ] ) range [ 1 ] = Note ( range [ 1 ] ) if not hasattr ( range [ 0 ] , 'name' ) : raise UnexpectedObjectError ( "Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % range [ 0 ] ) self . range = range
Set the range of the instrument .
47,410
def note_in_range ( self , note ) : if type ( note ) == str : note = Note ( note ) if not hasattr ( note , 'name' ) : raise UnexpectedObjectError ( "Unexpected object '%s'. " "Expecting a mingus.containers.Note object" % note ) if note >= self . range [ 0 ] and note <= self . range [ 1 ] : return True return False
Test whether note is in the range of this Instrument .
47,411
def can_play_notes ( self , notes ) : if hasattr ( notes , 'notes' ) : notes = notes . notes if type ( notes ) != list : notes = [ notes ] for n in notes : if not self . note_in_range ( n ) : return False return True
Test if the notes lie within the range of the instrument .
47,412
def play_Note ( self , note ) : velocity = 64 channel = 1 if hasattr ( note , 'dynamics' ) : if 'velocity' in note . dynamics : velocity = note . dynamics [ 'velocity' ] if 'channel' in note . dynamics : channel = note . dynamics [ 'channel' ] if hasattr ( note , 'channel' ) : channel = note . channel if hasattr ( note...
Convert a Note object to a midi event and adds it to the track_data .
47,413
def play_NoteContainer ( self , notecontainer ) : if len ( notecontainer ) <= 1 : [ self . play_Note ( x ) for x in notecontainer ] else : self . play_Note ( notecontainer [ 0 ] ) self . set_deltatime ( 0 ) [ self . play_Note ( x ) for x in notecontainer [ 1 : ] ]
Convert a mingus . containers . NoteContainer to the equivalent MIDI events and add it to the track_data .
47,414
def play_Bar ( self , bar ) : self . set_deltatime ( self . delay ) self . delay = 0 self . set_meter ( bar . meter ) self . set_deltatime ( 0 ) self . set_key ( bar . key ) for x in bar : tick = int ( round ( ( 1.0 / x [ 1 ] ) * 288 ) ) if x [ 2 ] is None or len ( x [ 2 ] ) == 0 : self . delay += tick else : self . se...
Convert a Bar object to MIDI events and write them to the track_data .
47,415
def play_Track ( self , track ) : if hasattr ( track , 'name' ) : self . set_track_name ( track . name ) self . delay = 0 instr = track . instrument if hasattr ( instr , 'instrument_nr' ) : self . change_instrument = True self . instrument = instr . instrument_nr for bar in track : self . play_Bar ( bar )
Convert a Track object to MIDI events and write them to the track_data .
47,416
def stop_Note ( self , note ) : velocity = 64 channel = 1 if hasattr ( note , 'dynamics' ) : if 'velocity' in note . dynamics : velocity = note . dynamics [ 'velocity' ] if 'channel' in note . dynamics : channel = note . dynamics [ 'channel' ] if hasattr ( note , 'channel' ) : channel = note . channel if hasattr ( note...
Add a note_off event for note to event_track .
47,417
def stop_NoteContainer ( self , notecontainer ) : if len ( notecontainer ) <= 1 : [ self . stop_Note ( x ) for x in notecontainer ] else : self . stop_Note ( notecontainer [ 0 ] ) self . set_deltatime ( 0 ) [ self . stop_Note ( x ) for x in notecontainer [ 1 : ] ]
Add note_off events for each note in the NoteContainer to the track_data .
47,418
def set_instrument ( self , channel , instr , bank = 1 ) : self . track_data += self . select_bank ( channel , bank ) self . track_data += self . program_change_event ( channel , instr )
Add a program change and bank select event to the track_data .
47,419
def header ( self ) : chunk_size = a2b_hex ( '%08x' % ( len ( self . track_data ) + len ( self . end_of_track ( ) ) ) ) return TRACK_HEADER + chunk_size
Return the bytes for the header of track .
47,420
def midi_event ( self , event_type , channel , param1 , param2 = None ) : assert event_type < 0x80 and event_type >= 0 assert channel < 16 and channel >= 0 tc = a2b_hex ( '%x%x' % ( event_type , channel ) ) if param2 is None : params = a2b_hex ( '%02x' % param1 ) else : params = a2b_hex ( '%02x%02x' % ( param1 , param2...
Convert and return the paraters as a MIDI event in bytes .
47,421
def note_off ( self , channel , note , velocity ) : return self . midi_event ( NOTE_OFF , channel , note , velocity )
Return bytes for a note off event .
47,422
def note_on ( self , channel , note , velocity ) : return self . midi_event ( NOTE_ON , channel , note , velocity )
Return bytes for a note_on event .
47,423
def controller_event ( self , channel , contr_nr , contr_val ) : return self . midi_event ( CONTROLLER , channel , contr_nr , contr_val )
Return the bytes for a MIDI controller event .
47,424
def set_deltatime ( self , delta_time ) : if type ( delta_time ) == int : delta_time = self . int_to_varbyte ( delta_time ) self . delta_time = delta_time
Set the delta_time .
47,425
def set_tempo ( self , bpm ) : self . bpm = bpm self . track_data += self . set_tempo_event ( self . bpm )
Convert the bpm to a midi event and write it to the track_data .
47,426
def set_tempo_event ( self , bpm ) : ms_per_min = 60000000 mpqn = a2b_hex ( '%06x' % ( ms_per_min / bpm ) ) return self . delta_time + META_EVENT + SET_TEMPO + '\x03' + mpqn
Calculate the microseconds per quarter note .
47,427
def time_signature_event ( self , meter = ( 4 , 4 ) ) : numer = a2b_hex ( '%02x' % meter [ 0 ] ) denom = a2b_hex ( '%02x' % int ( log ( meter [ 1 ] , 2 ) ) ) return self . delta_time + META_EVENT + TIME_SIGNATURE + '\x04' + numer + denom + '\x18\x08'
Return a time signature event for meter .
47,428
def set_key ( self , key = 'C' ) : if isinstance ( key , Key ) : key = key . name [ 0 ] self . track_data += self . key_signature_event ( key )
Add a key signature event to the track_data .
47,429
def key_signature_event ( self , key = 'C' ) : if key . islower ( ) : val = minor_keys . index ( key ) - 7 mode = '\x01' else : val = major_keys . index ( key ) - 7 mode = '\x00' if val < 0 : val = 256 + val key = a2b_hex ( '%02x' % val ) return '{0}{1}{2}\x02{3}{4}' . format ( self . delta_time , META_EVENT , KEY_SIGN...
Return the bytes for a key signature event .
47,430
def track_name_event ( self , name ) : l = self . int_to_varbyte ( len ( name ) ) return '\x00' + META_EVENT + TRACK_NAME + l + name
Return the bytes for a track name meta event .
47,431
def int_to_varbyte ( self , value ) : length = int ( log ( max ( value , 1 ) , 0x80 ) ) + 1 bytes = [ value >> i * 7 & 0x7F for i in range ( length ) ] bytes . reverse ( ) for i in range ( len ( bytes ) - 1 ) : bytes [ i ] = bytes [ i ] | 0x80 return pack ( '%sB' % len ( bytes ) , * bytes )
Convert an integer into a variable length byte .
47,432
def to_chords ( progression , key = 'C' ) : if type ( progression ) == str : progression = [ progression ] result = [ ] for chord in progression : ( roman_numeral , acc , suffix ) = parse_string ( chord ) if roman_numeral not in numerals : return [ ] if suffix == '7' or suffix == '' : roman_numeral += suffix r = chords...
Convert a list of chord functions or a string to a list of chords .
47,433
def determine ( chord , key , shorthand = False ) : result = [ ] if type ( chord [ 0 ] ) == list : for c in chord : result . append ( determine ( c , key , shorthand ) ) return result func_dict = { 'I' : 'tonic' , 'ii' : 'supertonic' , 'iii' : 'mediant' , 'IV' : 'subdominant' , 'V' : 'dominant' , 'vi' : 'submediant' , ...
Determine the harmonic function of chord in key .
47,434
def tuple_to_string ( prog_tuple ) : ( roman , acc , suff ) = prog_tuple if acc > 6 : acc = 0 - acc % 6 elif acc < - 6 : acc = acc % 6 while acc < 0 : roman = 'b' + roman acc += 1 while acc > 0 : roman = '#' + roman acc -= 1 return roman + suff
Create a string from tuples returned by parse_string .
47,435
def substitute_minor_for_major ( progression , substitute_index , ignore_suffix = False ) : ( roman , acc , suff ) = parse_string ( progression [ substitute_index ] ) res = [ ] if suff == 'm' or suff == 'm7' or suff == '' and roman in [ 'II' , 'III' , 'VI' ] or ignore_suffix : n = skip ( roman , 2 ) a = interval_diff (...
Substitute minor chords for its major equivalent .
47,436
def substitute_diminished_for_diminished ( progression , substitute_index , ignore_suffix = False ) : ( roman , acc , suff ) = parse_string ( progression [ substitute_index ] ) res = [ ] if suff == 'dim7' or suff == 'dim' or suff == '' and roman in [ 'VII' ] or ignore_suffix : if suff == '' : suff = 'dim' last = roman ...
Substitute a diminished chord for another diminished chord .
47,437
def interval_diff ( progression1 , progression2 , interval ) : i = numeral_intervals [ numerals . index ( progression1 ) ] j = numeral_intervals [ numerals . index ( progression2 ) ] acc = 0 if j < i : j += 12 while j - i > interval : acc -= 1 j -= 1 while j - i < interval : acc += 1 j += 1 return acc
Return the number of half steps progression2 needs to be diminished or augmented until the interval between progression1 and progression2 is interval .
47,438
def skip ( roman_numeral , skip = 1 ) : i = numerals . index ( roman_numeral ) + skip return numerals [ i % 7 ]
Skip the given places to the next roman numeral .
47,439
def add_note ( self , note , octave = None , dynamics = { } ) : if type ( note ) == str : if octave is not None : note = Note ( note , octave , dynamics ) elif len ( self . notes ) == 0 : note = Note ( note , 4 , dynamics ) else : if Note ( note , self . notes [ - 1 ] . octave ) < self . notes [ - 1 ] : note = Note ( n...
Add a note to the container and sorts the notes from low to high .
47,440
def add_notes ( self , notes ) : if hasattr ( notes , 'notes' ) : for x in notes . notes : self . add_note ( x ) return self . notes elif hasattr ( notes , 'name' ) : self . add_note ( notes ) return self . notes elif type ( notes ) == str : self . add_note ( notes ) return self . notes for x in notes : if type ( x ) =...
Feed notes to self . add_note .
47,441
def from_chord_shorthand ( self , shorthand ) : self . empty ( ) self . add_notes ( chords . from_shorthand ( shorthand ) ) return self
Empty the container and add the notes in the shorthand .
47,442
def from_interval ( self , startnote , shorthand , up = True ) : return self . from_interval_shorthand ( startnote , shorthand , up )
Shortcut to from_interval_shorthand .
47,443
def from_interval_shorthand ( self , startnote , shorthand , up = True ) : self . empty ( ) if type ( startnote ) == str : startnote = Note ( startnote ) n = Note ( startnote . name , startnote . octave , startnote . dynamics ) n . transpose ( shorthand , up ) self . add_notes ( [ startnote , n ] ) return self
Empty the container and add the note described in the startnote and shorthand .
47,444
def remove_note ( self , note , octave = - 1 ) : res = [ ] for x in self . notes : if type ( note ) == str : if x . name != note : res . append ( x ) else : if x . octave != octave and octave != - 1 : res . append ( x ) else : if x != note : res . append ( x ) self . notes = res return res
Remove note from container .
47,445
def remove_notes ( self , notes ) : if type ( notes ) == str : return self . remove_note ( notes ) elif hasattr ( notes , 'name' ) : return self . remove_note ( notes ) else : map ( lambda x : self . remove_note ( x ) , notes ) return self . notes
Remove notes from the containers .
47,446
def remove_duplicate_notes ( self ) : res = [ ] for x in self . notes : if x not in res : res . append ( x ) self . notes = res return res
Remove duplicate and enharmonic notes from the container .
47,447
def transpose ( self , interval , up = True ) : for n in self . notes : n . transpose ( interval , up ) return self
Transpose all the notes in the container up or down the given interval .
47,448
def get_note_names ( self ) : res = [ ] for n in self . notes : if n . name not in res : res . append ( n . name ) return res
Return a list with all the note names in the current container .
47,449
def determine ( notes ) : notes = set ( notes ) res = [ ] for key in keys : for scale in _Scale . __subclasses__ ( ) : if scale . type == 'major' : if ( notes <= set ( scale ( key [ 0 ] ) . ascending ( ) ) or notes <= set ( scale ( key [ 0 ] ) . descending ( ) ) ) : res . append ( scale ( key [ 0 ] ) . name ) elif scal...
Determine the scales containing the notes .
47,450
def degree ( self , degree_number , direction = 'a' ) : if degree_number < 1 : raise RangeError ( "degree '%s' out of range" % degree_number ) if direction == 'a' : notes = self . ascending ( ) [ : - 1 ] return notes [ degree_number - 1 ] elif direction == 'd' : notes = reversed ( self . descending ( ) ) [ : - 1 ] retu...
Return the asked scale degree .
47,451
def begin_track ( tuning , padding = 2 ) : names = [ x . to_shorthand ( ) for x in tuning . tuning ] basesize = len ( max ( names ) ) + 3 res = [ ] for x in names : r = ' %s' % x spaces = basesize - len ( r ) r += ' ' * spaces + '||' + '-' * padding res . append ( r ) return res
Helper function that builds the first few characters of every bar .
47,452
def add_headers ( width = 80 , title = 'Untitled' , subtitle = '' , author = '' , email = '' , description = '' , tunings = [ ] ) : result = [ '' ] title = str . upper ( title ) result += [ str . center ( ' ' . join ( title ) , width ) ] if subtitle != '' : result += [ '' , str . center ( str . title ( subtitle ) , wi...
Create a nice header in the form of a list of strings using the information that has been filled in .
47,453
def from_Note ( note , width = 80 , tuning = None ) : if tuning is None : tuning = default_tuning result = begin_track ( tuning ) min = 1000 ( s , f ) = ( - 1 , - 1 ) if hasattr ( note , 'string' ) and hasattr ( note , 'fret' ) : n = tuning . get_Note ( note . string , note . fret ) if n is not None and int ( n ) == in...
Return a string made out of ASCII tablature representing a Note object or note string .
47,454
def from_Track ( track , maxwidth = 80 , tuning = None ) : result = [ ] width = _get_width ( maxwidth ) if not tuning : tuning = track . get_tuning ( ) lastlen = 0 for bar in track : r = from_Bar ( bar , width , tuning , collapse = False ) barstart = r [ 1 ] . find ( '||' ) + 2 if ( len ( r [ 0 ] ) + lastlen ) - barsta...
Convert a mingus . containers . Track object to an ASCII tablature string .
47,455
def from_Composition ( composition , width = 80 ) : instr_tunings = [ ] for track in composition : tun = track . get_tuning ( ) if tun : instr_tunings . append ( tun ) else : instr_tunings . append ( default_tuning ) result = add_headers ( width , composition . title , composition . subtitle , composition . author , co...
Convert a mingus . containers . Composition to an ASCII tablature string .
47,456
def from_Suite ( suite , maxwidth = 80 ) : subtitle = str ( len ( suite . compositions ) ) + ' Compositions' if suite . subtitle == '' else suite . subtitle result = os . linesep . join ( add_headers ( maxwidth , suite . title , subtitle , suite . author , suite . email , suite . description , ) ) hr = maxwidth * '=' n...
Convert a mingus . containers . Suite to an ASCII tablature string complete with headers .
47,457
def _get_qsize ( tuning , width ) : names = [ x . to_shorthand ( ) for x in tuning . tuning ] basesize = len ( max ( names ) ) + 3 barsize = ( ( width - basesize ) - 2 ) - 1 return max ( 0 , int ( barsize / 4.5 ) )
Return a reasonable quarter note size for tuning and width .
47,458
def _get_width ( maxwidth ) : width = maxwidth / 3 if maxwidth <= 60 : width = maxwidth elif 60 < maxwidth <= 120 : width = maxwidth / 2 return width
Return the width of a single bar when width of the page is given .
47,459
def triad ( note , key ) : return [ note , intervals . third ( note , key ) , intervals . fifth ( note , key ) ]
Return the triad on note in key as a list .
47,460
def triads ( key ) : if _triads_cache . has_key ( key ) : return _triads_cache [ key ] res = map ( lambda x : triad ( x , key ) , keys . get_notes ( key ) ) _triads_cache [ key ] = res return res
Return all the triads in key .
47,461
def augmented_triad ( note ) : return [ note , intervals . major_third ( note ) , notes . augment ( intervals . major_fifth ( note ) ) ]
Build an augmented triad on note .
47,462
def seventh ( note , key ) : return triad ( note , key ) + [ intervals . seventh ( note , key ) ]
Return the seventh chord on note in key .
47,463
def sevenths ( key ) : if _sevenths_cache . has_key ( key ) : return _sevenths_cache [ key ] res = map ( lambda x : seventh ( x , key ) , keys . get_notes ( key ) ) _sevenths_cache [ key ] = res return res
Return all the sevenths chords in key in a list .
47,464
def dominant_flat_ninth ( note ) : res = dominant_ninth ( note ) res [ 4 ] = intervals . minor_second ( note ) return res
Build a dominant flat ninth chord on note .
47,465
def dominant_sharp_ninth ( note ) : res = dominant_ninth ( note ) res [ 4 ] = notes . augment ( intervals . major_second ( note ) ) return res
Build a dominant sharp ninth chord on note .
47,466
def eleventh ( note ) : return [ note , intervals . perfect_fifth ( note ) , intervals . minor_seventh ( note ) , intervals . perfect_fourth ( note ) ]
Build an eleventh chord on note .
47,467
def dominant_flat_five ( note ) : res = dominant_seventh ( note ) res [ 2 ] = notes . diminish ( res [ 2 ] ) return res
Build a dominant flat five chord on note .
47,468
def from_shorthand ( shorthand_string , slash = None ) : if type ( shorthand_string ) == list : res = [ ] for x in shorthand_string : res . append ( from_shorthand ( x ) ) return res if shorthand_string in [ 'NC' , 'N.C.' ] : return [ ] shorthand_string = shorthand_string . replace ( 'min' , 'm' ) shorthand_string = sh...
Take a chord written in shorthand and return the notes in the chord .
47,469
def determine ( chord , shorthand = False , no_inversions = False , no_polychords = False ) : if chord == [ ] : return [ ] elif len ( chord ) == 1 : return chord elif len ( chord ) == 2 : return [ intervals . determine ( chord [ 0 ] , chord [ 1 ] ) ] elif len ( chord ) == 3 : return determine_triad ( chord , shorthand ...
Name a chord .
47,470
def determine_triad ( triad , shorthand = False , no_inversions = False , placeholder = None ) : if len ( triad ) != 3 : return False def inversion_exhauster ( triad , shorthand , tries , result ) : intval1 = intervals . determine ( triad [ 0 ] , triad [ 1 ] , True ) intval2 = intervals . determine ( triad [ 0 ] , tria...
Name the triad ; return answers in a list .
47,471
def determine_seventh ( seventh , shorthand = False , no_inversion = False , no_polychords = False ) : if len ( seventh ) != 4 : return False def inversion_exhauster ( seventh , shorthand , tries , result , polychords ) : triads = determine_triad ( seventh [ : 3 ] , True , True ) intval3 = intervals . determine ( seven...
Determine the type of seventh chord ; return the results in a list ordered on inversions .
47,472
def determine_extended_chord5 ( chord , shorthand = False , no_inversions = False , no_polychords = False ) : if len ( chord ) != 5 : return False def inversion_exhauster ( chord , shorthand , tries , result , polychords ) : def add_result ( short ) : result . append ( ( short , tries , chord [ 0 ] ) ) triads = determi...
Determine the names of an extended chord .
47,473
def determine_extended_chord6 ( chord , shorthand = False , no_inversions = False , no_polychords = False ) : if len ( chord ) != 6 : return False def inversion_exhauster ( chord , shorthand , tries , result , polychords , ) : if tries == 1 and not no_polychords : polychords += determine_polychords ( chord , shorthand ...
Determine the names of an 6 note chord .
47,474
def determine_polychords ( chord , shorthand = False ) : polychords = [ ] function_list = [ determine_triad , determine_seventh , determine_extended_chord5 , determine_extended_chord6 , determine_extended_chord7 ] if len ( chord ) <= 3 : return [ ] elif len ( chord ) > 14 : return [ ] elif len ( chord ) - 3 <= 5 : func...
Determine the polychords in chord . This function can handle anything from polychords based on two triads to 6 note extended chords .
47,475
def from_Note ( note , process_octaves = True , standalone = True ) : if not hasattr ( note , 'name' ) : return False result = note . name [ 0 ] . lower ( ) for accidental in note . name [ 1 : ] : if accidental == '#' : result += 'is' elif accidental == 'b' : result += 'es' if process_octaves : oct = note . octave if o...
Get a Note object and return the LilyPond equivalent in a string .
47,476
def from_NoteContainer ( nc , duration = None , standalone = True ) : if nc is not None and not hasattr ( nc , 'notes' ) : return False if nc is None or len ( nc . notes ) == 0 : result = 'r' elif len ( nc . notes ) == 1 : result = from_Note ( nc . notes [ 0 ] , standalone = False ) else : result = '<' for notes in nc ...
Get a NoteContainer object and return the LilyPond equivalent in a string .
47,477
def from_Bar ( bar , showkey = True , showtime = True ) : if not hasattr ( bar , 'bar' ) : return False if showkey : key_note = Note ( bar . key . key [ 0 ] . upper ( ) + bar . key . key [ 1 : ] ) key = '\\key %s \\%s ' % ( from_Note ( key_note , False , standalone = False ) , bar . key . mode ) result = key else : res...
Get a Bar object and return the LilyPond equivalent in a string .
47,478
def from_Track ( track ) : if not hasattr ( track , 'bars' ) : return False lastkey = Key ( 'C' ) lasttime = ( 4 , 4 ) result = '' for bar in track . bars : if lastkey != bar . key : showkey = True else : showkey = False if lasttime != bar . meter : showtime = True else : showtime = False result += from_Bar ( bar , sho...
Process a Track object and return the LilyPond equivalent in a string .
47,479
def from_Composition ( composition ) : if not hasattr ( composition , 'tracks' ) : return False result = '\\header { title = "%s" composer = "%s" opus = "%s" } ' % ( composition . title , composition . author , composition . subtitle ) for track in composition . tracks : result += from_Track ( track ) + ' ' return resu...
Return the LilyPond equivalent of a Composition in a string .
47,480
def save_string_and_execute_LilyPond ( ly_string , filename , command ) : ly_string = '\\version "2.10.33"\n' + ly_string if filename [ - 4 : ] in [ '.pdf' , '.png' ] : filename = filename [ : - 4 ] try : f = open ( filename + '.ly' , 'w' ) f . write ( ly_string ) f . close ( ) except : return False command = 'lilypond...
A helper function for to_png and to_pdf . Should not be used directly .
47,481
def determine ( value ) : i = - 2 for v in base_values : if value == v : return ( value , 0 , 1 , 1 ) if value < v : break i += 1 scaled = float ( value ) / 2 ** i if scaled >= 0.9375 : return ( base_values [ i ] , 0 , 1 , 1 ) elif scaled >= 0.8125 : return ( base_values [ i + 1 ] , 0 , 7 , 4 ) elif scaled >= 17 / 24.0...
Analyse the value and return a tuple containing the parts it s made of .
47,482
def init ( sf2 , driver = None , file = None ) : global midi , initialized if not initialized : if file is not None : midi . start_recording ( file ) else : midi . start_audio_output ( driver ) if not midi . load_sound_font ( sf2 ) : return False midi . fs . program_reset ( ) initialized = True return True
Initialize the audio .
47,483
def start_recording ( self , file = 'mingus_dump.wav' ) : w = wave . open ( file , 'wb' ) w . setnchannels ( 2 ) w . setsampwidth ( 2 ) w . setframerate ( 44100 ) self . wav = w
Initialize a new wave file for recording .
47,484
def load_sound_font ( self , sf2 ) : self . sfid = self . fs . sfload ( sf2 ) return not self . sfid == - 1
Load a sound font .
47,485
def create ( self , group_type , config_file , group_name = None , region = None , profile_name = None ) : logging . info ( "[begin] create command using group_types:{0}" . format ( self . group_types ) ) config = GroupConfigFile ( config_file = config_file ) if config . is_fresh ( ) is False : raise ValueError ( "Conf...
Create a Greengrass group in the given region .
47,486
def _create_subscription_definition ( gg_client , group_type , config ) : logging . info ( '[begin] Configuring routing subscriptions' ) sub_info = gg_client . create_subscription_definition ( Name = "{0}_routing" . format ( group_type . type_name ) ) logging . info ( 'Created subscription definition: {0}' . format ( s...
Configure routing subscriptions for a Greengrass group .
47,487
def clean_core ( self , config_file , region = None , profile_name = None ) : config = GroupConfigFile ( config_file = config_file ) if region is None : region = self . _region core_cert_id = config [ 'core' ] [ 'cert_id' ] core_cert_arn = config [ 'core' ] [ 'cert_arn' ] core_thing_name = config [ 'core' ] [ 'thing_na...
Clean all Core related provisioned artifacts from both the local file and the AWS Greengrass service .
47,488
def clean_devices ( self , config_file , region = None , profile_name = None ) : config = GroupConfigFile ( config_file = config_file ) if region is None : region = self . _region devices = config [ 'devices' ] if 'device_thing_name' in devices : logging . info ( 'Configured devices already clean' ) return policy_name ...
Clean all device related provisioned artifacts from both the local file and the AWS Greengrass service .
47,489
def clean_file ( config_file ) : logging . info ( '[begin] Cleaning config file' ) config = GroupConfigFile ( config_file = config_file ) if config . is_fresh ( ) is True : raise ValueError ( "Config is already clean." ) config . make_fresh ( ) logging . info ( '[end] Cleaned config file:{0}' . format ( config_file ) )
Clean all provisioned artifacts from the local config file .
47,490
def clean_all ( self , config_file , region = None , profile_name = None ) : logging . info ( '[begin] Cleaning all provisioned artifacts' ) config = GroupConfigFile ( config_file = config_file ) if config . is_fresh ( ) is True : raise ValueError ( "Config is already clean." ) if region is None : region = self . _regi...
Clean all provisioned artifacts from both the local file and the AWS Greengrass service .
47,491
def deploy ( self , config_file , region = None , profile_name = None ) : config = GroupConfigFile ( config_file = config_file ) if config . is_fresh ( ) : raise ValueError ( "Config not yet tracking a group. Cannot deploy." ) if region is None : region = self . _region gg_client = _get_gg_session ( region = region , p...
Deploy the configuration and Lambda functions of a Greengrass group to the Greengrass core contained in the group .
47,492
def create_core ( self , thing_name , config_file , region = None , cert_dir = None , account_id = None , policy_name = 'ggc-default-policy' , profile_name = None ) : config = GroupConfigFile ( config_file = config_file ) if config . is_fresh ( ) is False : raise ValueError ( "Config file already tracking previously cr...
Using the thing_name value creates a Thing in AWS IoT attaches and downloads new keys & certs to the certificate directory then records the created information in the local config file for inclusion in the Greengrass Group as a Greengrass Core .
47,493
def create_devices ( self , thing_names , config_file , region = None , cert_dir = None , append = False , account_id = None , policy_name = 'ggd-discovery-policy' , profile_name = None ) : logging . info ( "create_devices thing_names:{0}" . format ( thing_names ) ) config = GroupConfigFile ( config_file = config_file ...
Using the thing_names values creates Things in AWS IoT attaches and downloads new keys & certs to the certificate directory then records the created information in the local config file for inclusion in the Greengrass Group as Greengrass Devices .
47,494
def associate_devices ( self , thing_names , config_file , region = None , profile_name = None ) : logging . info ( "associate_devices thing_names:{0}" . format ( thing_names ) ) config = GroupConfigFile ( config_file = config_file ) if region is None : region = self . _region devices = config [ 'devices' ] if type ( t...
Using the thing_names values associate existing Things in AWS IoT with the config of another Greengrass Group for use as Greengrass Devices .
47,495
def send_data ( self , message ) : data = json . dumps ( message ) . encode ( 'utf-8' ) + b'\n' self . transport . write ( data )
Given an object encode as JSON and transmit to the server .
47,496
async def got_who_reply ( self , nick = None , real_name = None , ** kws ) : nick = nick [ 2 : ] if nick [ 0 : 2 ] == 'E_' else nick host , ports = real_name . split ( ' ' , 1 ) self . servers . remove ( nick ) logger . debug ( "Found: '%s' at %s with port list: %s" , nick , host , ports ) self . results [ host . lower...
Server replied to one of our WHO requests with details .
47,497
async def _keepalive ( self ) : while self . protocol : vers = await self . RPC ( 'server.version' ) logger . debug ( "Server version: " + repr ( vers ) ) await asyncio . sleep ( 600 )
Keep our connect to server alive forever with some pointless traffic .
47,498
def _send_request ( self , method , params = [ ] , is_subscribe = False ) : self . next_id += 1 req_id = self . next_id msg = { 'id' : req_id , 'method' : method , 'params' : params } if is_subscribe : waitQ = asyncio . Queue ( ) self . subscriptions [ method ] . append ( waitQ ) fut = asyncio . Future ( loop = self . ...
Send a new request to the server . Serialized the JSON and tracks id numbers and optional callbacks .
47,499
def _got_response ( self , msg ) : resp_id = msg . get ( 'id' , None ) if resp_id is None : method = msg . get ( 'method' , None ) if not method : logger . error ( "Incoming server message had no ID nor method in it" , msg ) return result = msg . get ( 'params' , None ) logger . debug ( "Traffic on subscription: %s" % ...
Decode and dispatch responses from the server .