Skip to content

Commit

Permalink
1. 新增XML 文件中节奏(BPM)的设置
Browse files Browse the repository at this point in the history
2. 新增伴奏音量比主奏略低的功能 (原播放 jar 包从 maven 依赖中移除,使用自己编译的扩展包[jlayer-extend-1.0.2.0-SNAPSHOT.jar],在 lib 目录下,以支持音量调整)
3. 新增生成 XML 的功能 (具体步骤见Readme的教程)
4. 上传了一些歌曲的 xml 文件
5. 优化部分代码逻辑
6. 修复了一些已知问题
  • Loading branch information
gulihua committed Feb 11, 2023
1 parent fdc4be1 commit d58e43f
Show file tree
Hide file tree
Showing 32 changed files with 59,685 additions and 57 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 2.2.0 版本
1. 新增XML 文件中节奏(BPM)的设置
2. 新增伴奏音量比主奏略低的功能 (原播放 jar 包从 maven 依赖中移除,使用自己编译的扩展包[jlayer-extend-1.0.2.0-SNAPSHOT.jar],在 lib 目录下,以支持音量调整)
3. 新增生成 XML 的功能 (具体步骤见下面的教程)
4. 上传了一些歌曲的 xml 文件
5. 优化部分代码逻辑
6. 修复了一些已知问题

### 生成 XML 文件步骤
1. 在网上搜索有关歌曲的 midi 简谱,比如midishow网站(https://www.midishow.com/)
2. 使用 midi 编辑器打开midi 文件,比如 Logic Pro,Tune Flow(https://tuneflow.com/), Tune Flow在线也可以编辑,也有多个平台的客户端
3. 将 midi 文件删除伴奏轨道,只剩一个主奏轨道,如图(tuneFlow截图 1~2.png),然后导出 midi
4. 然后将主奏文件使用类(cn.jianwoo.genXml.GenStart)生成 xml 文件
5. 导出伴奏 xml 文件的方法同理
6. 导出后根据BPM,重置 xml 中的header.audio.midi.bpm节点

#### tuneFlow截图 1
![tuneFlow截图 1](tuneFlow截图 1.png)
#### tuneFlow截图 2
![tuneFlow截图 2](tuneFlow截图 2.png)
## 2.1.0 版本
1. 新增暂停/播放按钮
2. 新增进度条,可拖动
Expand Down
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.5.4</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.googlecode.soundlibs</groupId>-->
<!-- <artifactId>mp3spi</artifactId>-->
<!-- <version>1.9.5.4</version>-->
<!-- </dependency>-->

<!-- 如果需要解码播放flac文件则引入这个jar包 -->
<dependency>
Expand Down Expand Up @@ -134,10 +134,16 @@
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.googlecode.soundlibs</groupId>-->
<!-- <artifactId>basicplayer</artifactId>-->
<!-- <version>3.0.0.0</version>-->
<!-- </dependency>-->

<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>basicplayer</artifactId>
<version>3.0.0.0</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
</dependencies>

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/cn/jianwoo/bo/CurInfoBO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class CurInfoBO implements Serializable
/** 是否暂停 */
private Boolean isPause;

/** 是否完成准备 */
private Boolean isReady;

/** 锁 */
private Object lock;
/** 播放实例 */
Expand All @@ -35,6 +38,7 @@ public CurInfoBO()
this.isDebug = false;
this.lock = new Object();
this.threadList = new CopyOnWriteArrayList<>();
this.isReady = false;
}


Expand Down Expand Up @@ -104,13 +108,14 @@ public void calcIdxAndTime(Double time)
{
play.tokenDelay();
NoteBO noteBO = play.getNote(play.getTmpIdx() + 1);
play.setDelayTime(NoteBO.calcTime(noteBO.getEndTime() - maxTime).intValue());
play.setDelayTime(NoteBO.calcTime(noteBO.getEndTime() - maxTime, noteBO.getRate()).intValue());
play.incrementTmpIdx();
}
play.updateIndex(play.getTmpIdx());

// 更新拖动进度条之后的 totalTime
play.setTotalTime(NoteBO.calcTime(play.getNote(play.getTmpIdx() + 1).getStartTime()).intValue());
play.setTotalTime(NoteBO.calcTime(play.getNote(play.getTmpIdx() + 1).getStartTime(),
play.getNote(play.getTmpIdx() + 1).getRate()).intValue());
if (i == j)
{
// 拖动进度条时重新计算起始的基准时间
Expand Down Expand Up @@ -159,4 +164,21 @@ public void setTimestamp(Long timestamp)
this.timestamp = timestamp;
}


public Boolean isCompleteReady()
{
return this.isReady;
}


public void completeReady()
{
this.isReady = true;

synchronized (this.lock)
{
this.lock.notifyAll();
}

}
}
33 changes: 29 additions & 4 deletions src/main/java/cn/jianwoo/bo/NoteBO.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class NoteBO implements Serializable

