Beispiel #1
0
 def test_diminish(self):
     b = Bar()
     c = Bar()
     b + 'A'
     c + 'Ab'
     b.diminish()
     self.assertEqual(b, c)
Beispiel #2
0
    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)
Beispiel #3
0
 def test_to_major(self):
     b = Bar()
     c = Bar()
     b + 'C'
     c + 'A'
     c.to_major()
     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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
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
Beispiel #9
0
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
Beispiel #10
0
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
Beispiel #11
0
    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))
Beispiel #12
0
    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
Beispiel #13
0
 def setUp(self):
     self.b = Bar('C', (4, 4))
     self.c = Bar('E', (2, 2))
     self.meterless = Bar('C', (0, 0))
Beispiel #14
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))
Beispiel #15
0
 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())
Beispiel #16
0
 def test_get_note_names(self):
     b = Bar()
     b + 'C'
     b + 'A'
     self.assertEqual(['C', 'A'], b.get_note_names())