private bool HasNotes(string s)
        {
            bool result;

            try
            {
                string[] f = File.ReadAllLines(s);
                if (Path.GetExtension(s).Equals(PerformanceFileListView.fileTypes[1], StringComparison.OrdinalIgnoreCase) && new Performance(string.Join(",", f)).Sheet.Count > 0)
                {
                    result = true;
                }
                else
                {
                    ImplementedPlayer mml = new ImplementedPlayer();
                    for (int i = 0; i < f.Length; i++)
                    {
                        f[i] = f[i].RemoveLineComments();
                    }
                    string fmml = string.Join(string.Empty, f).RemoveBlockComments();
                    mml.Load(fmml);
                    result = mml.Tracks.Any((MMLPlayerTrack x) => x.notes.Any <Note>());
                }
            }
            catch (Exception e)
            {
                LogHost.Default.WarnException("HasNotes Could not read file: " + s, e);
                result = false;
            }
            return(result);
        }
예제 #2
0
 private bool HasNotes(string s)
 {
     try
     {
         var f = File.ReadAllLines(s);
         if (Path.GetExtension(s) == fileTypes[1])
         {
             if (new Performance(string.Join(",", f)).Sheet.Count > 0)
             {
                 return(true);
             }
         }
         var mml = new ImplementedPlayer();
         for (int i = 0; i < f.Length; i++)
         {
             f[i] = f[i].RemoveLineComments();
         }
         var fmml = string.Join(string.Empty, f).RemoveBlockComments();
         mml.Load(fmml);
         return(mml.Tracks.Any(x => x.notes.Any()));
     }catch (Exception e)
     {
         LogHost.Default.WarnException($"{nameof(HasNotes)} Could not read file: {s}", e);
         return(false);
     }
 }
예제 #3
0
        //Asumes file extension is already set to either .txt or .mml
        private void TryMML(string pathname)
        {
            var mml  = new ImplementedPlayer();
            var mmls = File.ReadAllLines(pathname);

            for (int i = 0; i < mmls.Length; i++)
            {
                mmls[i] = mmls[i].RemoveLineComments();
            }
            var fmml = string.Join(string.Empty, mmls).RemoveBlockComments();

            mml.Load(fmml);
            _ = Program.mem.PlayMML(mml, cts.Token);
        }
예제 #4
0
        internal async Task PlayMML(ImplementedPlayer p, CancellationToken cts)
        {
            p.Unmute();
            p.Play();
            if (!PersistentNamedPipeServer.Instance.IsConnected)
            {
                await TryInject();
            }
            PipeMessage noteOff = new PipeMessage(Process.Id, PMCommand.PlayNote)
            {
                Parameter = 0
            };

            foreach (var track in p.Tracks)
            {
                new Thread(() =>
                {
                    TimeSpan ts = new TimeSpan(0);
                    foreach (TextPlayer.Note note in track.notes)
                    {
                        TimeSpan w = note.TimeSpan - ts;
                        if (w.TotalMilliseconds > 0)
                        {
                            Thread.Sleep(w);
                        }
                        if (cts.IsCancellationRequested)
                        {
                            return;
                        }
                        PersistentNamedPipeServer.SendPipeMessage(new PipeMessage(Process.Id, PMCommand.PlayNote)
                        {
                            Parameter = note.GetStep()
                        });
                        Thread.Sleep(note.Length);
                        PersistentNamedPipeServer.SendPipeMessage(noteOff);
                        ts = note.TimeSpan + note.Length;
                    }
                })
                {
                    Priority     = ThreadPriority.Highest,
                    IsBackground = true
                }.Start();
            }
        }