【问题标题】:Java Read and Play MIDI file using public static void midi(Score score) methodJava Read and Play MIDI file using public static void midi(Score score) 方法
【发布时间】:2021-04-11 18:45:24
【问题描述】:

如何创建一个程序来读取和播放 MIDI 文件?我需要找到一种在 Class Play 中播放文件的方法,以及一种将 midi 文件加载到 Class Read 中的分数并将分数变量传递给 View.sketch() 的方法。我正在使用这个网站来查找类 Read 和类 Play http://www.explodingart.com/jmusic/jmDocumentation/index.html 下的方法。 这是我目前所拥有的。

import jm.JMC;
import jm.music.data.*;
import jm.util.*;

public class Main {
     public static void main ( String [] args ){
        public static void midi(Score score){
           Score score = new Score("my music score ");// Name your score
           View.sketch(score);
        }

    }
}
//1272439.1.mid 

这是我的文件名,但我不知道如何将它包含在我的代码中。

【问题讨论】:

    标签: java midi


    【解决方案1】:

    你可以试试这样的:

    import java.io.File;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    
    import jm.music.data.Score;
    import jm.util.Play;
    import jm.util.Read;
    import jm.util.View;
    
    public class Test {
        public static void main(String[] args) throws Exception {
            File f = new File("e:\\tb.mid");
            
            if(!f.exists()) {
                System.out.println("File " + f.getAbsolutePath() + " doesn't exist.");
                System.exit(-1);
            }
            Score score =  Read.midiOrJmWithNoMessaging(f);
            score.setTitle("my music score ");// Name your score
            
            View.sketch(score);
            
            //play whole file
            //Play.midi(score,false);
            
            //to play only for 5 seconds
            ExecutorService es = Executors.newSingleThreadExecutor();
            es.submit(()-> Play.midi(score, false));
            //stop playing after 5 seconds
            Thread.sleep(5000);  
            System.out.println("stopping");
            Play.stopMidi(); //stop playing midi
            Play.closeAll(); //close all resources
            
            //uncomment this if you want to exit the program after playing
            //System.exit(0); 
        }
    }
    

    输出:

    Convert SMF to JM
    jMusic Play: Playing score my music score  using JavaSound General MIDI soundbank.
    jMusic Play: Waiting for the end of my music score .
    stopping
    jMusic Play: Stopping JavaSound MIDI playback of 0
    jMusic MidiSynth: Stopped JavaSound MIDI playback
    

    注释和取消注释部分代码以获得更好的理解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 2016-05-22
      • 2021-02-17
      • 2011-01-24
      • 2019-05-28
      • 1970-01-01
      相关资源
      最近更新 更多