Esempio n. 1
0
        public EventReadResult Read()
        {
            if (Event != null)
            {
                Thread.Sleep(2000);
            }

            Event = null;
            switch (state++)
            {
            case 6:
                Exit = true;
                break;

            default:
                var tone = new IonianTone()
                {
                    Scale  = (IonianScale)state,
                    Octave = 4,
                };
                Console.WriteLine($"{(false ? "Release" : "Attack ")} : Scale {tone.Scale}, Octave {tone.Octave}");
                Event = new ToneKeyEvent(tone, false);
                break;
            }

            return(EventReadResult.Success);
        }
Esempio n. 2
0
 private void handleKeyEvent(ToneKeyEvent e)
 {
     if (DebugPrint && !e.Release)
     {
         Console.WriteLine($"{(e.Release ? "Release" : "Attack")} : {e.Tone.Scale}, {e.Tone.Octave}");
     }
     if (e.Release)
     {
         Release(e.Tone);
     }
     else
     {
         Attack(e.Tone);
     }
 }
Esempio n. 3
0
        public EventReadResult Read()
        {
            if (!initialized)
            {
                serialPort.BaudRate     = 9600;
                serialPort.ReadTimeout  = 500;
                serialPort.WriteTimeout = 500;
                serialPort.PortName     = SerialPortName;
                serialPort.DataBits     = 8;
                serialPort.Parity       = Parity.None;
                serialPort.StopBits     = StopBits.One;
                serialPort.Handshake    = Handshake.None;
                serialPort.Open();
                initialized = true;
            }

            int typeInt;

            do
            {
                try
                {
                    var typeChar = (char)serialPort.ReadChar();
                    typeInt = (int)char.GetNumericValue(typeChar);
                }
                catch (TimeoutException)
                {
                    return(EventReadResult.Timeout);
                }
            } while (typeInt > 4);

            var type = (ToneEventType)typeInt;

            try
            {
                byte[] buffer;
                switch (type)
                {
                case ToneEventType.Key:
                    buffer = ReadBytes(ToneKeyEvent.DataLength);
                    Event  = ToneKeyEvent.ParseEvent(buffer, 0);
                    break;

                case ToneEventType.Thumb:
                    buffer = ReadBytes(ToneThumbEvent.DataLength);
                    Event  = ToneThumbEvent.ParseEvent(buffer);
                    break;

                case ToneEventType.Filter:
                    Event = new ToneFilterEvent();
                    break;

                case ToneEventType.Wave:
                    Event = new ToneWaveEvent();
                    break;
                }
            }
            catch (TimeoutException)
            {
                return(EventReadResult.Timeout);
            }

            return(EventReadResult.Success);
        }