right use of MainTracksWindow.Focused

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

uziubalmy
Posts: 28
Joined: Thu Jun 07, 2012 5:01 pm

right use of MainTracksWindow.Focused

Post by uziubalmy »

EDIT:
WHATCH THE VIDEO:
http://youtu.be/LgWPce6FAUU


Hi,
this is my example the scenario:
I have 200 tracks in now playing and 50000 in the main track window.

The tracks in now playing are the recently added and I have to check them one per one if are ok with the other tracks in the main track window.

The problem was... when I use the Player.Next() the now playing window change the focus on the new track, but the main tracks window will remain focused on the old track untill I scroll to the new track or I use F5 (or refresh()) functionality.

I know that MainTracksWindow.Focused is what I need, in fact if I pass the correct Index to this property the main tracks Windows will focus to the right track.

THe problem now is: MainTracksWindow.Focused want a Index of AllVisibleSongList, that can have 10000+ of tracks. I can't find a way to have the index in a simple way, now I'm fetching all the AllVisibleSongList IDs and put them in an dictionary, and cache it for get fast the index of the Player.CurrentSong.ID in the Main track window. For fetch all the song it can take from 30sec to over ten minutes (!!!).

what is the right way for getting that index for use MainTracksWindow.Focused ?

Code: Select all

        private IDictionary<int,int> _cachedIds;

        private void btnNext_Click(object sender, EventArgs e)
        {
            using (var mm = new Biz.MM())
            {
                mm.App.Player.Next();

                if (_cachedIds == null || mm.App.AllVisibleSongList.Count != _cachedIds.Count())
                {
                    var count = mm.App.AllVisibleSongList.Count;
                    _cachedIds = new Dictionary<int, int>();

                    for (int i = 0; i < count; i++)
                    {
                        _cachedIds[i] = mm.App.AllVisibleSongList.get_Item(i).ID; //[color=#FF0000]THIS IS VERY SLOW[/color]
                        lblProgress.Text = string.Format("{0}/{1}", i, count);
                    }
                    lblProgress.Text = "";
                }

                var currentId = mm.App.Player.CurrentSong.ID;

                var index = _cachedIds.Single(k => k.Value == currentId).Key;
                
                mm.App.MainTracksWindow.Focused = index;
            }
        }
Last edited by uziubalmy on Fri Apr 03, 2015 1:53 am, edited 1 time in total.
uziubalmy
Posts: 28
Joined: Thu Jun 07, 2012 5:01 pm

Help MainTracksWindow.Focused

Post by uziubalmy »

Hi all,

I really need help with MainTracksWindow.Focused

I think I not able to explain well... so I make a video hoping it's more clear

the main problem is that I need to set MainTracksWindow.Focused, but it want an index that in my case is hard to find, becouse the track that I want to focus in the maintrackwindow is in the "now playing" list...

the video:
http://youtu.be/LgWPce6FAUU

here is the code

Code: Select all


  private IDictionary<int, int> _cachedIds;
        private int _cachedCount;
        private int _cachedIndex;

        private void btnNext_Click(object sender, EventArgs e)
        {
            using (var mm = new Biz.MM())
            {
                mm.App.Player.Next();

                if (_cachedIds == null || mm.App.AllVisibleSongList.Count != _cachedCount)
                {
                    _cachedCount = mm.App.AllVisibleSongList.Count;
                    _cachedIds = new Dictionary<int, int>();
                    _cachedIndex = 0;
                }

                int? index = null;
                var currentId = mm.App.Player.CurrentSong.ID;

                while (!index.HasValue)
                {
                    try
                    {
                        index = _cachedIds.Single(k => k.Value == currentId).Key;
                    }
                    catch
                    {
                        index = null;
                    }

                    if (!index.HasValue)
                    {
                        for (; _cachedIndex < _cachedCount; _cachedIndex++)
                        {
                            _cachedIds[_cachedIndex] = mm.App.AllVisibleSongList.get_Item(_cachedIndex).ID;
                            lblProgress.Text = string.Format("{0}/{1}", _cachedIndex, _cachedCount);
                            if (_cachedIds[_cachedIndex] == currentId)
                                break;
                        }
                        lblProgress.Text = "";
                    }
                }

                if (index.HasValue)
                    mm.App.MainTracksWindow.Focused = index.Value;
            }
        }
Post Reply