예제 #1
0
def get_music(a, b, key='C', mode='major'):
    midi_out = StringIO()

    scale = build_scale(key, mode, octaves=1)
    matcher = SequenceMatcher(None, a, b)

    tone = key.lower()
    melodies = [tone]
    for tag, i1, i2, j1, j2 in matcher.get_opcodes():
        next_note = None
        if tag == 'replace':
            next_note = 'r'
        elif tag == 'equal':
            next_note = tone
        elif tag == 'delete':
            tone = tone_down(tone, scale)
            next_note = tone
        elif tag == 'insert':
            tone = tone_up(tone, scale)
            next_note = tone
        melodies += [next_note] * ((i2 - i1) or 1)
    s = SMF([parse(" ".join(melodies))])

    s.write(midi_out)
    return midi_out
예제 #2
0
def get_music(a, b, key='C', mode='major'):
    midi_out = StringIO()

    scale = build_scale(key, mode, octaves=1)
    matcher = SequenceMatcher(None, a, b)

    tone = key.lower()
    melodies = [tone]
    for tag, i1, i2, j1, j2 in matcher.get_opcodes():
        next_note = None
        if tag == 'replace':
            next_note = 'r'
        elif tag == 'equal':
            next_note = tone
        elif tag == 'delete':
            tone = tone_down(tone, scale)
            next_note = tone
        elif tag == 'insert':
            tone = tone_up(tone, scale)
            next_note = tone
        melodies += [next_note] * ((i2 - i1) or 1)
    s = SMF([parse(" ".join(melodies))])

    s.write(midi_out)
    return midi_out
예제 #3
0
    def play_music(self, x, y):
        '''
        Generate sounds from data to be used for each coordinate.
        x and y are the coordinates of any image point.
        '''
        scale = build_scale('C', mode='major', octaves=1)
        notes = note_number(self.data, scale)
        note = notes[y,x]

        melody = parse(note_name(note, scale))
        midi_out = StringIO()
        write('Oc.midi', [melody])

        os.system('fluidsynth --audio-driver=alsa /usr/share/sounds/sf2/FluidR3_GM.sf2 Oc.midi')
예제 #4
0
    def play_music(self, x, y):
        '''
        Generate sounds from data to be used for each coordinate.
        x and y are the coordinates of any image point.
        '''
        scale = build_scale('C', mode='major', octaves=1)
        notes = note_number(self.data, scale)
        note = notes[y,x]

        melody = parse(note_name(note, scale))
        midi_out = StringIO()
        write('Oc.midi', [melody])

        pygame.mixer.init()

        music = pygame.mixer.Sound('Oc.midi')
        pygame.mixer.music.load('Oc.midi')
        pygame.mixer.music.play()
예제 #5
0
def test_build_scale_major():
    scale = build_scale('C', 'major', 1)
    assert scale == 'c d e f g a b'.split()
예제 #6
0
def test_build_note_name():
    scale = build_scale('C', 'major', 1)
    notes = note_number([1, 2, 3, 4, np.nan], scale)
    assert [note_name(x, scale) for x in notes] == ['c', 'e', 'g', 'b', 'r']
예제 #7
0
def test_note_number():
    scale = build_scale('C', 'major', 1)
    assert all(note_number([1, 2, 3, 4], scale) == [0, 2, 4, 6])
예제 #8
0
def test_build_scale_pentatonic_two_octaves():
    scale = build_scale('D', 'pentatonic', 2)
    assert scale == ['d', 'e', 'f#', 'a', 'b', "d'", "e'", "f#'", "a'", "b'"]
예제 #9
0
def test_build_scale_pentatonic():
    scale = build_scale('C', 'pentatonic', 1)
    assert scale == ['c', 'd', 'e', 'g', 'a']
예제 #10
0
def test_build_scale_minor():
    scale = build_scale('A', 'minor', 1)
    assert scale == 'a b c d e f g'.split()
예제 #11
0
def test_build_scale_major():
    scale = build_scale('C', 'major', 1)
    assert scale == 'c d e f g a b'.split()
예제 #12
0
def test_build_note_name():
    scale = build_scale('C', 'major', 1)
    notes = note_number([1, 2, 3, 4, np.nan], scale)
    assert [note_name(x, scale) for x in notes] == ['c', 'e', 'g', 'b', 'r']
예제 #13
0
def test_note_number():
    scale = build_scale('C', 'major', 1)
    assert all(note_number([1, 2, 3, 4], scale) == [0, 2, 4, 6])
예제 #14
0
def test_build_scale_pentatonic_two_octaves():
    scale = build_scale('D', 'pentatonic', 2)
    assert scale == ['d', 'e', 'f#', 'a', 'b', "d'", "e'", "f#'", "a'", "b'"]
예제 #15
0
def test_build_scale_pentatonic():
    scale = build_scale('C', 'pentatonic', 1)
    assert scale == ['c', 'd', 'e', 'g', 'a']
예제 #16
0
def test_build_scale_minor():
    scale = build_scale('A', 'minor', 1)
    assert scale == 'a b c d e f g'.split()