private void Save_Click(object sender, RoutedEventArgs e) { if (currentFile == null) { LogWrite("Couldn't export because there is no generated song yet."); return; } LogWrite("Select a destination to save."); var sfd = new SaveFileDialog(); sfd.Filter = "Standard MIDI File (*.mid, *.midi)|*.mid;*.midi"; if (sfd.ShowDialog() != true) { LogWrite("Canceled."); return; } LogWrite("Start saving! Please wait..."); IsEnabled = false; try { SmfParser.Save(new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write), currentFile); LogWrite("Successfully exported!"); } catch (Exception ex) { LogWrite("Couldn't export it due to a unknown error! " + ex.Message); } IsEnabled = true; }
public async Task AnalyzeAsync(string path) { try { using (var fs = new FileStream(path, FileMode.Open)) { var m = SmfParser.Parse(fs); await Task.Factory.StartNew(() => student.Learn(m)); LogWrite($"{path} has been analyzed!"); } } catch (ArgumentException) { LogWrite("Failed to analyze the file because it wasn't a midi file!"); } catch (FileNotFoundException) { LogWrite("Failed to analyze the file because it wasn't found!"); } catch (Exception ex) { LogWrite($"Unknown error! {ex.GetType().Name} : {ex.Message}\n{ex.StackTrace}"); } }
/// <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); }
private IEnumerator Start() { try { midi = SmfParser.Parse(new FileStream(StaticVariable.Path ?? path, FileMode.Open)); } catch (Exception) { Back(); } while (true) { yield return(null); if (!IsPlaying) { continue; } CurrentTime += Time.deltaTime; float time = CurrentTime * 1000; tick = (int)midi.Conductor.ToTick(time); foreach (var track in midi.Tracks) { foreach (var e in track.GetDataBetweenTicks(prevTick - 1, tick).OfType <NoteEvent>()) { var i = Instantiate(drop, new Vector3(e.Note - 60, 30, 0), default(Quaternion)); i.GetComponent <Drop>().Velocity = e.Velocity; } } prevTick = tick; text.text = $"{TimeToString(CurrentTime)} / {TimeToString(MaxTime)}"; //slider.maxValue = MaxTime; //slider.minValue = 0; //slider.value = CurrentTime; if (MaxTime < CurrentTime) { Stop(); } } }
public GroorineAudioSource(Stream midi, int latency = 20, int sampleRate = 44100) { data = SmfParser.Parse(midi); Latency = latency; SampleRate = sampleRate; }