Rockbox Technical Forums

Rockbox Development => Feature Ideas => Topic started by: Frankenpod on March 20, 2015, 08:11:46 AM

Title: Disk usage pie-chart?
Post by: Frankenpod on March 20, 2015, 08:11:46 AM
Just a suggestion for anyone who could write a plug-in - a way of displaying disk usage akin to how it works on windows (and on Macs I assume!), with a little coloured pie-chart - perhaps with different pie segments for different types of media (video/music/podcasts/free space/etc). 

Or if it's not that easy to differentiate between different types of media for this purpose, it could just show the sizes of the first level of folders (so 'podcasts' folder vs 'music' folder vs 'rockbox' folder, etc).

Title: Re: Disk usage pie-chart?
Post by: __builtin on March 20, 2015, 08:39:30 PM
This is totally doable. The 'stats' plugin gets all the data that's needed. Just add in a fancy drawing function and... *BOOM* ;)
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 23, 2015, 09:48:50 AM
Though, looking at it, the 'stats' plugin only reports number of files, rather than the disk space they use, so presumably it would need a slightly modified version of that plugin?  Can't be hard to collect size information while counting files though, surely?

Also, file-type I guess wouldn't distinguish between music and podcasts or audiobooks, which is why I was thinking maybe there could be an option of reporting the sizes of the top-level folders - though I don't know how common it is for poeple to organise their media files in 'music' 'podcast' 'audiobooks' folders.
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 28, 2015, 06:53:24 PM
Am very vaguely thinking I might try and implement this myself.  Though I might be being over-ambitious, as am not very skilled at c programming.  But, on the plus side, I don't think its a very demanding project.

Not sure if this is the right forum for the rest of this post, but...

Having installed the rockbox package, and looked at the code for the stats plug-in, it seems as if all it would take is making a modified version to total up the sizes of the files instead of just counting them.  And then another bit of code to draw a pie-chart.

But (and this is how out-of-my-depth I am), I don't know how to get the size of a file. 

Can one call linux system functions from within Rockbox (as I know that's one way to do it), or is that a silly question given the platforms it runs on?  I don't even understand this much - does Rockbox sit on a kind of linux 'layer' when its installed on a DAP or is it a totally stand-alone?

Otherwise does one have to open files and read to the end of them to find out their size?

This is a dumb question, I know, but to be fair, I think that's the only problematic bit of this idea, the rest seems pretty straightforward.
Title: Re: Disk usage pie-chart?
Post by: saratoga on March 28, 2015, 07:08:33 PM
But (and this is how out-of-my-depth I am), I don't know how to get the size of a file. 

The plugin API struct has a filesize function. 

Can one call linux system functions from within Rockbox (as I know that's one way to do it), or is that a silly question given the platforms it runs on?  I don't even understand this much - does Rockbox sit on a kind of linux 'layer' when its installed on a DAP or is it a totally stand-alone?

No theres no linux system in rockbox, but rockbox does have its own APIs.  Plugins are stricted to the functions exported by the plugin API:

http://git.rockbox.org/?p=rockbox.git;a=blob;f=apps/plugin.h;h=f781f60350d79f6438296900f525aa1dda61596c;hb=HEAD#l445

Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 29, 2015, 09:46:37 AM
Thanks - I'll give it a go (but don't hold your breath!).  Testing will be the tricky bit - there's an emulator, yes?  Will need to figure out how to get that working.
Title: Re: Disk usage pie-chart?
Post by: saratoga on March 29, 2015, 11:24:37 AM
Simulator, it doesn't emulate the hardware. Its compiled the same way as a device build except you choose simulator instead of normal build in the configure script.
Title: Re: Disk usage pie-chart?
Post by: __builtin on March 29, 2015, 11:42:17 AM
Thanks - I'll give it a go (but don't hold your breath!).  Testing will be the tricky bit - there's an emulator, yes?  Will need to figure out how to get that working.

HINT: You'll probably need some trig functions to do the drawing. Look in
Code: [Select]
lib/fixedpoint/fixedpoint.h for some fixed-point ones.
Title: Re: Disk usage pie-chart?
Post by: saratoga on March 29, 2015, 11:51:39 AM
Or use a bar chart if you want easy math :)
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 29, 2015, 12:34:38 PM
Thanks - I'll give it a go (but don't hold your breath!).  Testing will be the tricky bit - there's an emulator, yes?  Will need to figure out how to get that working.

