Our new official repo is on github
LCD Smartie version 5.6 is released!
Download it now: https://github.com/LCD-Smartie/LCDSmartie/releases

How to handle multiple plugin calls with persistent data

Discussing issues that occur during plugin development.

Moderators: _X7JAY7X_, caesar, IFR, mattcro, limbo

Post Reply
mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

How to handle multiple plugin calls with persistent data

Post by mattcro »

Hi all,

For my 1st attempt at a Smartie plugin, I'm trying to create a scroller that works like a cross between RevEng's width.dll and krisp's scroll.dll (from if/scroll/swap package). I'm using good old MS VC++. The plugin behaviour is as follows:

If the text to display is shorter than the specified width, it is simply returned as-is.

If the text is longer than the width allowed, it is scrolled in a loop, with an optional separator/padding string.

Usage: $dll(scrollpad.dll,1,width#separator,TextToDisplay)

eg:

Code: Select all

$dll(scrollpad.dll,1,20# ** ,$WinampTitle)
will display the title as static text if it's shorter than 20 characters, otherwise the title will scroll (loop) in a width of 20 characters, with " ** " as a separator between the end and start of the title. So you get

Code: Select all

ange ** Coldplay - W
instead of the normal behaviour

Code: Select all

angeColdplay - We Ne
in the title "Coldplay - We Never Change".

It's working fine so far, but problems arise when you have 2 or more calls to the dll on the same screen. The scroll position is declared as "static", but I need a way to distinguish between separate calls to the plugin so the scrolling is independent. I'm sort of figuring out various things as I go along, but can't spot any C/C++ source that does this (that I can understand). Open-source plugins, please!

Any hints and source snippets on keeping multiple instances of static/persistent variables separate would be appreciated!

I'm pretty green as far as C/C++ application programming is concerned (is it obvious from by source code?), having only done some C at uni (Electronics Eng) and some microcontroller stuff... I've based this plugin on code from Rev Eng and krisp - thanks for your contributions to Smartie!

Matt.

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

Uh, suppose I'd better upload the source code...

scrollpad.dll v0.2

This code is as per the post below

Matt
Last edited by mattcro on March 25th, 2006, 10:39 pm, edited 2 times in total.

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

As a quick and dirty workaround to multiple calls to scrollpad interfering with each other's scroll position, I've made multiple functions that do exactly the same thing, but with unique static variables for the scroll position (ie scrollpos1, scrollpos2...) so it works with more than one instance of scrollpad on a screen. I have a Winamp screen with scrolling artist on line 1 and scrolling track name on line 2, like so:

line 1:

Code: Select all

$dll(scrollpad,1,20# ** ,$dll(splittitle,1,$WinampTitle,dummy))
line 2:

Code: Select all

$dll(scrollpad,2,20# ** ,$dll(splittitle,2,$WinampTitle,dummy))
line 3:

Code: Select all

$dll(sandr.dll,1,$WinampStat,) $Right($dll(regexp,3,0:(\d*):#\1:#:(\d)#:0\1#0(\d\d)#\1,0:$WinampPosh),$5%)/$Right($dll(regexp,3,0:(\d*):#\1:#:(\d)#:0\1#0(\d\d)#\1,0:$WinampLengts),$5%) $Fill(15)$Right($WinampKBPS,$4%)k
line 4:

Code: Select all

CPU:$Right($CPUUsage%,$3%)%    Mem:$Right($MemU%,$3%)%
The sandr.dll on line 3 produces customchar play/pause/stop symbols, and the huge regexp code formats the current time/total time nicely.

Incidentally, the splittitle plugin mangles extended/accented characters (eg umlaut, grave, beta...) in the same way as swap/scroll/if, as I posted previously. This might be a "feature" of the string functions used... dotNet or something... trying to do unicode/multibyte characters.

Matt.

elesquiador
Plugin Author
Posts: 18
Joined: February 9th, 2007, 10:47 pm

Re: How to handle multiple plugin calls with persistent data

Post by elesquiador »

mattcro wrote: Any hints and source snippets on keeping multiple instances of static/persistent variables separate would be appreciated!
Based on the date, maybe you have solved this issue (other than using seperate function calls), but have you tried using an STL map container(C++)?

Code: Select all

#include <map>
static std::map<string, int> scroll; 

//Assume that the variables text and textpos store the string you are scrolling and the current position associated with that string
string text("sample");
int textpos = 4;

//now you can store and retrieve values using a text string as the subscript
scroll[text] = textpos;
int RetrievedTextPos = scroll[text];
This data structure should let you store and retrieve as many separate scroll positions as you'd like, all in one compact function.

SlithyToves
Posts: 5
Joined: June 4th, 2007, 1:56 am

Post by SlithyToves »

There may be a work-around for this, but is there a way to code the plugin so the scroll rate isn't tied to the dll check interval?
I like scrollpad and want to use it, but the spectrum analyzer doesn't look good that slow.

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

I haven't looked at my scrollpad plugin for a while (it's been doing all I want). The scroll rate is determined by the Smartie refresh interval, which I have at 250ms. That's great for scrolling text, but yes, rubbish for spectrum display...

I think the min refresh interval in scrollpad is set very low - it probably should be more like 200ms. Would that affect the scroll rate with a fast display refresh? How about if the DLL check rate in Smartie is set very low?

Another option is to add a parameter to the plugin parameter string that specifies a scroll rate divisor, so if the Smartie refresh interval were 100ms and I set a divisor of 3, scrollpad's output would scroll one step every 300ms.

Hmm, I'll have to do some experimenting.

mattcro
Forum Supporter
Posts: 590
Joined: March 8th, 2006, 1:58 pm
Location: Scotland

Post by mattcro »

I've had a play with the code again and set the min DLL check interval to a sensible value. It seems to work well now if the Smartie refresh interval or DLL interval is set low. Previously it scrolled as fast as it could, as SlithyToves found out!

See http://forums.lcdsmartie.org/viewtopic.php?p=12787 for the new version.

Post Reply