使用android-mid-lib分别播放每个音符

时间:2016-10-17 05:13:01

标签: android midi

我想分别播放.mid文件的每个音符。我正在使用android-mid-lib for android(Click here)。

但我无法分开播放音符,因为我无法单独获取.mid文件的每个音符。以下是我到目前为止所做的工作。

File input = new File(Environment.getExternalStorageDirectory()+"/ants.mid");
      //  File input= new File("android.resource://" + getPackageName() + "/" + R.raw._twinkle_twinkle_bundled);
        try {
            midiFile = new MidiFile(input);
            System.out.println("asdsadsadsa:"+midiFile.getTracks().get(0).getEvents().first().getDelta());


        } catch (IOException e) {
            e.printStackTrace();
        }
        // 1. Create some MidiTracks
        MidiTrack tempoTrack = new MidiTrack();
        MidiTrack noteTrack = new MidiTrack();


// 2. Add events to the tracks
// Track 0 is the tempo map
        TimeSignature ts = new TimeSignature();
        ts.setTimeSignature(4, 4, TimeSignature.DEFAULT_METER, TimeSignature.DEFAULT_DIVISION);

        Tempo tempo = new Tempo();
        tempo.setBpm(228);

        tempoTrack.insertEvent(ts);
        tempoTrack.insertEvent(tempo);

// Track 1 will have some notes in it
        final int NOTE_COUNT = 80;

        for(int i = 0; i < NOTE_COUNT; i++)
        {
            int channel = 0;
            int pitch = 1 + i;
            int velocity = 100;
            long tick = i * 480;
            long duration = 120;

            noteTrack.insertNote(channel, pitch, velocity, tick, duration);
        }

// 3. Create a MidiFile with the tracks we created
        ArrayList<MidiTrack> tracks = new ArrayList<MidiTrack>();
        tracks.add(tempoTrack);
        tracks.add(noteTrack);

        MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, tracks);

// 4. Write the MIDI data to a file
        File output = new File(Environment.getExternalStorageDirectory()+"/exampleout.mid");
        try
        {
            midi.writeToFile(output);
        }
        catch(IOException e)
        {
            System.err.println(e);
        }

使用此功能,我可以更改整个mid文件的音高,但我不知道如何分别播放每个音符 任何帮助表示赞赏!

0 个答案:

没有答案
相关问题