开发者

Midiplayer stops playing sounds after 16 notes

开发者 https://www.devze.com 2022-12-31 18:08 出处:网络
I am currently programming a Piano Keyboard editor, much like the one you can find in Cubase, Logic, Reason etc..

I am currently programming a Piano Keyboard editor, much like the one you can find in Cubase, Logic, Reason etc..

I have this big grid, double array new int [13][9], which makes it 13 rows, 9 columns. The first column [0-12][0] is the Keyboard, at the top there's "high C" (midi note 72) and at the bottom there's "low C" (midi note 60). That column is an array of JButtons and when you press for example "low C", note 60 is being played by the Synthesizer.

I've gotten this to work pretty OK as for now, but one problem I have is that I can only play 16 notes in a row, then it's like the Synthesizer shuts down or something.

Do you guys have ANY idea of what the problem is?

A bit of the code:

 import java.awt.*;
        import javax.swing.*;
        import java.awt.event.*;
        import java.util.*;
        import javax.sound.midi.*;

    actionPerformed(ActionEvent ae){
    for(int i = 0; i<13; i++){
            if(o== instr[i]){//instr is the button array
                SpelaTangent(i);
            }
        }

    }

    public void SpelaTangent(int tangent){


            int [] klaviatur = new int[13];
            for(int i = 0; i<13; i++){

                klaviatur[i] = (72-i);
                }

                         try {
                       Synthesizer synth = MidiSystem.getSynthesizer();                

synth.open(); 
                       final MidiChannel[] mc    = synth.getChannels();               

 Instrument[]        instrument = synth.getDefaultSoundbank().getInstruments();     

               synth.loadInstrument(instrument[1]);  
                        mc[0].noteOn(klaviatur[tangent],350);
                        mc[0].not开发者_JS百科eOff(klaviatur[tangent],350);

                   } catch (MidiUnavailableException e) {}
    }

Help is very much appreciated!


You seem to initialize the MIDI system new for every note that is played. Try to move the initializing code somewhere it is only executed once at the start of your program and reuse the MidiChannel you create there.

0

精彩评论

暂无评论...
验证码 换一张
取 消