Rockbox Technical Forums

Rockbox Development => Feature Ideas => Topic started by: fduniho on May 03, 2012, 07:36:18 AM

Title: Place Database on External Card When Available
Post by: fduniho on May 03, 2012, 07:36:18 AM
I'm using a SanDisk Clip Zip, which allows me to supplement its internal memory with external microSDHC cards. But I have more music than will fit on one card. So I sometimes need to switch cards. Each time I switch cards, I need to recompute the database from scratch if I want to browse the new card with the database.

This hassle could easily be eliminated with a small change to the code for saving and loading the database. When an external card is present, load the database from the card and save it to the card. When one isn't present, use the player's internal memory. This would allow each card to have its own database, so that when you switched cards, the player would load the right database without any need to recompute it, and if you took the card out, it would load a database that lists only the music still left in the player's internal memory.
Title: Re: Place Database on External Card When Available
Post by: Llorean on May 03, 2012, 12:28:09 PM
You still need to determine if the music on internal storage has been changed since that card was last inserted, or if that card's music has been changed since Rockbox last updated its database. It's not as simple as it seems on first thought.
Title: Re: Place Database on External Card When Available
Post by: torne on May 03, 2012, 12:53:42 PM
This has been suggested before. As well as Llorean's note that you still need to update the separate database files, currently the way the database indexes work would make this tricky to implement (since each index expects to have all the data from A to Z in order; having two indexes on different devices would probably mean reading both in parallel and merging them - a complexity the code doesn't have right now, and probably especially difficult for the case when the DB is not loaded to ram at boot).

It's a reasonable idea in principle, but the database code is complicated and understood by few people, so don't expect it to actually happen unless you implement it :)
Title: Re: Place Database on External Card When Available
Post by: fduniho on May 03, 2012, 08:32:36 PM
What I'm suggesting is simpler than what you're describing. There should be no need to merge two databases. I am suggesting that when there is a card inserted, the player should ignore the database stored on the player's internal memory and just read and write the database from and to the external card. And when there is no card, it should read and write the database from and to the internal memory.

While my player's own firmware checks for changes each time I boot it up, Rockbox has not been doing that. I can create a database for one card, insert another without changing the database, then replace it with the previous card and still have the database for that card. For example, I was out exercising earlier with the card that has psy trance on it, but I didn't need to change the database, because I was using a previously created playlist. I just took that card out and put in the card with classical music, and the database still reflects what is on that card instead of the one I was last listening to. I'm not familiar with all the options in the database context menu, but I have mainly been using "Initialize Now" to create the database afresh. This creates a database of all the music on both the player itself and the card, and it apparently stores this database on the player. All I'm suggesting is a change in location of the full database file when a card is inserted. There would be duplication of information, but that's simpler than trying to merge two databases, which is not at all what I've been suggesting.
Title: Re: Place Database on External Card When Available
Post by: torne on May 04, 2012, 09:33:45 AM
That has a different problem instead, which is that you'd need to update the database on *every card* when the music on the player has changed. It seems plausible, but there'd still need to be some changes to the database for it to be able to notice the card being removed and reload itself.
Title: Re: Place Database on External Card When Available
Post by: fduniho on May 04, 2012, 12:46:37 PM
Yes, when you update the internal memory, the database would have to be updated for every card. But this would not increase the frequency with which you need to update the database. You would have to update the database on each card only as you put it in. This is no different than how things already are. But here is the difference. When you update the contents of a card, only the database for that card would have to be updated, and you could freely switch cards without updating the database each time. Overall, it would decrease the frequency with which the database needs to be updated.
Title: Re: Place Database on External Card When Available
Post by: torne on May 05, 2012, 07:01:43 AM
My point was that the right way to handle this is to actually split the database as I assumed you meant, and that doing the work to make it store the database on the card the way you suggest may not be sufficient of an advantage to be worthwhile.
Title: Re: Place Database on External Card When Available
Post by: fduniho on May 05, 2012, 09:37:02 AM
Yes, splitting the database would probably be best. It avoids duplication of data and minimizes the number of times the database needs to be updated. I have downloaded the source to Ubuntu with git, and I already know C, but I've never developed for Rockbox, and I've mainly been programming in PHP. So it may be a while before I identify the right code and understand what it is doing. If you can tell me what files and functions I should be looking at, it would help.
Title: Re: Place Database on External Card When Available
Post by: bodymind on August 23, 2012, 06:53:46 AM
bump!! guys i want to do this feature it is extremely useful! I will start looking into the code this days..

anyway what I read from you guys I believe that the best would be when a card is attached, the database would be merged and copied again to the RAM!

it still has the problem that each index is from A to Z.. but I will start looking into code later.

there is this patch:
http://www.rockbox.org/tracker/task/12474

or we can have a different approach, making a centralized DB of all SD cards.
This could be done, by adding a new element to the database like a "serial number" of the SD card, and hidding and showing this elements everytime we connect/disconnect a new SD card!
what do you think?