HINT: You'll probably need some trig functions to do the drawing. Look in
Code: [Select]
lib/fixedpoint/fixedpoint.h for some fixed-point ones.

Cheers!  Probably will indeed need that.  I expect this will take me a while.
Title: Re: Disk usage pie-chart?
Post by: __builtin on March 29, 2015, 03:42:59 PM
If you need any help, feel free to ask on IRC.
Good luck! ;)
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 31, 2015, 08:27:42 AM
Not on IRC yet, so asking here!

To my surprise, first-draft (text output only) works in the simulator without trouble..despite not quite knowing what I'm doing.

But, have two stumbling blocks...

1/ Is there a rockbox API call to get the total size of the DAP's disk/flash storage?
2/ I'm struggling to understand the rockbox graphics functions - in particular, why is there an _array_ of screen objects, rather than just the one?  Which one do I use to draw graphics on?

Thanks.

Edit - hmm, have gotten a bar chart working, but only by hard-coding the total disk size, as I still can't work out where to get that information from.  Also still haven't quite worked out how to use IRC (never used it before, believe it or not).
Other issue is am not sure about type conversions - adding up disk usage in bytes leads to numbers too large for int or even long int.  Not sure whether to use floats instead or just to round to kb or Mb.
Title: Re: Disk usage pie-chart?
Post by: gevaerts on March 31, 2015, 03:52:46 PM
1/ Is there a rockbox API call to get the total size of the DAP's disk/flash storage?

No. I suspect you'd have to add this to fat.c and then export it in the plugin api.

Quote
2/ I'm struggling to understand the rockbox graphics functions - in particular, why is there an _array_ of screen objects, rather than just the one?

Because there can be more than one screen. Think remotes.

Quote
Which one do I use to draw graphics on?

