Esempio n. 1
0
 protected void disposePianoAndSoundDevices()
 {
     if (outDevice != null && inDevice != null)
     {
         MIDIDevice.Disconnect(inDevice.Handle, outDevice.Handle);
     }
     if (outDevice != null)
     {
         Debug.Log("Dispose output device.");
         outDevice.Dispose();
         outDevice = null;
     }
     if (inDevice != null)
     {
         Debug.Log("Dispose input device.");
         try
         {
             inDevice.StopRecording();
         }
         catch (Exception e)
         {
             throw new Exception("Failed to stop recording. " + e.Message);
         }
         inDevice.Dispose();
         inDevice = null;
     }
 }
Esempio n. 2
0
    protected void initPianoAndSoundDevices()
    {
        // initialize input and output device
        if (MIDIOutDevice.DeviceCount > 0)
        {
            outDevice = new MIDIOutDevice(0);
            Debug.Log("Output device setup complete.");
        }
        if (MIDIController.DeviceCount > 0)
        {
            inDevice = new MIDIController(0);
            inDevice.ChannelMessageReceived += HandleKeyPressed;
            inDevice.Error += new EventHandler <ErrorEventArgs>(inDevice_Error);
            Debug.Log("Input device setup complete.");
        }

        if (outDevice == null)
        {
            throw new Exception("No output device present. Please check if your sound system is working correctly.");
        }
        if (inDevice == null)
        {
            Debug.Log("Input Device or Output Device missing.");
            return;
        }

        // connect the input device to output device
        MIDIDevice.Connect(inDevice.Handle, outDevice.Handle);

        // initialize the queue: Key (Channel) Value (Channel Command)
        keyEvents = new Queue <KeyValuePair <int, ChannelCommand> >();

        try
        {
            inDevice.StartRecording();
        }
        catch (Exception e)
        {
            throw new Exception("Failed to start recording. " + e.Message);
        }
        Debug.Log("Successfully start!");
    }