java的part方法_Java Part.empty方法代码示例

import jm.music.data.Part; //导入方法依赖的package包/类

/**

* packs all of the phrases within this part into a single phrase

*

*/

public static void consolidate(Part p) {

Phrase [] phr = p.getPhraseArray();

if(phr.length <2)

return;

// the new phrase has the start time of the earliest one

Phrase nphr = new Phrase(phr[0].getStartTime());

Note n;

boolean finished = false;

double prevsst = phr[0].getStartTime();

while(!finished) {

double sst = Double.POSITIVE_INFINITY; // smallest start time

// a temporary phrase (pointer to the one in the array

Phrase tphr = null;

//find the phrase with the smallest start time

for(int i=0;i

if (phr[i].getSize()>0 && phr[i].getStartTime()

sst = phr[i].getStartTime();

tphr = phr[i];

}

}

if(tphr == null) {finished = true;break;}

//get a note out of that phrase and, if it is not a rest,

// put it into the new phrase, adjusting the rhythmValue

// of the previous note accordingly

n = tphr.getNote(0);

if(!n.isRest()) {

if(nphr.getSize()>0){ // if it is not the first note

nphr.getNote(nphr.getSize()-1).setRhythmValue(((int)((sst-prevsst)*100000 + 0.5))/100000.0);

} else {// if it is the first note to go in, set the startime

nphr.setStartTime(sst);

}

nphr.addNote(n);

}

// adjust the start time and remove the note

tphr.setStartTime(((int)((sst+

n.getRhythmValue())*100000 + 0.5))/100000.0);

tphr.removeNote(0);

prevsst = sst;

}

p.empty();

p.addPhrase(nphr);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值