Ejemplo n.º 1
0
        private void PlayRandom()
        {
            if (lstMusic.Items.Count == 0)
            {
                return;
            }
            long lt = 0, et = DateTime.Now.Ticks;

            foreach (object var in lstMusic.Items)
            {
                MusicData m = (MusicData)var;
                if (m.LastPlayedTicks > lt)
                {
                    lt = m.LastPlayedTicks;
                }
                if (m.LastPlayedTicks < et)
                {
                    et = m.LastPlayedTicks;
                }
            }
            double sum      = 0.0;
            double timeRate = setting.TimeWeight;

            if (lt != et)
            {
                timeRate /= lt - et;
            }
            double fixedRate = 100.0 - setting.TimeWeight;
            int    index = random.Next(lstMusic.Items.Count), i = 0;

            foreach (object var in lstMusic.Items)
            {
                MusicData m = (MusicData)var;
                double    p = (100.0 - m.SkipRate) * (fixedRate + timeRate * (double)(lt - m.LastPlayedTicks));
                sum += p;
                if (sum * random.Next() / int.MaxValue < p)
                {
                    index = i;
                }
                i++;
            }
            lstMusic.SelectedIndex = index;
            PlaySelected();
        }
Ejemplo n.º 2
0
 private void UpdateCaption(Status status, MusicData data)
 {
     statusValue = status;
     statusData  = data;
     UpdateCaption();
 }
Ejemplo n.º 3
0
        public int CompareLastPlayed(MusicData x, MusicData y)
        {
            int ret = Math.Sign(y.LastPlayedTicks - x.LastPlayedTicks);

            return(ret != 0 ? ret : string.Compare(x.FileName, y.FileName));
        }
Ejemplo n.º 4
0
        public int CompareTitle(MusicData x, MusicData y)
        {
            int ret = string.Compare(x.Title, y.Title);

            return(ret != 0 ? ret : string.Compare(x.FileName, y.FileName));
        }
Ejemplo n.º 5
0
 public int CompareFileName(MusicData x, MusicData y)
 {
     return(string.Compare(x.FileName, y.FileName));
 }
Ejemplo n.º 6
0
        private void Play(bool loop)
        {
            Cursor preCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (lstMusic.SelectedItem == null)
                {
                    return;
                }
                MusicData data = (MusicData)lstMusic.SelectedItem;
                if (!File.Exists(data.FileName))
                {
                    musicController.Data = null;
                    UpdateCaption(Status.ReadError, data);
                    if (Log.Error(
                            $"再生しようとしたファイルは存在しません。\n{data.FileName}\n\nリストから削除しますか?",
                            MessageBoxButtons.YesNo,
                            MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        removeItemToolStripMenuItem.PerformClick();
                    }
                    return;
                }
                UpdateCaption(Status.Reading, data);
                try { musicController.Data = data; }
                catch (Exception e)
                {
                    musicController.Data = null;
                    UpdateCaption(Status.ReadError, data);
                    if (Log.Error(
                            $"読み込みに失敗しました!\n読み込みに対応していない形式である可能性があります。\n{data.FileName}\n\nリストから削除しますか?",
                            e,
                            MessageBoxButtons.YesNo,
                            MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        removeItemToolStripMenuItem.PerformClick();
                    }
                    return;
                }
                UpdateCaption(Status.Preparing, data);
                try { musicController.Play(loop); }
                catch (Exception e)
                {
                    musicController.Data = null;
                    UpdateCaption(Status.PlayError, data);
                    Log.Error("再生に失敗しました!\n" + data.FileName, e);
                    return;
                }
                lastPlayed = DateTime.Now;
                UpdateCaption((loop ? Status.LoopPlaying : Status.Playing), data);
                if (setting.PlayLog)
                {
                    Log.Write(Log.LogType.Play, data.FileName);
                }
                UpdateStatusBar();
                if (setting.Sorting == Sorting.LastPlayed)
                {
                    UpdateList(DirtyLevel.ListItem);
                }
            }
            finally
            {
                Cursor.Current = preCursor;
            }
        }