コード例 #1
0
        protected virtual string GetDrawString(IMusicInfo item)
        {
            if (item == null)
                return null;

            return string.Format("{0}. {1}", item.ID, item.Name);
        }
コード例 #2
0
ファイル: MusicManager.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Stops the currently playing music.
        /// </summary>
        public void Stop()
        {
            if (_playing == null)
            {
                return;
            }

            try
            {
                _playing.Dispose();
            }
            catch (InvalidOperationException ex)
            {
                const string errmsg = "Failed to dispose music `{0}` [`{1}`] (can potentially ignore). Exception: {2}";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, _playing, _playingInfo, ex);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to dispose music `{0}` [`{1}`]. Exception {2}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, _playing, _playingInfo, ex);
                }
                Debug.Fail(string.Format(errmsg, _playing, _playingInfo, ex));
            }
            finally
            {
                _playing     = null;
                _playingInfo = null;
            }
        }
コード例 #3
0
        protected virtual string GetDrawString(IMusicInfo item)
        {
            if (item == null)
            {
                return(null);
            }

            return(string.Format("{0}. {1}", item.ID, item.Name));
        }
コード例 #4
0
ファイル: StringUtils.cs プロジェクト: OronDF343/Sky-Jukebox
        private static string ParseWithFallback(IMusicInfo m, string h)
        {
            // we have $xx or $xx(...)
            // get the value of $xx:
            string s;
            try { s = FormatElements[h.Substring(0, 3)](m); }
            catch { s = ""; }

            // if there is no need to fallback, return the value
            if (!string.IsNullOrWhiteSpace(s)) return s;

            // we need to fallback
            // if we don't have a fallback, return a default string
            // if we do, lets use our regex to parse it, recursively calling this method where needed
            return h.Length < 5 ? "[Unknown]" : Regex.Replace(h.Substring(4, h.Length - 5), RegexString, match => ParseWithFallback(m, match.Value));
        }
コード例 #5
0
 public static string FormatHeader(IMusicInfo m, string h)
 {
     try
     {
         // use our regex to parse this, call ParseWithFallback to evaluate variables and fallback
         var r = Regex.Replace(h, RegexString, match => ParseWithFallback(m, match.Value));
         // unescape the remaining characters
         // find:
         // \$       find $
         // (.)      followed by one character (any) -> to capture group 1 [that is what the () are for]
         // replace:
         // $1       replace with capture group 1
         return(Regex.Replace(r, @"\$(.)", @"$1"));
     }
     catch
     {
         return("[Format Error]");
     }
 }
コード例 #6
0
ファイル: StringUtils.cs プロジェクト: OronDF343/Sky-Jukebox
 public static string FormatHeader(IMusicInfo m, string h)
 {
     try
     {
         // use our regex to parse this, call ParseWithFallback to evaluate variables and fallback
         var r = Regex.Replace(h, RegexString, match => ParseWithFallback(m, match.Value));
         // unescape the remaining characters
         // find:
         // \$       find $
         // (.)      followed by one character (any) -> to capture group 1 [that is what the () are for]
         // replace:
         // $1       replace with capture group 1
         return Regex.Replace(r, @"\$(.)", @"$1");
     }
     catch
     {
         return "[Format Error]";
     }
 }
コード例 #7
0
        private static string ParseWithFallback(IMusicInfo m, string h)
        {
            // we have $xx or $xx(...)
            // get the value of $xx:
            string s;

            try { s = FormatElements[h.Substring(0, 3)](m); }
            catch { s = ""; }

            // if there is no need to fallback, return the value
            if (!string.IsNullOrWhiteSpace(s))
            {
                return(s);
            }

            // we need to fallback
            // if we don't have a fallback, return a default string
            // if we do, lets use our regex to parse it, recursively calling this method where needed
            return(h.Length < 5 ? "[Unknown]" : Regex.Replace(h.Substring(4, h.Length - 5), RegexString, match => ParseWithFallback(m, match.Value)));
        }
コード例 #8
0
        /// <summary>
        /// 为各个属性加权重  选出权重最高的返回
        /// </summary>
        /// <param name="musics"></param>
        /// <param name="music"></param>
        /// <returns></returns>
        public IMusicInfo GetMatchMusic(List <IMusicInfo> musics, IMusicInfo music)
        {
            Dictionary <IMusicInfo, double> weighdic = new Dictionary <IMusicInfo, double>();

            musics.ForEach(item => {
                double w = 0;
                //歌名 权重5
                w += GetCompareResult(music.name, item.name) * 5;
                //专辑 权重2
                w += GetCompareResult(music.album, item.album) * 5;
                //时长权重 5
                w           -= (Math.Abs(TimeConverter.ToSecondDouble(item.time) - TimeConverter.ToSecondDouble(music.time)) / TimeConverter.ToSecondDouble(item.time)) * 5;
                var singer_a = String.Join(",", from a in item.singers select a.name);
                var singer_b = String.Join(",", from a in music.singers select a.name);
                //歌手 权重10
                w += GetCompareResult(singer_b, singer_a) * 10;
                weighdic.Add(item, w);
            });
            return(weighdic.OrderByDescending(w => w.Value).Where(a => a.Value > 0).FirstOrDefault().Key);
        }
コード例 #9
0
 /// <summary>
 /// Plays a music track.
 /// </summary>
 /// <param name="musicManager">The music manager.</param>
 /// <param name="info">The <see cref="IMusicInfo"/> to play.</param>
 /// <returns>
 /// True if the music played successfully; otherwise false.
 /// </returns>
 public static bool Play(this IMusicManager musicManager, IMusicInfo info)
 {
     return musicManager.Play(info.ID);
 }