/** 音符组件对象 */
private Button node;
/** 播放速率 */
private Double rate;

public NoteBO()
{
Expand All @@ -74,6 +76,7 @@ public NoteBO()
this.isResetTime = false;
this.isUseDefinedDuration = false;
this.isMuleNotes = false;
this.rate = 1D;
}


Expand Down Expand Up @@ -118,8 +121,12 @@ public void initExtendNoteList(boolean isUseDefinedDuration)

public void init()
{
this.time = calcTime(this.getDuration()).intValue();
this.unitTime = calcTime(this.getUnit()).intValue();
if (this.getRate() == null || this.getRate().compareTo(0D) == 0)
{
this.setRate(1D);
}
this.time = calcTime(this.getDuration(), this.getRate()).intValue();
this.unitTime = calcTime(this.getUnit(), this.getRate()).intValue();
if (StrUtil.isBlank(this.getNote()))
{
this.setNote(generateNote(this.getValue()));
Expand All @@ -128,8 +135,13 @@ public void init()
{
this.setValue(parseNote(this.getNote()));
}
if (this.getUnit() == null)
{
this.unit = 0.041666666666666664;
}
this.setMultiple(this.getDuration() / this.getUnit());
this.setEndTime(this.getStartTime() + this.getDuration());

}


Expand Down Expand Up @@ -178,20 +190,21 @@ public static String generateNote(int note)
* 时间转换(音谱里的时间轴转换为毫秒)
*
* @param t 音谱里的时间
* @param rate 速率
* @date 17:33 2023/1/2
* @author gulihua
*
* @return 毫秒
**/
public static Double calcTime(Double t)
public static Double calcTime(Double t, Double rate)
{
if (t == null)
{
return 0d;
}
BigDecimal dur = new BigDecimal(t.toString());
return dur.divide(new BigDecimal("0.0625"), 6, RoundingMode.HALF_UP).multiply(new BigDecimal("180"))
.doubleValue();
.multiply(new BigDecimal(rate)).doubleValue();
}


Expand Down Expand Up @@ -607,4 +620,16 @@ public void setNode(Button node)
{
this.node = node;
}


public Double getRate()
{
return this.rate;
}


public void setRate(Double rate)
{
this.rate = rate;
}
}
19 changes: 19 additions & 0 deletions src/main/java/cn/jianwoo/genXml/GenStart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cn.jianwoo.genXml;

/**
* 根据 mid 文件生成 xml 文件的运行类
* !!重要:运行前请先看 Readme 中相应的方法
* @author gulihua
* @Description
* @date 2023-02-10 16:29
*/
public class GenStart
{
public static void main(String[] args) throws Exception
{
String midiPath = "/Users/gulihua/Downloads/她说伴奏.mid";
String xmlPath = "/Users/gulihua/Downloads/她说-林俊杰_伴奏.xml";
MidParseAndGenXML gen = new MidParseAndGenXML(midiPath, xmlPath);
gen.run();
}
}
Loading

0 comments on commit d58e43f

Please sign in to comment.