/// <summary> /// Opens a file. /// TODO: Remove the switch cases and delegate. /// TODO: Remove the knowledge of filetypes. What if we want to support MusicXML later? /// TODO: Remove the calling of the outer viewmodel layer. We want to be able reuse this in an ASP.NET Core application for example. /// </summary> /// <param name="fileName"></param> public void OpenFile(string fileName) { if (Path.GetExtension(fileName).EndsWith(".mid")) { SequenceReader midiReader = new MidiSequenceReader(fileName); Sequence = midiReader.Sequence; MidiSequence = new Sequence(); MidiSequence.Load(fileName); LilypondViewModel.LilypondTextLoaded(LoadMidiIntoLilypond(MidiSequence)); } else if (Path.GetExtension(fileName).EndsWith(".ly")) { StringBuilder sb = new StringBuilder(); foreach (var line in File.ReadAllLines(fileName)) { sb.AppendLine(line); } LoadLilyPond(sb.ToString()); LilypondViewModel.LilypondTextLoaded(sb.ToString()); } else { throw new NotSupportedException($"File extension {Path.GetExtension(fileName)} is not supported."); } LoadStaffsAndMidi(); }
public void SetLilypondViewModel(LilypondViewModel lilypondViewModel) { if (_lilypondViewModel != null) { _lilypondViewModel.TextChanged -= _lilypondViewModel_TextChanged; } _lilypondViewModel = lilypondViewModel; _lilypondViewModel.TextChanged += _lilypondViewModel_TextChanged; }
public override void GoInto(LilypondViewModel owner) { lastChange = DateTime.Now; OwnEventmanager.Manager.DispatchEvent("changeInformativeText", showText); Task.Delay(MILLISECONDS_BEFORE_CHANGE_HANDLED).ContinueWith(task => { if ((DateTime.Now - lastChange).TotalMilliseconds >= MILLISECONDS_BEFORE_CHANGE_HANDLED) { OwnEventmanager.Manager.DispatchEvent("reRender", owner.LilypondText); owner.UndoCommand.RaiseCanExecuteChanged(); OwnEventmanager.Manager.DispatchEvent("changeEditorState", "Idle"); } }, TaskScheduler.FromCurrentSynchronizationContext()); // Request from main thread. }
public void Execute(LilypondViewModel editor) { editor.SaveAsCommand.Execute("PDF|*.pdf"); }
public EditorDisabledState(LilypondViewModel viewModel) : base(viewModel) { ReadOnly = true; }
public override void GoInto(LilypondViewModel owner) { owner.CanEdit = true; OwnEventmanager.Manager.DispatchEvent("changeInformativeText", showText); }
public virtual void GoInto(LilypondViewModel owner) { }
public void Execute(LilypondViewModel editor) { editor.SaveAsCommand.Execute("Lilypond|*.ly"); }
public override void GoInto(LilypondViewModel owner) { owner.CanEdit = false; }
public void Execute(LilypondViewModel editor) { editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, @"\tempo 4=120"); }
public void Execute(LilypondViewModel editor) { editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, $"\\time {_beatUnit}/{_beatsPerBar}"); }
protected BaseEditorState(LilypondViewModel viewModel) { ViewModel = viewModel; }
public void Execute(LilypondViewModel editor) { editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, @"\clef treble"); }
public EditorEnabledState(LilypondViewModel viewModel) : base(viewModel) { ReadOnly = false; }