SCREEN_MAIN, usually (unless you want to draw on the remote's screem)

Quote
Other issue is am not sure about type conversions - adding up disk usage in bytes leads to numbers too large for int or even long int.  Not sure whether to use floats instead or just to round to kb or Mb.

Going with 512-byte sectors isn't wrong, or you could try to get the FAT cluster size and use that as a unit. It depends on what you want disk usage to mean, actual bytes or used disk blocks.
Title: Re: Disk usage pie-chart?
Post by: __builtin on March 31, 2015, 05:40:49 PM
Other issue is am not sure about type conversions - adding up disk usage in bytes leads to numbers too large for int or even long int.  Not sure whether to use floats instead or just to round to kb or Mb.

You /could/ try using 64-bit integers (unsigned long long or uint64_t with <stdint.h>).
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 31, 2015, 06:18:01 PM
Other issue is am not sure about type conversions - adding up disk usage in bytes leads to numbers too large for int or even long int.  Not sure whether to use floats instead or just to round to kb or Mb.

You /could/ try using 64-bit integers (unsigned long long or uint64_t with <stdint.h>).

I did consider doing that - nut just, not being at all experienced at this, I wondered what the 'normal' way of dealing with such things would be.  At the moment I just round everything to kb.  Maybe I'll use long long, dunno!
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on March 31, 2015, 06:23:25 PM
1/ Is there a rockbox API call to get the total size of the DAP's disk/flash storage?

No. I suspect you'd have to add this to fat.c and then export it in the plugin api.

Quote
2/ I'm struggling to understand the rockbox graphics functions - in particular, why is there an _array_ of screen objects, rather than just the one?

Because there can be more than one screen. Think remotes.

Quote
Which one do I use to draw graphics on?

SCREEN_MAIN, usually (unless you want to draw on the remote's screem)

Quote
Other issue is am not sure about type conversions - adding up disk usage in bytes leads to numbers too large for int or even long int.  Not sure whether to use floats instead or just to round to kb or Mb.

Going with 512-byte sectors isn't wrong, or you could try to get the FAT cluster size and use that as a unit. It depends on what you want disk usage to mean, actual bytes or used disk blocks.

Thanks for answering!

As I'm not very expert in this, I think till I know enough to understand the fat.c explanation, I'll just ask the user to select a total disk size!
Its just to scale the bar correctly anyway.

Somehow I got the graph to draw without referring to the screen object. just with rp->lcd_... function calls.  Quite confused what the correct way to do it is.
Title: Re: Disk usage pie-chart?
Post by: __builtin on April 01, 2015, 04:59:22 PM
Somehow I got the graph to draw without referring to the screen object. just with rp->lcd_... function calls.  Quite confused what the correct way to do it is.

You probably want to use the lcd_* functions rather than the screen functions.
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on April 26, 2015, 04:00:55 PM
Haven't had time to continue on this - would like to figure out how to get that 'total storage space' figure, without having to ask user for it, but haven't time to work on it at moment, as its clearly more complicated than what I've so far done.

(Also, want to work out how to draw a prettier-looking bar chart!).
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on November 16, 2016, 10:53:21 AM
I did eventually get this working.

But without being able to face delving into the main Rockbox code to create a GetAvailableStorageSize() function, it isn't that useful!  As the space taken by 'audio' file types is larger than that of art or any other type by several orders of magnitude, a bar chart doesn't actually show very much (it just comes out all one colour - that of 'audio files' - with a tiny sliver on one end for other file types!).  Should have thought this through a bit more!

I also made an alternative version, which is more useful for me, but don't know if anyone else would have any use for it.

  Mainly, it looks at the top-level directory and works out the size of the first 10 folders it finds.  Which for me means it draws a chart showing the relative size of 'music' 'podcasts' 'audiobooks' and 'music podcasts' folders (and the rockbox folder).  In the absence of any 'content type' tag that rockbox can access, this seems a managable way to show the relative space of each content type - but it only works if people organise their files in that hierarchy.

The other thing is it takes a long time to add up the sizes, but then again, it takes quite a long time to work out the sizes of those folders within Windows, so that's not surprising.

Anyway, I've put it on my ipod even if its of absolutely no use to anyone else.  Needs a bit more refining anyway (is there any way to make the bar chart look prettier?  Any graduated fills or anything?)

And do people organise their media files in that kind of heirarchy?  Presumably some players don't allow arbitrary folder structures anyway?
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on November 16, 2016, 10:55:38 AM
Sample output (better version)
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on November 18, 2016, 06:09:47 PM
1/ Is there a rockbox API call to get the total size of the DAP's disk/flash storage?

No. I suspect you'd have to add this to fat.c and then export it in the plugin api.


I've almost got this bit working.  I added the function volume_size from disk.h to the plugin.h api so the plugin can use it.  It works perfectly in the simulator so can now show free/total disk space...but doesn't compile for an ipod target and the problem seems to be with the IF_MV part, which I assume is some sort of compiler macro for multi-volume targets?  It's a bit beyond my limited programming knowledge.

This macro is defined in mv.h.  I don't really care about multi-volume case, but obviously I don't want to do anything that will break something on other targets.

  Simply deleting the IF_MV part from the declaration of volume_size in plugin.h makes it compile and work on my ipods, but I'm suspect that's not the right thing to do as I don't know what it would do on a target that is multi_volume.

But with that IF_MV() part left in, the compiler throws up an error about there being too few close-brackets, and I'm not sure why it does so or how to fix it other than just removing it.  Anyone able to clarify this?  Thanks.

I was thinking the next thing to add might be to save the calculated figures to a little text file, and then the next time the plug-in is run it can check timestamps on directories and see if sizes actually need to be recalculated (as on a large storage player it takes a fair while).
Title: Re: Disk usage pie-chart?
Post by: Frankenpod on January 07, 2017, 08:35:55 AM
Guess I'll have to ask on IRC.  But don't want to till I'm sure I have time/inclination to actually work on this.

Curious as to how people generally organise their media files.  If most people do it as I do and use a top-level with folders by media-type, i.e. 'music', 'podcasts', 'audiobooks' folders (etc), then maybe this plugin might be of some use.  But if people just have, say, 'artist' as their top level, or have a single folder ('stuff') with everything in that, then just giving the size of the first N top-level folders won't be useful.