Пример #1
0
class test_Instrument(unittest.TestCase):
    def setUp(self):
        self.i = Instrument()
        self.p = Piano()
        self.g = Guitar()
        self.notes = NoteContainer(["A", "B", "C", "D", "E"])
        self.noteslow = NoteContainer(["C-0", "D-0", "E-0"])
        self.noteshigh = NoteContainer(
            ["A-12", "B-12", "C-12", "D-12", "E-12"])

    def test_note_in_range(self):
        for x in self.notes:
            self.assertTrue(self.i.note_in_range(x))
            self.assertTrue(self.p.note_in_range(x))
            self.assertTrue(self.g.note_in_range(x))
        for x in self.noteslow + self.noteshigh:
            self.assertEqual(
                False,
                self.p.note_in_range(x),
                "%s should not be able to be played by a Piano" % x,
            )
            self.assertEqual(
                False,
                self.g.note_in_range(x),
                "%s should not be able to be played by a Guitar" % x,
            )

    def test_can_play_notes(self):
        self.assertTrue(self.i.can_play_notes(self.notes))
        self.assertTrue(self.p.can_play_notes(self.notes))
        self.assertTrue(self.g.can_play_notes(self.notes))
        self.assertEqual(False, self.p.can_play_notes(self.noteslow))
        self.assertEqual(False, self.g.can_play_notes(self.noteslow))
        self.assertEqual(False, self.p.can_play_notes(self.noteshigh))
        self.assertEqual(False, self.g.can_play_notes(self.noteshigh))
        self.assertEqual(
            False,
            self.g.can_play_notes(
                NoteContainer([
                    "A",
                    "B",
                    "C",
                    "D",
                    "E",
                    "F",
                    "G",
                ])),
        )
Пример #2
0
class test_Instrument(unittest.TestCase):
    def setUp(self):
        self.i = Instrument()
        self.p = Piano()
        self.g = Guitar()
        self.notes = NoteContainer(['A', 'B', 'C', 'D', 'E'])
        self.noteslow = NoteContainer(['C-0', 'D-0', 'E-0'])
        self.noteshigh = NoteContainer(
            ['A-12', 'B-12', 'C-12', 'D-12', 'E-12'])

    def test_note_in_range(self):
        for x in self.notes:
            self.assert_(self.i.note_in_range(x))
            self.assert_(self.p.note_in_range(x))
            self.assert_(self.g.note_in_range(x))
        for x in self.noteslow + self.noteshigh:
            self.assertEqual(
                False, self.p.note_in_range(x),
                '%s should not be able to be played by a Piano' % x)
            self.assertEqual(
                False, self.g.note_in_range(x),
                '%s should not be able to be played by a Guitar' % x)

    def test_can_play_notes(self):
        self.assert_(self.i.can_play_notes(self.notes))
        self.assert_(self.p.can_play_notes(self.notes))
        self.assert_(self.g.can_play_notes(self.notes))
        self.assertEqual(False, self.p.can_play_notes(self.noteslow))
        self.assertEqual(False, self.g.can_play_notes(self.noteslow))
        self.assertEqual(False, self.p.can_play_notes(self.noteshigh))
        self.assertEqual(False, self.g.can_play_notes(self.noteshigh))
        self.assertEqual(
            False,
            self.g.can_play_notes(
                NoteContainer([
                    'A',
                    'B',
                    'C',
                    'D',
                    'E',
                    'F',
                    'G',
                ])))
Пример #3
0
class test_Instrument(unittest.TestCase):

    def setUp(self):
        self.i = Instrument()
        self.p = Piano()
        self.g = Guitar()
        self.notes = NoteContainer(['A', 'B', 'C', 'D', 'E'])
        self.noteslow = NoteContainer(['C-0', 'D-0', 'E-0'])
        self.noteshigh = NoteContainer(['A-12', 'B-12', 'C-12', 'D-12', 'E-12'])

    def test_note_in_range(self):
        for x in self.notes:
            self.assert_(self.i.note_in_range(x))
            self.assert_(self.p.note_in_range(x))
            self.assert_(self.g.note_in_range(x))
        for x in self.noteslow + self.noteshigh:
            self.assertEqual(False, self.p.note_in_range(x),
                             '%s should not be able to be played by a Piano'
                              % x)
            self.assertEqual(False, self.g.note_in_range(x),
                             '%s should not be able to be played by a Guitar'
                              % x)

    def test_can_play_notes(self):
        self.assert_(self.i.can_play_notes(self.notes))
        self.assert_(self.p.can_play_notes(self.notes))
        self.assert_(self.g.can_play_notes(self.notes))
        self.assertEqual(False, self.p.can_play_notes(self.noteslow))
        self.assertEqual(False, self.g.can_play_notes(self.noteslow))
        self.assertEqual(False, self.p.can_play_notes(self.noteshigh))
        self.assertEqual(False, self.g.can_play_notes(self.noteshigh))
        self.assertEqual(False, self.g.can_play_notes(NoteContainer([
            'A',
            'B',
            'C',
            'D',
            'E',
            'F',
            'G',
            ])))
Пример #4
0
c.augment()  #升半音
c.diminish()  #降半音
c.remove_redundant_accidentals()  #清理多余升降号(只能成对清理,烂)

#谱容器
from mingus.containers import NoteContainer
#创建谱容器对象(继承列表,完全可以按列表操作,不用看下面的)
n = NoteContainer(['A-3', 'C-5', 'B-4'])
n.add_note('F-1')  # 0位加音
n.remove_note('B', 4)  #删音
n.empty()  #清空

#乐器音色
from mingus.containers.instrument import Instrument, Piano, Guitar
#创建乐器对象
i = Instrument()
i.range  #乐器音域
i.set_range((Note('C-2'), Note('E-4')))  #设定音域
i.note_in_range('F-4')  #判断音是否在乐器音域内
#音轨
from mingus.containers import Track
t = Track(i)  #乐器放入音轨容器

#MIDI音乐播放(安装困难)
#from mingus.midi import fluidsynth
#fluidsynth.init("soundfont.SF2")
#fluidsynth.play_Note( Note('C-5') )

from mingus.midi import MidiFileOut
MidiFileOut.write_NoteContainer('test.mid', n)