def simple_transpose(c, full, interval, up): # determine whether can transpose by a full octave (only want to # transpose to nearest octave) # TODO: introduce recursive calls so track transposes itself # until it is within range, using full octave jumps unless # necessary to do half steps if (full): for i in range(len(c)): for j in range(len(c[i])): for k in range(len(c[i][j])): for l in range(len(c[i][j][k][2])): if (up): c[i][j][k][2][l].octave_up() else: c[i][j][k][2][l].octave_down() else: for i in range(len(c)): for j in range(len(c[i])): for k in range(len(c[i][j])): for l in range(len(c[i][j][k][2])): n = Note() if (up): c[i][j][k][2][l] = n.from_int(Note.__int__(c[i][j][k][2][l]) + interval) else: c[i][j][k][2][l] = n.from_int(Note.__int__(c[i][j][k][2][l]) - interval) ''' else: for i in range(len(c)): c[i] = c[i].transpose(interval, up) ''' return c
def generate_and_write_music( output_file, music_length, lengths_distribution, bpm, ): import mingus.core.notes as notes from mingus.containers.note import Note from mingus.containers.track import Track from mingus.midi import midi_file_out track = Track() for note, length in generate_music(music_length, lengths_distribution, note_base=36): n = Note() n.from_int(note) track.add_notes(n, length) midi_file_out.write_Track(output_file, track, bpm=bpm)
def rebuild_composition(old, xylo, cutoff): lowest = Note.__int__(Note('C', 8)) highest = Note.__int__(Note('C', 0)) new = Composition() for i in old.selected_tracks: t = Track() t.instrument = xylo for bar in old[i]: b = Bar() b.key.name = bar.key.name b.set_meter(bar.meter) # note value per beat == the denominator in time signature dem = b.meter[1] for lst in bar: value = lst[1] if (is_garbage(value, dem, cutoff[old.selected_tracks.index(i)])): continue # do not include lists without notes if (not lst[2]): continue nc = NoteContainer() for note in lst[2]: if (Note.__int__(note) < lowest): lowest = Note.__int__(note) if (Note.__int__(note) > highest): highest = Note.__int__(note) nc + note b.place_notes(nc, value) t.add_bar(b) new.add_track(t) # can't do the transposing until all notes in all tracks have been # compared against lowest and highest, which is why it is done here n1 = Note() n2 = Note() low = n1.from_int(lowest) high = n2.from_int(highest) # print("lowest and highest notes:", low, high) if (not xylo.notes_in_range([low, high])): new = transposer(new, lowest, highest, xylo) return new