Example #1
0
        private int _beatsPerBar;     // Aantal beatnotes per maat.

        public void OpenFile(string fileName)
        {
            if (Path.GetExtension(fileName).EndsWith(".mid"))
            {
                MidiSequence = new Sequence();
                MidiSequence.Load(fileName);
                MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
                {
                    MidiSequence = MidiSequence
                });
                LoadMidi(MidiSequence);
            }
            else if (Path.GetExtension(fileName).EndsWith(".ly"))
            {
                StringBuilder sb = new StringBuilder();
                foreach (var line in File.ReadAllLines(fileName))
                {
                    sb.AppendLine(line);
                }

                LilypondText = sb.ToString();

                LoadLilypond(sb.ToString());
            }
            else
            {
                throw new NotSupportedException($"File extension {Path.GetExtension(fileName)} is not supported.");
            }
        }
        async public Task TextChanged(string lilypondText)
        {
            var sheetReaderFactory = new SheetReaderFactory();
            var sheetReader        = sheetReaderFactory.GetReader(".ly");

            try
            {
                var sheet = await sheetReader.ReadFromStringAsync(lilypondText);

                var converter = new SheetToWPFConverter();

                WPFStaffs.Clear();
                WPFStaffs.AddRange(converter.ConvertSheet(sheet));
                WPFStaffsChanged?.Invoke(this, new WPFStaffsEventArgs()
                {
                    Symbols = WPFStaffs
                });

                MidiSequence = GetSequenceFromWPFStaffs();
                MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
                {
                    MidiSequence = MidiSequence
                });
            }
            catch (Exception)
            {
                Messenger.Default.Send(new CurrentStateMessage()
                {
                    State = "Error parsing lilypond"
                });
            }
        }
        private int _beatsPerBar;    // Aantal beatnotes per maat.

        async public Task OpenFile(string fileName)
        {
            var sheetReaderFactory = new SheetReaderFactory();
            var sheetWriterFactory = new SheetWriterFactory();
            var sheetReader        = sheetReaderFactory.GetReader(fileName);
            var converter          = new SheetToWPFConverter();
            var writer             = sheetWriterFactory.GetWriter(".ly");

            var sheet = await sheetReader.ReadFromFileAsync();

            WPFStaffs.Clear();
            WPFStaffs.AddRange(converter.ConvertSheet(sheet));
            WPFStaffsChanged?.Invoke(this, new WPFStaffsEventArgs()
            {
                Symbols = WPFStaffs
            });

            LilypondTextChanged?.Invoke(this, new LilypondEventArgs {
                LilypondText = await writer.WriteToString(sheet)
            });

            MidiSequence = GetSequenceFromWPFStaffs();
            MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
            {
                MidiSequence = MidiSequence
            });
        }
Example #4
0
 public void Open()
 {
     MidiSequence = new Sequence();
     MidiSequence.Load(fileName);
     MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
     {
         MidiSequence = MidiSequence
     });
 }
        public void LoadLilypond(string content)
        {
            WPFStaffs.Clear();
            LilypondText = content.Length > 0 ? content : "";

            var tokens          = GetTokensFromLilypond(content);
            var staffCollection = new LilypondClient(tokens).Solve();

            WPFStaffs.AddRange(staffCollection);
            WPFStaffsChanged?.Invoke(this, new WPFStaffsEventArgs()
            {
                Symbols = WPFStaffs, Message = ""
            });

            MidiSequence = new StaffHandler().GetSequenceFromWPFStaffs(WPFStaffs);
            MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
            {
                MidiSequence = MidiSequence
            });
        }
Example #6
0
        public void LoadLilypond(string content)
        {
            LilypondText = content;
            content      = content.Trim().ToLower().Replace("\r\n", " ").Replace("\n", " ").Replace("  ", " ");
            LinkedList <LilypondToken> tokens = GetTokensFromLilypond(content);

            WPFStaffs.Clear();
            string message;

            WPFStaffs.AddRange(GetStaffsFromTokens(tokens, out message));
            WPFStaffsChanged?.Invoke(this, new WPFStaffsEventArgs()
            {
                Symbols = WPFStaffs, Message = message
            });

            MidiSequence = GetSequenceFromWPFStaffs();
            MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
            {
                MidiSequence = MidiSequence
            });
        }
Example #7
0
        public void ShowStaff()
        {
            WPFStaffs.Clear();
            WPFManager.getMusicSymbols(Staff, WPFStaffs);
            WPFStaffsChanged?.Invoke(this, new WPFStaffsEventArgs()
            {
                Symbols = WPFStaffs
            });

            Lilypond lily = new Lilypond("");

            LilypondText = lily.GetLilyFromStaff(Staff);

            Midi midi = new Midi("");

            MidiSequence = midi.GetSequenceFromStaff(Staff);
            MidiSequenceChanged?.Invoke(this, new MidiSequenceEventArgs()
            {
                MidiSequence = MidiSequence
            });
        }