コード例 #10
0
 /// <summary>
 /// Plays a music track.
 /// </summary>
 /// <param name="musicManager">The music manager.</param>
 /// <param name="info">The <see cref="IMusicInfo"/> to play.</param>
 /// <returns>
 /// True if the music played successfully; otherwise false.
 /// </returns>
 public static bool Play(this IMusicManager musicManager, IMusicInfo info)
 {
     return(musicManager.Play(info.ID));
 }
コード例 #11
0
ファイル: MusicManager.cs プロジェクト: wtfcolt/game
 /// <summary>
 /// Gets the file path for a music file.
 /// </summary>
 /// <param name="musicInfo">The <see cref="IMusicInfo"/> to get the file path for.</param>
 /// <returns>The file path for the <paramref name="musicInfo"/>.</returns>
 protected static string GetFilePath(IMusicInfo musicInfo)
 {
     return(ContentPaths.Build.Music.Join(musicInfo.Name + ContentPaths.ContentFileSuffix));
 }
コード例 #12
0
ファイル: MusicManager.cs プロジェクト: wtfcolt/game
        /// <summary>
        /// Plays a music track by the given <see cref="MusicID"/>.
        /// </summary>
        /// <param name="id">The ID of the music to play.</param>
        /// <returns>
        /// True if the music played successfully; otherwise false.
        /// </returns>
        public bool Play(MusicID id)
        {
            try
            {
                // If the music is already playing, continue to play it
                if (_playingInfo != null && _playingInfo.ID == id)
                {
                    if (_playing.Status != SoundStatus.Playing)
                    {
                        _playing.Play();
                    }

                    return(true);
                }

                // Stop the old music
                Stop();

                // Get the info for the music to play
                var info = GetMusicInfo(id);
                if (info == null)
                {
                    return(false);
                }

                // Start the new music
                _playingInfo = info;

                var file = GetFilePath(info);
                try
                {
                    _playing = new Music(file);
                }
                catch (LoadingFailedException ex)
                {
                    const string errmsg = "Failed to load music `{0}`: {1}";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, info, ex);
                    }
                    Debug.Fail(string.Format(errmsg, info, ex));

                    _playing     = null;
                    _playingInfo = null;

                    return(false);
                }

                // Set the values for the music and start playing it
                _playing.Volume             = Volume;
                _playing.Loop               = Loop;
                _playing.RelativeToListener = true;
                _playing.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play music with ID `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, id, ex);
                }
                Debug.Fail(string.Format(errmsg, id, ex));
            }

            return(true);
        }
コード例 #13
0
ファイル: MusicManager.cs プロジェクト: mateuscezar/netgore
 /// <summary>
 /// Gets the file path for a music file.
 /// </summary>
 /// <param name="musicInfo">The <see cref="IMusicInfo"/> to get the file path for.</param>
 /// <returns>The file path for the <paramref name="musicInfo"/>.</returns>
 protected static string GetFilePath(IMusicInfo musicInfo)
 {
     return ContentPaths.Build.Music.Join(musicInfo.Name + ContentPaths.ContentFileSuffix);
 }
コード例 #14
0
ファイル: MusicManager.cs プロジェクト: mateuscezar/netgore
        /// <summary>
        /// Stops the currently playing music.
        /// </summary>
        public void Stop()
        {
            if (_playing == null)
                return;

            try
            {
                _playing.Dispose();
            }
            catch (InvalidOperationException ex)
            {
                const string errmsg = "Failed to dispose music `{0}` [`{1}`] (can potentially ignore). Exception: {2}";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, _playing, _playingInfo, ex);
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to dispose music `{0}` [`{1}`]. Exception {2}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, _playing, _playingInfo, ex);
                Debug.Fail(string.Format(errmsg, _playing, _playingInfo, ex));
            }
            finally
            {
                _playing = null;
                _playingInfo = null;
            }
        }
コード例 #15
0
ファイル: MusicManager.cs プロジェクト: mateuscezar/netgore
        /// <summary>
        /// Plays a music track by the given <see cref="MusicID"/>.
        /// </summary>
        /// <param name="id">The ID of the music to play.</param>
        /// <returns>
        /// True if the music played successfully; otherwise false.
        /// </returns>
        public bool Play(MusicID id)
        {
            try
            {
                // If the music is already playing, continue to play it
                if (_playingInfo != null && _playingInfo.ID == id)
                {
                    if (_playing.Status != SoundStatus.Playing)
                        _playing.Play();

                    return true;
                }

                // Stop the old music
                Stop();

                // Get the info for the music to play
                var info = GetMusicInfo(id);
                if (info == null)
                    return false;

                // Start the new music
                _playingInfo = info;

                var file = GetFilePath(info);
                try
                {
                    _playing = new Music(file);
                }
                catch (LoadingFailedException ex)
                {
                    const string errmsg = "Failed to load music `{0}`: {1}";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, info, ex);
                    Debug.Fail(string.Format(errmsg, info, ex));

                    _playing = null;
                    _playingInfo = null;

                    return false;
                }

                // Set the values for the music and start playing it
                _playing.Volume = Volume;
                _playing.Loop = Loop;
                _playing.RelativeToListener = true;
                _playing.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play music with ID `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, id, ex);
                Debug.Fail(string.Format(errmsg, id, ex));
            }

            return true;
        }