Example #1
0
        /// <summary>
        /// MIDI ファイルのパスを指定して、再生を開始します。
        /// </summary>
        /// <param name="filePath">ファイルパス。</param>
        /// <param name="loopCount"></param>
        /// <param name="fadeOutTime"></param>
        public void Play(string filePath, int loopCount = -1, int fadeOutTime = 2000)
        {
            // 正しく生成されていればこれらはnullでないはずなので、例外が投げられたらバグが起きているはず
            if (CorePlayer == null ||
                _nativeplayer == null ||
                _cts == null ||
                _buffer == null
                )
            {
                throw new InvalidOperationException("初期化が完了していません。");
            }

            CorePlayer.Load(SmfParser.Parse(F.OpenRead(P.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath))));

            PlayAsync(loopCount, fadeOutTime);
        }
Example #2
0
        public async Task SaveAsync(string path, int loopCount = 2, MidiFile mf = null)
        {
            CorePlayer.Stop();
            if (mf != null)
            {
                CorePlayer.Load(mf);
            }
            CorePlayer.Play(loopCount);

            using (var wfw = new WaveFileWriter(path, new WaveFormat()))
            {
                while (CorePlayer.IsPlaying)
                {
                    byte[] b = ToByte(CorePlayer.GetBuffer(_buffer));
                    await wfw.WriteAsync(b, 0, b.Length);
                }
            }
        }