Ejemplo n.º 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? DONE
        /// 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)
        {
            FileLoaderFactory factory = new FileLoaderFactory();
            FileLoader        loader  = factory.GetLoader(Path.GetExtension(fileName));

            if (Path.GetExtension(fileName).EndsWith(".mid"))
            {
                MidiSequence = new Sequence();
                MidiSequence.Load(fileName);

                MidiPlayerViewModel.MidiSequence = MidiSequence;
                this.LilypondText = LoadMidiIntoLilypond(MidiSequence);
                this.LilypondViewModel.LilypondTextLoaded(this.LilypondText);
            }
            else if (Path.GetExtension(fileName).EndsWith(".ly"))
            {
                StringBuilder sb = new StringBuilder();
                foreach (var line in File.ReadAllLines(fileName))
                {
                    sb.AppendLine(line);
                }

                this.LilypondText = sb.ToString();
                this.LilypondViewModel.LilypondTextLoaded(this.LilypondText);
            }
            else
            {
                throw new NotSupportedException($"File extension {Path.GetExtension(fileName)} is not supported.");
            }

            LoadLilypondIntoWpfStaffsAndMidi(LilypondText);
        }
Ejemplo n.º 2
0
        public Models.Track ReadFile(String path)
        {
            if (!IsMusicFile(path))
            {
                throw new NotSupportedException($"File extension {Path.GetExtension(path)} is not supported.");
            }

            IFileLoader loader = fileLoaderFactory.GetLoader(Path.GetExtension(path));

            return(loader.FileToString(path));
        }