小编Ner*_*zid的帖子

Music21 获取所有带持续时间的音符

我试图获取所有带有持续时间(度量)的笔记。

from music21 import *

allBach = corpus.search('bach')

x = allBach[0]
p = x.parse()

partStream = p.parts.stream()

for n in p.pitches:
    print "Pitch: " + str(n)

print "*************"

for n in p.notes:
    print "Note: " + str(n)
#print "Duration " + str(x.parse().duration)
Run Code Online (Sandbox Code Playgroud)

上面的代码产生以下输出

Pitch: E5
Pitch: G5
Pitch: A5
Pitch: D5
Pitch: F#5
Pitch: A5
Pitch: D5
Pitch: F#5
Pitch: A5
Pitch: C6
Pitch: G4
Pitch: B4
Pitch: D5
*************
Run Code Online (Sandbox Code Playgroud)

我知道音高只是带有八度音程的音符的名称,但我试图通过其持续时间(小节)获得音符值。

另外,如果你能帮我解决这个问题,你能不能解释一下为什么 p.notes 什么都不返回。谢谢你。

python machine-learning python-2.7 music21 music-notation

6
推荐指数
1
解决办法
2149
查看次数

JavaParser 不更新源文件

我正在使用JavaParser并关注其 Wiki。问题是即使我更改了方法的名称并向其添加了参数,文件也不会更新。换句话说,不会保存更改。当我System.out.println更改时CompilationUnit,它会打印更改,但这些更改根本不会影响源文件。

有什么类似的东西CompilationUnit.update()还是我错过了什么?

我从 Wiki 中使用的示例:

    files_list = FilePicker.chooseAndGetJavaFiles();

    if (files_list == null || files_list.isEmpty()) {
        Errors.showError(Errors.COMMENT_GENERATOR_FILELIST_NULL_OR_EMPTY);
    } else {

        CompilationUnit cu = null;
        FileInputStream in = new FileInputStream(files_list.get(0));
        try {
            cu = JavaParser.parse(in);
        } catch (ParseException ex) {
            Logger.getLogger(CommentGenerator.class.getName()).log(Level.SEVERE, null, ex);
        } finally{
            in.close();
        }
        new MethodChangerVisitor().visit(cu,null);

        System.out.println(cu.toString());
    }
}

private static class MethodChangerVisitor extends VoidVisitorAdapter{

    @Override
    public void visit(MethodDeclaration n, Object arg) {
       // change the name of the method …
Run Code Online (Sandbox Code Playgroud)

java visitor abstract-syntax-tree compilationunit javaparser

1
推荐指数
1
解决办法
1539
查看次数