简体   繁体   English

如何在music21中制作这两个小节的乐谱

[英]How to make music sheet of these two measures in music21

I have two adjacent measures here:我在这里有两个相邻的措施:

在此处输入图像描述

My problem is how to make this piece of music with music21 python package.我的问题是如何用 music21 python package 制作这首音乐。

from music21 import *
s = stream.Stream();
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
c = note.Note('E4',quarterLength = 8);
s.insertIntoNoteOrChord(0, c);
s.show('lily.pdf')

The error coming was即将出现的错误是

s.insertIntoNoteOrChord(0, c); s.insertIntoNoteOrChord(0, c); music21.exceptions21.StreamException: more than one element found at the specified offset music21.exceptions21.StreamException:在指定偏移处发现多个元素

How can I rectify the error?我该如何纠正错误?

Edit:编辑:

from music21 import note,stream
s = stream.Measure();
c = note.Note('E4',quarterLength = 8);
s.insert(0, c)
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);
n = note.Note('C5',quarterLength = 0.5);
s.append(n);
n = note.Note('A4',quarterLength = 0.5);
s.append(n);

s.show('lily.pdf')

is giving output as正在给 output 作为

在此处输入图像描述

Your command s.insertIntoNoteOrChord(0, c);你的命令s.insertIntoNoteOrChord(0, c); is unnecessary.是不必要的。 You're trying to insert the tied whole notes into the first measure, not into a note or chord.您正在尝试将捆绑的整个音符插入第一小节,而不是插入音符或和弦。 You should just s.insert(0, c) .你应该只是s.insert(0, c)

Also, there are ways to batch insert, see the docs for Stream.insert() .此外,还有批量插入的方法,请参阅Stream.insert()的文档。

EDIT -- for example:编辑——例如:

from music21 import note,stream
s = stream.Stream()  # sorry, your instinct to use a stream was probably good

n = note.Note('C5',quarterLength = 0.5)
s.append(n)
n = note.Note('A4',quarterLength = 0.5)
s.append(n)
n = note.Note('C5',quarterLength = 0.5)
s.append(n)
n = note.Note('A4',quarterLength = 0.5)
s.append(n)
n = note.Note('C5',quarterLength = 0.5)
s.append(n)
n = note.Note('A4',quarterLength = 0.5)
s.append(n)
n = note.Note('C5',quarterLength = 0.5)
s.append(n)
n = note.Note('A4',quarterLength = 0.5)
s.append(n)
c = note.Note('E4',quarterLength = 8)
s.insert(0, c)
out1 = s.makeVoices()
out2 = out1.makeNotation()
out2.show('lily.pdf')

在此处输入图像描述

Much better with .show('musicxml.pdf') :使用.show('musicxml.pdf')了:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM