コード例 #1
0
        public override void Run()
        {
            while (running)
            {
                try
                {
                    byte[]         receiveData    = new byte[RECEIVE_BUFFER_LENGTH];
                    DatagramPacket incomingPacket = new DatagramPacket(receiveData, receiveData.Length);
                    socket.Receive(incomingPacket);

                    System.Threading.Thread thread = new System.Threading.Thread(new ThreadStart(() => {
                        if (receiveData[0] == RtpMidiCommand.MIDI_COMMAND_HEADER1)
                        {
                            midiCommandHandler.handle(receiveData,
                                                      new model.RtpMidiServer(incomingPacket.Address, incomingPacket.Port));
                        }
                        else
                        {
                            midiMessageHandler.Handle(receiveData,
                                                      new RtpMidiServer(incomingPacket.Address.HostName, incomingPacket.Port));
                        }
                    }));
                    thread.Start();
                }
                catch (SocketTimeoutException ignored)
                {
                }
                catch (IOException e)
                {
                    Log.Error("RtpMidi", "IOException while receiving", e);
                }
            }
            socket.Close();
        }
コード例 #2
0
        public MIDIPlayer(Context context, MIDIStyle style)
        {
            this.context = context;
            Style        = style;

            MIDISession.GetInstance().Init(context);
            MIDISession.GetInstance().Start();

            Bundle rinfo = new Bundle();

            rinfo.PutString(MIDIConstants.RINFO_ADDR, "192.168.1.118");
            //rinfo.PutString(MIDIConstants.RINFO_ADDR, "192.168.2.229");

            rinfo.PutInt(MIDIConstants.RINFO_PORT, 5008);

            rinfo.PutBoolean(MIDIConstants.RINFO_RECON, true);
            MIDISession.GetInstance().Connect(rinfo);

            currentSongPosition = 0;
            СurrentTempo        = 120;                     // 120BPM
            msOnPulse           = 60000000 / СurrentTempo; // 500 000

            pulsesPerQuarterNote = style.MidiSection.MidiHeaderInfo.Ticks;


            thread = new System.Threading.Thread(new ThreadStart(Run));
            thread.Start();
            isPlaying           = false;
            currentPressedNotes = new List <byte>();
            Subscribe();
        }
コード例 #3
0
 private void StartThread(ImageRunnable runnable)
 {
     StopThread();
     _thread = runnable.GetThread();
     _thread.Start();
 }