def test_diminish(self): b = Bar() c = Bar() b + "A" c + "Ab" b.diminish() self.assertEqual(b, c)
def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C' ]) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2)
def test_to_major(self): b = Bar() c = Bar() b + "C" c + "A" c.to_major() self.assertEqual(b, c)
def add_notes(self, note, duration=None): """Adds a [refMingusContainersNote Note], note as string or \ [refMingusContainersNotecontainer NoteContainer] to the last \ [refMingusContainersBar Bar]. If the [refMingusContainersBar Bar] is \ full, a new one will automatically be created. If the \ [refMingusContainersBar Bar] is not full but the note can't fit in, this \ method will return `False`. True otherwise. An !InstrumentRangeError exception will be raised if an \ [refMingusContainersInstrument Instrument] is attached to the Track, but \ the note turns out not to be within the range of the \ [refMingusContainersInstrument Instrument].""" if self.instrument != None: if not self.instrument.can_play_notes(note): raise InstrumentRangeError( "Note '%s' is not in range of the instrument (%s)" % (note, self.instrument)) if duration == None: duration = 4 # Check whether the last bar is full, if so create a new bar and add the # note there if len(self.bars) == 0: self.bars.append(Bar()) last_bar = self.bars[-1] if last_bar.is_full(): self.bars.append(Bar(last_bar.key, last_bar.meter)) # warning should hold note if it doesn't fit return self.bars[-1].place_notes(note, duration)
def test_diminish(self): b = Bar() c = Bar() b + 'A' c + 'Ab' b.diminish() self.assertEqual(b, c)
def test_to_major(self): b = Bar() c = Bar() b + 'C' c + 'A' c.to_major() self.assertEqual(b, c)
def record_new_bar(self, state): if hasattr(self, "bar"): self.track + self.bar b = Bar() b.set_meter(state["meter"]) b.length = 0.0 b.key = state["key"] self.bar = b
def _set_up_metronome(self): metronome = Track() bar = Bar('C', (4, 4)) metronome.add_bar(bar) kick = MidiPercussion.BassDrum1 kick.velocity = 120 for i in range(4): bar.place_notes(kick, value.quarter) return metronome
def generate_pattern(progression_list, key = "C", pattern_index = 0, nb_bars=1): pattern = patterns.PATTERNS[pattern_index] t = Track() for progression in progression_list: progression = progression_to_int(progression) for p in progression : # permet d'avancer dans la progression des mesures previews_note = None p_key = get_progression_key(p, key) b = Bar(key, (4, 4)) position_note = 0 already_used=[] for pattern_note in pattern : if position_note not in already_used : is_chord = chord_length(pattern_note, pattern, position_note) if is_chord[2] : note_list = [] # c est un accord for p_note in pattern[is_chord[0]:is_chord[1]+1] : note_str = get_note_pattern(p_note, p_key) note = Note(note_str, p_note[5]) if previews_note is not None: if p_note[4]=='+': if int(note) < previews_note : note.octave_up() elif p_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) note_list.append(note) for n in range(is_chord[0], is_chord[1]+1): already_used.append(n) b.place_notes(note_list, pattern_note[1]) else : note_str = get_note_pattern(pattern_note, p_key) note = Note(note_str, pattern_note[5]) if previews_note is not None: if pattern_note[4]=='+': if int(note) < previews_note : note.octave_up() elif pattern_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) b.place_notes(note, pattern_note[1]) already_used.append(position_note) position_note+=1 t.add_bar(b) return t
def index(): if request.method == 'POST': keys = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] meters = [(2,2), (2,4), (3,4), (4,4)] bars = int(request.form['bars']) key = keys[int(request.form['key'])] meter = meters[int(request.form['meter'])] scale = int(request.form['scale']) composition = Composition() composition.set_author("by givemeasheet.com", "*****@*****.**") composition.set_title("%d bars exercise in %s" % (bars, key)) track = Track(Guitar()) dificulty = 3 if scale == 0: scale = scales.diatonic(key) scale_name = "Natural Major" elif scale == 1: scale = scales.natural_minor(key) scale_name = "Natural Minor" elif scale == 2: scale = scales.harmonic_minor(key) scale_name = "Minor Harmonic" elif scale == 3: scale = scales.melodic_minor(key) scale_name = "Minor Melodic" composition.subtitle = scale_name for bar in range(0,bars): bar = Bar(key, meter) while not bar.is_full(): # Random note index = randrange(dificulty) note = Note(scale[index]) possibles = get_possibles(bar) bar.place_notes(note, possibles[randrange(len(possibles))]) track.add_bar(bar) composition.add_track(track) l = LilyPond.from_Composition(composition) u = uuid.uuid1() file_name = "/var/www/givemeasheet/givemeasheet/static/sheets/%s" % u.hex LilyPond.save_string_and_execute_LilyPond(l, file_name, "-fpng") sheet="/static/sheets/%s.png" % os.path.basename(file_name) midi="/static/sheets/%s.midi" % os.path.basename(file_name) MidiFileOut.write_Composition("%s.midi" % file_name, composition) return render_template('index.html', sheet=sheet, midi=midi) else: return render_template('index.html')
def generate_transition(previous_phrase, next_phrase, nb_note_needed, pattern_index, key): previous_note = Note(previous_phrase[len(previous_phrase)-1]) next_note = Note(next_phrase[0]) selected_notes = get_note_between(previous_note, next_note, previous_phrase) temp_selected = get_note_between(previous_note, next_note, next_phrase) for i in range(len(temp_selected)): if temp_selected[i] not in selected_notes: selected_notes.append(temp_selected[i]) if (float(len(selected_notes))/abs((nb_note_needed[0]+nb_note_needed[1])))<(float(3)/4): temp_from_scale = get_note_between(previous_note, next_note, generate_blues_scale(key)) for i in range(len(temp_from_scale)): if temp_from_scale[i] not in selected_notes: selected_notes.append(temp_from_scale[i]) first_bar = Bar() last_bar = Bar() for i in range(1, nb_note_needed[0]): time = first_bar.current_beat + 1 list_compatible = get_compatible_notes(pattern_index, selected_notes, key, time) print "liste compatible : " + str(list_compatible) list_length = get_max_length_note(first_bar, nb_note_needed[0]-i) best_notes = get_best_notes_transition(list_compatible, previous_note, next_note, 0, float(i)/nb_note_needed[0]) print "best_notes : " + str(best_notes) chosen_note = best_notes[random.randint(0, len(best_notes)-1)] chosen_length = list_length[random.randint(0, len(list_length)-1)] first_bar.place_notes(chosen_note.name, chosen_length) for i in range(1, nb_note_needed[1]): time = last_bar.current_beat + 1 list_compatible = get_compatible_notes(pattern_index, selected_notes, key, time) list_length = get_max_length_note(last_bar, nb_note_needed[1]-i) best_notes = get_best_notes_transition(list_compatible, previous_note, next_note, 1, float(i)/nb_note_needed[1]) chosen_note = best_notes[random.randint(0, len(best_notes)-1)] chosen_length = list_length[random.randint(0, len(list_length)-1)] last_bar.place_notes(chosen_note.name, chosen_length) if last_bar.length - last_bar.current_beat != 0 : print("ajout de silence") space_left = 1.0 / (last_bar.length - last_bar.current_beat) last_bar.place_rest(space_left) if first_bar.length - first_bar.current_beat != 0 : print("ajout de silence") space_left = 1.0 / (first_bar.length - first_bar.current_beat) first_bar.place_rest(space_left) return [first_bar, last_bar]
def play_pattern(pattern_index, key): pattern = patterns.PATTERNS[pattern_index] fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument previews_note = None b = Bar(key, (4, 4)) position_note = 0 already_used=[] for pattern_note in pattern : if position_note not in already_used : is_chord = chord_length(pattern_note, pattern, position_note) if is_chord[2] : note_list = [] # c est un accord for p_note in pattern[is_chord[0]:is_chord[1]+1] : note_str = get_note_pattern(p_note, key) note = Note(note_str, p_note[5]) if previews_note is not None: if p_note[4]=='+': if int(note) < previews_note : note.octave_up() elif p_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) note_list.append(note) for n in range(is_chord[0], is_chord[1]+1): already_used.append(n) b.place_notes(note_list, pattern_note[1]) else : note_str = get_note_pattern(pattern_note, key) note = Note(note_str, pattern_note[5]) if previews_note is not None: if pattern_note[4]=='+': if int(note) < previews_note : note.octave_up() elif pattern_note[4]=='-': if int(note) > previews_note : note.octave_down() previews_note = int(note) b.place_notes(note, pattern_note[1]) already_used.append(position_note) position_note+=1 fluidsynth.play_Bar(b, 1, 60)
def toTrack(key, meter, melody): _, base = meter t = Track() for mb in melody: b = Bar(key, meter) for mn in mb.split(): nr = mn.split(':') n = nr[0] r = base if len(nr) > 1: r = int(nr[1]) ok = b.place_notes(n, r) t.add_bar(b) return t
def drum_beat(beat_probas): b = Bar() for (bass, snare, hhat) in beat_probas: p = random() if p < bass: b.place_notes(BASS, 8) elif p < bass + snare: b.place_notes(SNARE, 8) elif p < bass + snare + hhat: b.place_notes(HIHAT, 8) else: b.place_rest(8) return b
def test_transpose(self): b = Bar() c = Bar() b + ['C', 'E', 'G'] c + ['E', 'G#', 'B'] b + ['F', 'A', 'C'] c + ['A', 'C#', 'E'] b.transpose('3', True) self.assertEqual(b, c) b.transpose('3', False) b.transpose('3') self.assertEqual(b, c)
def test_set_item(self): b = Bar() b + ['A', 'C', 'E'] c = Bar() c + ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = NoteContainer(['A', 'C', 'E']) self.assertEqual(b, c) c[0] = ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + NoteContainer(['C', 'E']) self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + 'C' c[0] = c[0][2] + 'E' self.assertEqual(b, c)
def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C']) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2)
def bassline(chord, beat_probas): chord_tones = chords.from_shorthand(chord) octave = 2 b = Bar() for (bass, els, octa) in beat_probas: p = random.random() if p < bass: b.place_notes(Note(chord_tones[0], octave), 8) elif p < bass + els: b.place_notes(Note(random.choice(chord_tones[1:]), octave), 8) elif p < bass + els + octa: b.place_notes(Note(chord_tones[0], octave + 1), 8) else: b.place_rest(8) return b
def test_augment(self): b = Bar() c = Bar() d = Bar() b + "A" c + "A#" d + "A##" b.augment() self.assertEqual(b, c) b.augment() self.assertEqual(b, d) c.augment() self.assertEqual(c, d)
def test_transpose(self): b = Bar() c= Bar() b + ["C", "E", "G"] c + ["E", "G#", "B"] b + ["F", "A", "C"] c + ["A", "C#", "E"] b.transpose("3", True) self.assertEqual(b, c) b.transpose("3", False) b.transpose("3") self.assertEqual(b, c)
def _next_bar(self): prev = None while True: chord_bar = Bar() nxt_chord = next(self.sim) nxt_voiced = voice(prev, nxt_chord) prev = nxt_voiced chord_bar + NoteContainer(nxt_voiced) chord_bar[0][1] = 1 self.current = nxt_chord yield (chord_bar, bassline(nxt_chord, self.bassproba), drum_beat(self.bassproba))
class test_LilyPond(unittest.TestCase): def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C' ]) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2) def test_from_Note(self): self.assertEqual(LilyPond.from_Note(Note('C'), standalone=False), "c'") self.assertEqual(LilyPond.from_Note(Note('C#'), standalone=False), "cis'") self.assertEqual(LilyPond.from_Note(Note('C##'), standalone=False), "cisis'") self.assertEqual(LilyPond.from_Note(Note('Cb'), standalone=False), "ces'") self.assertEqual(LilyPond.from_Note(Note('Cbb'), standalone=False), "ceses'") self.assertEqual(LilyPond.from_Note(Note('C', 0), standalone=False), 'c,,,') self.assertEqual(LilyPond.from_Note(Note('C', 1), standalone=False), 'c,,') self.assertEqual(LilyPond.from_Note(Note('C', 2), standalone=False), 'c,') self.assertEqual(LilyPond.from_Note(Note('C', 3), standalone=False), 'c' ) self.assertEqual(LilyPond.from_Note(Note('C', 4), standalone=False), "c'") self.assertEqual(LilyPond.from_Note(Note('C', 5), standalone=False), "c''") self.assertEqual(LilyPond.from_Note(Note('C', 6), standalone=False), "c'''") self.assertEqual(LilyPond.from_Note(Note('C', 7), standalone=False), "c''''") def test_from_NoteContainer(self): self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), standalone=False), "c'") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 4, standalone=False), "c'4") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']), standalone=False), "<c' e'>") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']), 4, standalone=False), "<c' e'>4") # issue #37 self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16, standalone=False), "c'16") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16.0, standalone=False), "c'16") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(16), standalone=False), "c'16.") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.25, standalone=False), "c'\\longa") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.5, standalone=False), "c'\\breve") def test_from_Bar(self): self.assertEqual(LilyPond.from_Bar(self.commonbar), "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }") self.assertEqual(LilyPond.from_Bar(self.ebar), "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }") self.assertEqual(LilyPond.from_Bar(self.fbar), "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }") def test_from_Track(self): self.assertEqual(LilyPond.from_Track(self.track1), "{ { c'4 e'4 g'4 b'4 } }") self.assertEqual(LilyPond.from_Track(self.track2), "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }" ) def test_from_Composition(self): self.assertEqual(LilyPond.from_Composition(self.composition1), '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }' ) self.assertEqual(LilyPond.from_Composition(self.composition2), '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } } { { c\'4 e\'4 g\'4 b\'4 } { \\key e \\major c\'4 e\'4 g\'4 b\'4 } }' ) def test_from_Suite(self): LilyPond.from_Suite(None) def test_dotted_notes(self): self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8), standalone=False), "c'8.") self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(4, 2), standalone=False), "c'4..") def test_to_pdf(self): self.assert_(LilyPond.to_pdf('{ %s }' % LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8)), 'pdftest first test')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))
def test_determine_progression(self): b = Bar() b + ["C", "E", "G"] b + ["F", "A", "C"] self.assertEqual([[0.0, ["I"]], [0.25, ["IV"]]], b.determine_progression(True))
class test_Bar(unittest.TestCase): def setUp(self): self.b = Bar('C', (4, 4)) self.c = Bar('E', (2, 2)) self.meterless = Bar('C', (0, 0)) def test_place_notes_types(self): self.assertEqual(True, self.meterless + NoteContainer(['A', 'C'])) self.assertEqual(True, self.meterless + 'A') self.assertEqual(True, self.meterless + Note('A')) self.assertEqual(True, self.meterless + ['A', 'B']) self.assertEqual(True, self.meterless + [Note('A'), Note('B')]) def test_get_range(self): self.b + NoteContainer(['C', 'E']) self.assertEqual((Note('C'), Note('E')), self.b.get_range()) def test_set_item(self): b = Bar() b + ['A', 'C', 'E'] c = Bar() c + ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = NoteContainer(['A', 'C', 'E']) self.assertEqual(b, c) c[0] = ['A', 'C', 'E'] self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + NoteContainer(['C', 'E']) self.assertEqual(b, c) c[0] = Note('A') c[0] = c[0][2] + 'C' c[0] = c[0][2] + 'E' self.assertEqual(b, c) def test_key(self): self.assertEqual(self.b.key, Note('C')) self.assertEqual(self.c.key, Note('E')) def test_transpose(self): b = Bar() c = Bar() b + ['C', 'E', 'G'] c + ['E', 'G#', 'B'] b + ['F', 'A', 'C'] c + ['A', 'C#', 'E'] b.transpose('3', True) self.assertEqual(b, c) b.transpose('3', False) b.transpose('3') self.assertEqual(b, c) def test_augment(self): b = Bar() c = Bar() d = Bar() b + 'A' c + 'A#' d + 'A##' b.augment() self.assertEqual(b, c) b.augment() self.assertEqual(b, d) c.augment() self.assertEqual(c, d) def test_diminish(self): b = Bar() c = Bar() b + 'A' c + 'Ab' b.diminish() self.assertEqual(b, c) def test_to_minor(self): b = Bar() c = Bar() b + 'C' c + 'A' b.to_minor() self.assertEqual(b, c) def test_to_major(self): b = Bar() c = Bar() b + 'C' c + 'A' c.to_major() self.assertEqual(b, c) def test_get_note_names(self): b = Bar() b + 'C' b + 'A' self.assertEqual(['C', 'A'], b.get_note_names()) def test_determine_chords(self): b = Bar() b + ['C', 'E', 'G'] b + ['F', 'A', 'C'] self.assertEqual([[0.0, ['C major triad']], [0.25, ['F major triad']]], b.determine_chords()) def test_determine_progression(self): b = Bar() b + ['C', 'E', 'G'] b + ['F', 'A', 'C'] self.assertEqual([[0.0, ['I']], [0.25, ['IV']]], b.determine_progression(True))
def test_determine_chords(self): b = Bar() b + ['C', 'E', 'G'] b + ['F', 'A', 'C'] self.assertEqual([[0.0, ['C major triad']], [0.25, ['F major triad']]], b.determine_chords())
class test_LilyPond(unittest.TestCase): def setUp(self): self.commonbar = Bar() self.ebar = Bar('E', (4, 4)) self.fbar = Bar('F', (6, 8)) self.tbar = Bar('C', (4, 4)) self.mbar = Bar('C', (4, 4)) for y in [self.commonbar, self.ebar, self.fbar]: map(lambda x: y + x, ['C', 'E', 'G', 'B']) map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [ 'C', 'E', 'G', 'B', 'C', 'E', ]) map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E']) map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C']) self.track1 = Track() self.track1 + self.commonbar self.track2 = Track() self.track2 + self.commonbar self.track2 + self.ebar self.composition1 = Composition() self.composition1.add_track(self.track1) self.composition2 = Composition() self.composition2.add_track(self.track1) self.composition2.add_track(self.track2) def test_from_Note(self): self.assertEqual(LilyPond.from_Note(Note('C'), standalone=False), "c'") self.assertEqual(LilyPond.from_Note(Note('C#'), standalone=False), "cis'") self.assertEqual(LilyPond.from_Note(Note('C##'), standalone=False), "cisis'") self.assertEqual(LilyPond.from_Note(Note('Cb'), standalone=False), "ces'") self.assertEqual(LilyPond.from_Note(Note('Cbb'), standalone=False), "ceses'") self.assertEqual(LilyPond.from_Note(Note('C', 0), standalone=False), 'c,,,') self.assertEqual(LilyPond.from_Note(Note('C', 1), standalone=False), 'c,,') self.assertEqual(LilyPond.from_Note(Note('C', 2), standalone=False), 'c,') self.assertEqual(LilyPond.from_Note(Note('C', 3), standalone=False), 'c') self.assertEqual(LilyPond.from_Note(Note('C', 4), standalone=False), "c'") self.assertEqual(LilyPond.from_Note(Note('C', 5), standalone=False), "c''") self.assertEqual(LilyPond.from_Note(Note('C', 6), standalone=False), "c'''") self.assertEqual(LilyPond.from_Note(Note('C', 7), standalone=False), "c''''") def test_from_NoteContainer(self): self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), standalone=False), "c'") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), 4, standalone=False), "c'4") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer(['C', 'E']), standalone=False), "<c' e'>") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer(['C', 'E']), 4, standalone=False), "<c' e'>4") # issue #37 self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), 16, standalone=False), "c'16") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), 16.0, standalone=False), "c'16") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(16), standalone=False), "c'16.") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), 0.25, standalone=False), "c'\\longa") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), 0.5, standalone=False), "c'\\breve") def test_from_Bar(self): self.assertEqual(LilyPond.from_Bar(self.commonbar), "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }") self.assertEqual(LilyPond.from_Bar(self.ebar), "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }") self.assertEqual(LilyPond.from_Bar(self.fbar), "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }") def test_from_Track(self): self.assertEqual(LilyPond.from_Track(self.track1), "{ { c'4 e'4 g'4 b'4 } }") self.assertEqual( LilyPond.from_Track(self.track2), "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }") def test_from_Composition(self): self.assertEqual( LilyPond.from_Composition(self.composition1), '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }' ) self.assertEqual( LilyPond.from_Composition(self.composition2), '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } } { { c\'4 e\'4 g\'4 b\'4 } { \\key e \\major c\'4 e\'4 g\'4 b\'4 } }' ) def test_from_Suite(self): LilyPond.from_Suite(None) def test_dotted_notes(self): self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8), standalone=False), "c'8.") self.assertEqual( LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(4, 2), standalone=False), "c'4..") def test_to_pdf(self): self.assert_( LilyPond.to_pdf( '{ %s }' % LilyPond.from_NoteContainer(NoteContainer('C'), value.dots(8)), 'pdftest first test')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2')) self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))
class test_Bar(unittest.TestCase): def setUp(self): self.b = Bar('C', (4, 4)) self.c = Bar('E', (2, 2)) self.meterless = Bar('C', (0, 0)) def test_place_notes_types(self): self.assertEqual(True, self.meterless + NoteContainer(["A", "C"])) self.assertEqual(True, self.meterless + "A") self.assertEqual(True, self.meterless + Note("A")) self.assertEqual(True, self.meterless + ["A", "B"]) self.assertEqual(True, self.meterless + [Note("A"), Note("B")]) def test_get_range(self): self.b + NoteContainer(["C", "E"]) self.assertEqual((Note("C"), Note("E")), self.b.get_range()) def test_set_item(self): b = Bar() b + ["A", "C", "E"] c = Bar() c + ["A", "C", "E"] self.assertEqual(b, c) c[0] = NoteContainer(["A", "C", "E"]) self.assertEqual(b, c) c[0] = ["A", "C", "E"] self.assertEqual(b, c) c[0] = Note("A") c[0] = c[0][2] + NoteContainer(["C", "E"]) self.assertEqual(b, c) c[0] = Note("A") c[0] = c[0][2] + "C" c[0] = c[0][2] + "E" self.assertEqual(b, c) def test_key(self): self.assertEqual(self.b.key, Note("C")) self.assertEqual(self.c.key, Note("E")) def test_transpose(self): b = Bar() c= Bar() b + ["C", "E", "G"] c + ["E", "G#", "B"] b + ["F", "A", "C"] c + ["A", "C#", "E"] b.transpose("3", True) self.assertEqual(b, c) b.transpose("3", False) b.transpose("3") self.assertEqual(b, c) def test_augment(self): b = Bar() c = Bar() d = Bar() b + "A" c + "A#" d + "A##" b.augment() self.assertEqual(b, c) b.augment() self.assertEqual(b, d) c.augment() self.assertEqual(c, d) def test_diminish(self): b = Bar() c = Bar() b + "A" c + "Ab" b.diminish() self.assertEqual(b, c) def test_to_minor(self): b = Bar() c = Bar() b + "C" c + "A" b.to_minor() self.assertEqual(b, c) def test_to_major(self): b = Bar() c = Bar() b + "C" c + "A" c.to_major() self.assertEqual(b, c) def test_get_note_names(self): b = Bar() b + "C" b + "A" self.assertEqual(["C", "A"], b.get_note_names()) def test_determine_chords(self): b = Bar() b + ["C", "E", "G"] b + ["F", "A", "C"] self.assertEqual([[0.0, ["C major triad"]], [0.25, ["F major triad"]]], b.determine_chords()) def test_determine_progression(self): b = Bar() b + ["C", "E", "G"] b + ["F", "A", "C"] self.assertEqual([[0.0, ["I"]], [0.25, ["IV"]]], b.determine_progression(True))
def setUp(self): self.b = Bar('C', (4, 4)) self.c = Bar('E', (2, 2)) self.meterless = Bar('C', (0, 0))
def test_determine_progression(self): b = Bar() b + ['C', 'E', 'G'] b + ['F', 'A', 'C'] self.assertEqual([[0.0, ['I']], [0.25, ['IV']]], b.determine_progression(True))
def test_get_note_names(self): b = Bar() b + 'C' b + 'A' self.assertEqual(['C', 'A'], b.get_note_names())
def test_determine_chords(self): b = Bar() b + ["C", "E", "G"] b + ["F", "A", "C"] self.assertEqual([[0.0, ["C major triad"]], [0.25, ["F major triad"]]], b.determine_chords())
def test_get_note_names(self): b = Bar() b + "C" b + "A" self.assertEqual(["C", "A"], b.get_note_names())
class test_tied_notes(unittest.TestCase): def setUp(self): self.bar1 = Bar() self.bar2 = Bar() def test_tie_note(self): n = Note('G') m = Note('G', tie_note=n) self.bar1.place_notes('C', 2) self.bar1.place_notes('G', 4) self.bar1.place_notes(n, 4) self.bar2.place_notes(m, 4) self.bar2.place_notes('C', 2) self.assertEqual(m.tie_note(), n) self.assertEqual(n.next_note(), m) self.assertTrue(n.is_tied()) self.assertTrue(m.is_last_tied()) def test_tie_together(self): n = Note('G') m = Note('G') m.tie_together(n) self.bar1.place_notes('C', 2) self.bar1.place_notes('G', 4) self.bar1.place_notes(n, 4) self.bar2.place_notes(m, 4) self.bar2.place_notes('C', 2) self.assertEqual(m.tie_note(), n) self.assertEqual(n.next_note(), m) self.assertTrue(n.is_tied()) self.assertTrue(m.is_last_tied()) def test_not_tieable(self): def different_note(): n = Note('G') m = Note('C') m.tie_together(n) def different_channel(): n = Note('G') m = Note('G', dynamics={'channel': n.channel+1}) m.tie_together(n) self.assertRaises(NotesNotTieable, different_note) self.assertRaises(NotesNotTieable, different_channel)
def setUp(self): self.bar1 = Bar() self.bar2 = Bar()
def test_augment(self): b = Bar() c = Bar() d = Bar() b + 'A' c + 'A#' d + 'A##' b.augment() self.assertEqual(b, c) b.augment() self.assertEqual(b, d) c.augment() self.assertEqual(c, d)
for x in range(len(composition.tracks)): t += [MidiTrack(bpm)] m.tracks = t while repeat >= 0: for i in range(len(composition.tracks)): m.tracks[i].play_Track(composition.tracks[i]) repeat -= 1 return m.write_file(file, verbose) if __name__ == '__main__': from mingus.containers.NoteContainer import NoteContainer from mingus.containers.Bar import Bar from mingus.containers.Track import Track from mingus.containers.Instrument import MidiInstrument b = Bar() b2 = Bar('Ab', (3, 4)) n = NoteContainer(['A', 'C', 'E']) t = Track() b + n b + [] b + n b + n b2 + n b2 + n b2 + [] t + b t + b m = MidiInstrument() m.instrument_nr = 13 t.instrument = m
def generate_bar(previews_note, bar, key, mode, progression, progression_list, nb_p, pattern_index): if mode == 'mixolydien' : if progression == 'IV' : key = intervals.fourth(key, key) elif progression == 'V' : key = intervals.fifth(key, key) b = Bar(key, (4, 4)) position_note = 0 already_used=[] list_note = [] for bar_note in bar : if position_note not in already_used : is_chord = chord_length(bar_note, bar, position_note) if is_chord[2] : note_list = [] # c est un accord for p_note in bar[is_chord[0]:is_chord[1]+1] : note_str = get_note(p_note, key) note = Note(note_str, p_note[5]) if previews_note is not None: if p_note[4]=='+': if int(note) < previews_note : note.octave_up() elif p_note[4]=='-': if int(note) > previews_note : note.octave_down() current_progression = progression_list[0][nb_p] note = change_note_if_needed(bar_note[2], note, pattern_index, current_progression, bar_note, key) previews_note = int(note) #appeler best_note la aussi note_list.append(note) list_note.append(note) for n in range(is_chord[0], is_chord[1]+1): already_used.append(n) b.place_notes(note_list, bar_note[1]) else : note_str = get_note(bar_note, key) note = Note(note_str, bar_note[5]) if previews_note is not None: if bar_note[4]=='+': if int(note) < previews_note : note.octave_up() elif bar_note[4]=='-': if int(note) > previews_note : note.octave_down() # la un faut appeler le truc pour modifier la note current_progression = progression_list[0][nb_p] note = change_note_if_needed(bar_note[2], note, pattern_index, current_progression, bar_note, key) previews_note = int(note) list_note.append(note) b.place_notes(note, bar_note[1]) already_used.append(position_note) position_note+=1 return (b, previews_note, list_note)