Exemple #1
0
        /// <summary> This is the background thread responsible for playing the SingleBeats. </summary>
        private void ThreadEntryPrt()
        {
            while (_running)
            {
                //Get next MIDI Command, waiting until it is time to play it.
                SimpleMidiMessage next = _source.GetNextMidiCommand(block: true);

                Winmm.midiOutShortMsg(_handle, next.Data);      //Send MIDI Comand to winmm
            }
        }
 public override bool Stop()
 {
     if (Enabled)
     {
         bool stopped = Winmm.Stop(_timerId);
         _enabled = !stopped;
         return(stopped);
     }
     return(false);
 }
        public static void ExecuteCommand(string cmd)
        {
            var err = Winmm.mciSendString(cmd, null, 0, 0);

            if (err != 0)
            {
                StringBuilder buf = new StringBuilder(256);
                Winmm.mciGetErrorString(err, buf, 256);
                string errStr = buf.ToString();
                throw new MCIException(string.Format("ErrorCode: {0} ,Info: {1}", err.ToString(), errStr));
            }
        }
        public override void Start()
        {
            if (Enabled)
            {
                return;
            }

            uint interval = Convert.ToUInt32(Math.Round(_intervalLength, 0));

            _timerId   = Winmm.Start(interval, TimerCallback);
            _startTime = DateTime.Now;

            _enabled = true;
        }
Exemple #5
0
        /// <summary>
        /// Disables high precision timers. Use before exiting the app.
        /// </summary>
        public static void DisableHighPrecisionTimers()
        {
            lock (_lock)
            {
                if (_useDefaultTimers || !_isHighPrecision)
                {
                    return;
                }

                Winmm.TimeEndPeriod(1);

                _isHighPrecision = false;
            }
        }
Exemple #6
0
        /// <summary>
        /// Enables high precision timers. Use before calling anything else.
        /// </summary>
        public static void EnableHighPrecisionTimers()
        {
            lock (_lock)
            {
                if (_useDefaultTimers || _isHighPrecision)
                {
                    return;
                }

                Winmm.TimeBeginPeriod(1);

                _isHighPrecision = true;
            }
        }
Exemple #7
0
        private void LoadAndPlay(SoundFlags flags)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            if (_streamData == null)
            {
                int streamLen = (int)_stream.Length;
                _streamData = new byte[streamLen];
                _stream.Read(_streamData, 0, streamLen);
            }

            Winmm.PlaySound(_streamData, IntPtr.Zero, SoundFlags.SND_MEMORY | SoundFlags.SND_NODEFAULT | flags);
        }
Exemple #8
0
        /// <summary>
        /// Creates a new instance of the WinmmOut class which opens a MIDI port at the specified device ID.
        /// </summary>
        /// <param name="deviceID">The underlaying hardware port used to play music.
        /// Windows should have a built-in virtual synthesizer as device 0.
        /// The next port(if available) will be port 1 and so on.</param>
        /// <param name="beatsPerMinutes">Specifies the length of a beat, which is the unit of time used throughout MIDI Gremlin.
        /// If left at 60, a beat will be the same as a second.</param>
        public WinmmOut(uint deviceID, int beatsPerMinutes = 60)
        {
            timeMannager   = new VariableBpmCounter();
            BeatsPerMinute = beatsPerMinutes;

            uint numberOfDevices = Winmm.midiOutGetNumDevs();

            DeviceID = numberOfDevices < deviceID ? 0 : deviceID;
            if (0 != Winmm.midiOutOpen(out _handle, DeviceID, IntPtr.Zero, IntPtr.Zero, 0))
            {
                throw new Exception("Opening MIDI device unsuccessful. Is the device already open somwhere else?");
            }


            _workThread = new Thread(ThreadEntryPrt)
            {
                IsBackground = true
            };
        }
        private readonly int DEAD         = 16000; //スライドパッドが入力の閾値。16000だとだいたい中央から半分以上倒したら入力扱い


        //この辺の処理は殆ど参考URLのパクリ。ゲームパッドの接続数を1つに限定している
        private GamePadObserver()
        {
            var joy_info = new Winmm.JOYINFO();

            var timer = new DispatcherTimer(DispatcherPriority.Normal)
            {
                Interval = new TimeSpan(0, 0, 0, 0, 10)
            };

            timer.Tick += (sender1, e1) => {
                if (Winmm.joyGetPos(0, ref joy_info) == 0)
                {
                    onEnterKeyDown.OnNext((joy_info.wButtons & Winmm.JOY_BUTTON1) != 0);
                    var x_pos  = joy_info.wXpos;
                    var y_pos  = joy_info.wYpos;
                    var y_flow = 0;
                    var x_flow = 0;
                    if (y_pos < CENTER_POINT - DEAD)
                    {
                        y_flow = 1;
                    }
                    else if (y_pos > CENTER_POINT + DEAD)
                    {
                        y_flow = -1;
                    }
                    if (x_pos > CENTER_POINT + DEAD)
                    {
                        x_flow = 1;
                    }
                    else if (x_pos < CENTER_POINT - DEAD)
                    {
                        x_flow = -1;
                    }
                    inHorizontalInput.OnNext(x_flow);
                    inVerticalInput.OnNext(y_flow);
                }
            };

            timer.Start();
        }
Exemple #10
0
 /// <summary>
 /// Closes the WinmmOut instance safely.
 /// </summary>
 public void Dispose()
 {
     Winmm.midiOutClose(_handle);
     _disposed = true;
 }
Exemple #11
0
 public void Stop()
 {
     Winmm.PlaySound((byte[])null, IntPtr.Zero, SoundFlags.SND_PURGE);
 }