import java.applet.AudioClip; //import midi.*; // This version ignores fTime arguments. (not needed) import java.applet.Applet; import java.net.*; public class CMIDI { static Applet sm_applet = null; //MidiOutDevice midiOut; //int g_arriInstToChan[]; //int g_arriChanToInst[]; //int g_iFreeChanNum = 0; NoteFiles garr_nfInst[]; int g_iMaxInst = -1; public void MidiOutNoteON(int note, int vel, int chnl, int fTime) { garr_nfInst[chnl].Start(note, fTime); //try midiOut.Out(MidiDevice.MidiNoteOn | chnl | note<<8 | vel<<16); catch(MidiException e); } public void MidiOutNoteOFF(int note, int chnl) { garr_nfInst[chnl].Stop(note); //try midiOut.Out(MidiDevice.MidiNoteOff | chnl | note << 8); catch(MidiException e); } //================================================= public int iGetParameter (String str) { return (new Integer(sm_applet.getParameter(str))).intValue(); } public void OnInit () // Call this to initialize { garr_nfInst = new NoteFiles[128]; /*g_arriInstToChan = new int[128]; int C; for (C=0; C<128; C++) g_arriInstToChan[C] = -1; g_arriChanToInst = new int[16]; for (C=0; C<16; C++) g_arriChanToInst[C] = -1; MidiOutDevice.GetNumDevices(); // bogus int iDevice; try iDevice = iGetParameter("device"); catch(NumberFormatException e) iDevice=-1; try midiOut = new MidiOutDevice(iDevice); catch(MidiException e); */ } public void OnStart () // call this to start { //try midiOut.Open(); catch(MidiException e); } public void OnStop () // call this to stop { for (int C=0; C<=g_iMaxInst; C++) garr_nfInst[C].AllStop(); //try midiOut.Close(); catch(MidiException e); } public void LoopThis (int fTime) { for (int C=0; C<=g_iMaxInst; C++) if (garr_nfInst[C] != null) garr_nfInst[C].LoopThis(fTime); } //================================================= int iGetInstrumentChannel (char pv) { int ret = (int)pv; if (garr_nfInst[ret] == null) { try garr_nfInst[ret] = new NoteFiles(ret, sm_applet); catch(Exception e) ret = 0; if (ret > g_iMaxInst) g_iMaxInst = ret; } return ret; /*short C=(short)pv; if (g_arriInstToChan[C] >= 0 && C == g_arriChanToInst[g_arriInstToChan[C]]) return g_arriInstToChan[C]; g_arriInstToChan[C] = g_iFreeChanNum; g_arriChanToInst[g_iFreeChanNum] = C; try midiOut.Out(MidiDevice.MidiProgramChange | g_iFreeChanNum | (C << 8)); catch(MidiException e); g_iFreeChanNum++; if (g_iFreeChanNum == 16) { g_iFreeChanNum = 0; return 15; } return g_iFreeChanNum - 1; */ } //---------------------------------- boolean m_bHaveDefaultInst = false; final int c_iNumInst = 9; int marr_iDefaultInst[] = new int[c_iNumInst]; //--------------------------------------------- public int iGetParameter (String str, Applet app) { return (new Integer(app.getParameter(str))).intValue(); } //--------------------------------------------- int iGetDefaultInst (int iIndex, Applet app) // Hack to get decent MIDI sounds { if (!m_bHaveDefaultInst) { for (int C=0; C= m_iLowestNote + m_iNumFiles) iMIDINote -= 12; return iMIDINote - m_iLowestNote; } } // end class NoteFiles