Beispiel #1
0
        /// <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();
        }
Beispiel #2
0
 public void SetLilypondViewModel(LilypondViewModel lilypondViewModel)
 {
     if (_lilypondViewModel != null)
     {
         _lilypondViewModel.TextChanged -= _lilypondViewModel_TextChanged;
     }
     _lilypondViewModel              = lilypondViewModel;
     _lilypondViewModel.TextChanged += _lilypondViewModel_TextChanged;
 }
Beispiel #3
0
 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;
 }
Beispiel #10
0
 public void Execute(LilypondViewModel editor)
 {
     editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, @"\tempo 4=120");
 }
Beispiel #11
0
 public void Execute(LilypondViewModel editor)
 {
     editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, $"\\time {_beatUnit}/{_beatsPerBar}");
 }
Beispiel #12
0
 protected BaseEditorState(LilypondViewModel viewModel)
 {
     ViewModel = viewModel;
 }
Beispiel #13
0
 public void Execute(LilypondViewModel editor)
 {
     editor.LilypondText = editor.LilypondText.Insert(editor.CaretIndex, @"\clef treble");
 }
Beispiel #14
0
 public EditorEnabledState(LilypondViewModel viewModel) : base(viewModel)
 {
     ReadOnly = false;
 }