如何替换音乐中的音高21分数

时间:2017-01-19 07:09:17

标签: music21

我正在尝试用另一个音高替换乐谱中的一个音高(最终目标是生成和声部分)。

var https = require('https');
    exports.getFbData = function(accessToken, apiPath, callback) {
        var options = {
            host: 'graph.facebook.com',
            port: 443,
            path: apiPath + '?access_token=' + accessToken, //apiPath example: '/me/friends'
            method: 'GET'
        };

        console.log("\n\n options:::", options);
        var buffer = ''; //this buffer will be populated with the chunks of the data received from facebook
        var request = https.get(options, function(result){
            result.setEncoding('utf8');
            result.on('data', function(chunk){
                buffer += chunk;
            });

            result.on('end', function(){
                callback(buffer);
            });
        });

        request.on('error', function(e){
            console.log('error from facebook.getFbData: ' + e.message)
        });

        request.end();
    }

我该怎么做呢?

更新:我发布了我的“test.mid”文件here

1 个答案:

答案 0 :(得分:4)

我刚检查了transpose的代码。只需通过inPlace=True,它就像魔法一样。希望它有所帮助!

from music21 import *
score = converter.parse('test.mid')
p0 = score.parts[0].pitches[0]
print p0
p0.transpose(1, inPlace=True)
print score.parts[0].pitches[0]

对于那些想要一个完整的工作示例而不加载现有midi文件的人:

from music21 import stream, instrument, meter
from music21.note import Note
from music21.stream import Score

# Creating the example score
n = Note("A2", type='quarter')
part = stream.Part()
measure = stream.Measure()
measure.append(n)
part.append(measure)
score = Score()
score.append(part)

p0 = score.parts[0].pitches[0]
print p0
p0.transpose(1, inPlace=True)
print score.parts[0].pitches[0]