コード例 #1
0
        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"
                });
            }
        }
コード例 #2
0
        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
            });
        }
コード例 #3
0
        /// <summary>
        /// This creates WPF staffs and MIDI from Lilypond.
        /// TODO: Remove the dependencies from one language to another. If we want to replace the WPF library with another for example, we have to rewrite all logic.
        /// TODO: Create our own domain classes to be independent of external libraries/languages.
        /// </summary>
        /// <param name="content"></param>
        public void LoadLilypondIntoWpfStaffsAndMidi(string content)
        {
            LilypondText = content;
            content      = content.Trim().ToLower().Replace("\r\n", " ").Replace("\n", " ").Replace("  ", " ");
            LinkedList <LilypondToken> tokens = GetTokensFromLilypond(content);

            WPFStaffs.Clear();

            // We use a hard-coded Song to test Domain to WPF converting, as we don't have a Lilypond to Domain converter.
            WPFStaffs.AddRange(new ToWPFConverter().parseToWPF(new Song()
            {
                components = new List <SongComponent>()
                {
                    new ClefLeaf("treble"),
                    new TempoLeaf(4, 4, 120),
                    new NoteLeaf(new Tone(ToneHeight.C, Modifier.b, 4), new NoteLength(1, 0)),
                    new NoteLeaf(new Tone(ToneHeight.D, Modifier.none, 4), new NoteLength(0.5, 0)),
                    new NoteLeaf(new Tone(ToneHeight.E, Modifier.none, 4), new NoteLength(0.25, 0)),
                    new NoteLeaf(null, new NoteLength(0.25, 0)),
                    new NoteLeaf(new Tone(ToneHeight.F, Modifier.none, 4), new NoteLength(0.125, 0)),
                    new NoteLeaf(new Tone(ToneHeight.G, Modifier.none, 4), new NoteLength(0.0625, 0)),
                    new NoteLeaf(new Tone(ToneHeight.A, Modifier.none, 4), new NoteLength(0.0625, 0)),
                    new NoteLeaf(new Tone(ToneHeight.B, Modifier.none, 4), new NoteLength(0.03125, 0)),
                    new NoteLeaf(new Tone(ToneHeight.C, Modifier.sharp, 5), new NoteLength(0.03125, 0)),
                    new RepeatComposite(3)
                    {
                        components = new List <SongComponent>()
                        {
                            new NoteLeaf(new Tone(ToneHeight.C, Modifier.b, 4), new NoteLength(1, 0)),
                            new NoteLeaf(new Tone(ToneHeight.D, Modifier.none, 4), new NoteLength(0.5, 0)),
                            new NoteLeaf(new Tone(ToneHeight.E, Modifier.none, 4), new NoteLength(0.25, 0))
                        },
                        firstAlternative = new List <SongComponent>()
                        {
                            new NoteLeaf(new Tone(ToneHeight.F, Modifier.none, 4), new NoteLength(0.125, 0)),
                            new NoteLeaf(new Tone(ToneHeight.G, Modifier.none, 4), new NoteLength(0.25, 0)),
                            new NoteLeaf(new Tone(ToneHeight.A, Modifier.none, 4), new NoteLength(0.25, 0)),
                        },
                        lastAlternative = new List <SongComponent>()
                        {
                            new NoteLeaf(new Tone(ToneHeight.B, Modifier.none, 4), new NoteLength(0.5, 0)),
                            new NoteLeaf(new Tone(ToneHeight.C, Modifier.sharp, 5), new NoteLength(0.5, 0)),
                        }
                    }
                }
            }));
            //WPFStaffs.AddRange(GetStaffsFromTokens(tokens));
            this.StaffsViewModel.SetStaffs(this.WPFStaffs);

            MidiSequence = GetSequenceFromWPFStaffs();
            MidiPlayerViewModel.MidiSequence = MidiSequence;
        }
コード例 #4
0
ファイル: MusicLoader.cs プロジェクト: Bryans91/MusicReader
        /// <summary>
        /// This creates WPF staffs and MIDI from Lilypond.
        /// TODO: Remove the dependencies from one language to another. If we want to replace the WPF library with another for example, we have to rewrite all logic.
        /// TODO: Create our own domain classes to be independent of external libraries/languages.
        /// </summary>
        /// <param name="content"></param>
        public void LoadLilypondIntoWpfStaffsAndMidi(string content)
        {
            LilypondText = content;
            content      = content.Trim().ToLower().Replace("\r\n", " ").Replace("\n", " ").Replace("  ", " ");
            LinkedList <LilypondToken> tokens = GetTokensFromLilypond(content);

            WPFStaffs.Clear();

            WPFStaffs.AddRange(GetStaffsFromTokens(tokens));
            this.StaffsViewModel.SetStaffs(this.WPFStaffs);

            MidiSequence = GetSequenceFromWPFStaffs();
            MidiPlayerViewModel.MidiSequence = MidiSequence;
        }
コード例 #5
0
        /// <summary>
        /// This creates WPF staffs and MIDI from Lilypond.
        /// </summary>
        /// <param name="content"></param>
        public void LoadStaffsAndMidi()
        {
            WPFStaffs.Clear();

            StaffBuilder staffBuilder = new PsamStaffBuilder();
            StaffLoader  staffLoader  = new StaffLoader(staffBuilder);

            staffLoader.LoadStaffs(Sequence.Symbols);

            WPFStaffs.AddRange(staffLoader.Symbols);
            this.StaffsViewModel.SetStaffs(this.WPFStaffs);

            MidiSequence = GetSequenceFromWPFStaffs();
            MidiPlayerViewModel.MidiSequence = MidiSequence;
        }
コード例 #6
0
        public void OpenFile(string path)
        {
            WPFStaffs.Clear();
            FilePath = path;

            String      extension = Path.GetExtension(path);
            IFileReader reader    = new FileReaderFactory().Get(extension);

            var musicSheet   = reader.ReadFile(path);
            var symbolString = musicSheet.SymbolsContent.ToString();

            LoadLilypond(symbolString);

            this.State = new MusicEditingState(this);
        }
コード例 #7
0
        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
            });
        }
コード例 #8
0
ファイル: FileHandler.cs プロジェクト: glenndewildt/DPA
        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
            });
        }
コード例 #9
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
            });
        }