You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JFugue 5.0中获取所有支持的Tempo速度字典列表

实现方案

JFugue 5.0.9 版本内置了org.staccato.TempoDictionary类管理所有预设的速度名称和对应BPM值,你可以通过反射直接读取该类内置的映射表,避免手动硬编码速度名称,具体实现代码如下:

import org.staccato.TempoDictionary;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Set;

public class JFugueTempoFetcher {
    public static String[] getAllTempoNames() throws NoSuchFieldException, IllegalAccessException {
        // 获取TempoDictionary单例实例
        TempoDictionary tempoDict = TempoDictionary.getInstance();
        // 反射读取内置的速度名称映射表
        Field tempoMapField = TempoDictionary.class.getDeclaredField("tempoMap");
        tempoMapField.setAccessible(true);
        Map<String, Integer> tempoMap = (Map<String, Integer>) tempoMapField.get(tempoDict);
        // 提取所有速度名称转为字符串数组
        Set<String> tempoNameSet = tempoMap.keySet();
        return tempoNameSet.toArray(new String[0]);
    }

    public static void main(String[] args) throws Exception {
        String[] allTempos = getAllTempoNames();
        // 输出验证
        for (String tempo : allTempos) {
            System.out.println(tempo);
        }
    }
}

补充说明

  • 该实现依赖JFugue 5.0.9的内部逻辑,如果你后续升级JFugue版本,需要先确认TempoDictionary类和tempoMap字段的定义是否有变更
  • 如果你不想用反射,也可以直接查看TempoDictionary的源码,将所有映射的key复制出来硬编码,避免反射的性能开销和版本兼容风险,完整的预设速度包含Grave、Lento、Adagio、Andante、Moderato、Allegro、Presto等20+种,完全覆盖你当前手动录入的取值
  • 如果你需要同时获取速度对应的BPM数值,直接从上述代码的tempoMap中读取value即可,不需要额外处理

内容的提问来源于stack exchange,提问作者BabaNew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 05:54:05