Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: WSH Panel Mod (Read 803849 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

WSH Panel Mod

Reply #75
Thanks, I got it working

I'm just wondering about window.CreateTimerTimeout/Interval, and window.KillTimer, how do they work exactly? I had thought they'd be able to run some code after a delay, but I can't figure out the syntax. For example, is it possible to repaint the window more than once per second?

Thanks again.

WSH Panel Mod

Reply #76
Okay I got it working

I use the 1.1.4 version of the plugin.

If you create a WSH Panel with the following code:
Code: [Select]
var DT_TOP = 0x00000000;
var DT_LEFT = 0x00000000;
var DT_CENTER = 0x00000001;
var DT_RIGHT = 0x00000002;
var DT_VCENTER = 0x00000004;
var DT_BOTTOM = 0x00000008;
var DT_WORDBREAK = 0x00000010;
var DT_SINGLELINE = 0x00000020;
var DT_EXPANDTABS = 0x00000040;
var DT_TABSTOP = 0x00000080;
var DT_NOCLIP = 0x00000100;
var DT_EXTERNALLEADING = 0x00000200;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;
var DT_INTERNAL = 0x00001000;
var DT_EDITCONTROL = 0x00002000;
var DT_PATH_ELLIPSIS = 0x00004000;
var DT_END_ELLIPSIS = 0x00008000;
var DT_MODIFYSTRING = 0x00010000;
var DT_RTLREADING = 0x00020000;
var DT_WORD_ELLIPSIS = 0x00040000;
var DT_NOFULLWIDTHCHARBREAK = 0x00080000;
var DT_HIDEPREFIX = 0x00100000;
var DT_PREFIXONLY = 0x00200000;

function RGB(r,g,b){
return (0xff000000|(r<<16)|(g<<8)|(b));
}

function RGBA(r,g,b,a){
return ((a<<24)|(r<<16)|(g<<8)|(b));
}

function TimeFmt(t){
var zpad = function(n){
var str = n.toString();
return (str.length<2) ? "0"+str : str;
}
var h = Math.floor(t/3600); t-=h*3600;
var m = Math.floor(t/60); t-=m*60;
var s = Math.floor(t);
if(h>0) return h.toString()+":"+zpad(m)+":"+zpad(s);
return m.toString()+":"+zpad(s);
}

var g_font = gdi.Font("Arial",12,0);
var g_fileinfo = null;

var g_drag = 0;
var g_drag_seek = 0;

// --- APPLICATION START

function on_paint(gr){
var ww = window.Width;
var wh = window.Height;
var pos = 0;
var length = fb.PlaybackLength;
var txt;

if(length > 0){
if(g_drag){
pos = window.Width * g_drag_seek;
txt = "Seek " + TimeFmt(g_drag_seek * length) + " / " + TimeFmt(length);
}
else{
pos = window.Width * (fb.PlaybackTime / length);
var percentage = 100*fb.PlaybackTime/fb.PlaybackLength;
txt = percentage.toString().substr(0,4) + "%";
}
}

gr.FillGradRect(  0, 0,    pos, wh/2, 270, RGB(64,192,192), RGB(0,64,64));
gr.FillGradRect(  0,wh/2,    pos, wh/2+1, 90, RGB(64,192,192), RGB(0,64,64));
gr.FillGradRect(pos, 0, ww-pos, wh/2, 270, RGB(96,96,96), RGB(16,16,16));
gr.FillGradRect(pos, wh/2, ww-pos, wh/2+1, 90, RGB(96,96,96), RGB(16,16,16));



gr.DrawRect(0,0, ww, wh, 4.0, RGB(0,0,0));

gr.GdiDrawText(txt, g_font, RGB(255,255,255), 0, 0, ww, wh, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}

function on_mouse_lbtn_down(x,y){
g_drag = 1;
}

function on_mouse_lbtn_up(x,y){
if(g_drag){
g_drag = 0;
g_drag_seek = x / window.Width;
g_drag_seek = (g_drag_seek<0) ? 0 : (g_drag_seek<1) ? g_drag_seek : 1;
fb.PlaybackTime = fb.PlaybackLength * g_drag_seek;
}
}

function on_mouse_move(x,y){
if(g_drag){
g_drag_seek = x / window.Width;
g_drag_seek = (g_drag_seek<0) ? 0 : (g_drag_seek<1) ? g_drag_seek : 1;
window.Repaint();
}
}

function on_playback_new_track(info){
window.Repaint();
}

function on_playback_stop(){
window.Repaint();
}

function on_playback_seek(time){
window.Repaint();
}

function on_playback_time(time){
window.Repaint();
}

// --- APPLICATION END

Everything is as I want it to be.

But if I use the following code in a WSH Panel a black line appears and disappears where in the middle:

Code: [Select]
gr.FillGradRect(this.left, this.top, pos, this.h/2, 270, RGBA(64,192,192, 255), RGBA(31, 50, 63, 255));
gr.FillGradRect(this.left, this.top+5, pos, this.h/2+1, 90, RGBA(64,192,192, 255), RGBA(31, 50, 63, 255));
gr.DrawRect(this.left, this.top, this.w, this.h, 2.0, RGBA(0, 0, 0, 255));

The seekbars height is 12.

 

WSH Panel Mod

Reply #77
I found out how to read from a text file:

Code: [Select]
var fso, f1, ts, s;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", true);
// Write a line.
fb.trace("Writing file");
f1.WriteLine("Hello World");
f1.WriteBlankLines(1);
f1.Close();
// Read the contents of the file.
fb.trace("Reading file");
ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
s = ts.ReadLine();
fb.trace("File contents = '" + s + "'");
ts.Close();

More here. Note: I had to change Response.Write to fb.trace. I haven't explored it hugely, I don't know how to make scroll bars, which would be necessary for large files.

Such an awesome component.

WSH Panel Mod

Reply #78
Quote
I'm just wondering about window.CreateTimerTimeout/Interval, and window.KillTimer, how do they work exactly?

  Both window.CreateTimerTimeout() and window.CreateTimerInterval() will create an instance of ITimerObj.
The difference is: windowCreateTimerTimeout(timeout), will make timer event occur only once after the timeout(ms), at the same time, window.CreateTimerInterval(delay), will make timer event occur every delay(ms). 
Once the Timer object is created, when timer event is coming, WSH Panel Mod will invoke on_timer(id) callback function. The id number (id is unique which can indentify which timer event is coming) is assigned by system, you can use ITimerObject.ID to access it.
Since the window.CreateTimerInterval() will create a periodic timer object, so you should use window.KillTimer() to terminate it manually (Recommended way), or assign the timer object to null, then call CollectGarbate() in JScript (I don't know about VBScript, you know, because of GC, the object won't be destroyed as soon as it's null or reference counter is 0).

Quote
I had thought they'd be able to run some code after a delay, but I can't figure out the syntax. For example, is it possible to repaint the window more than once per second?

You can do that with Timer, however, I think it may cause performance issues.

Quote
But if I use the following code in a WSH Panel a black line appears and disappears where in the middle:
...

  Please post a full list of your script.


Quote
I found out how to read from a text file:
...

  I've noticed that some people will disable FSO, so you should use try...catch... statement to make it more safe to use.


EDIT: Cleanup

WSH Panel Mod

Reply #79
WSH Panel Mod 1.1.6 Released.

@TomBarlow:
Now there's an example for timers (named Timer.txt) comes with Samples-1.1.6.7z.

WSH Panel Mod

Reply #80
@Spirit_of_the_ocean
I know what you're talking about. Had the same problems with gr.FillGradRect.

Try the following (just change some small values )
Code: [Select]
gr.FillGradRect(this.left, this.top, pos, this.h/2+1, 90, RGBA(31, 50, 63, 255), RGBA(64,192,192, 255));
gr.FillGradRect(this.left, this.top+this.h/2, pos, this.h/2, 270, RGBA(31, 50, 63, 255), RGBA(64,192,192, 255));
gr.DrawRect(this.left, this.top, this.w, this.h, 2.0, RGBA(0, 0, 0, 255));

WSH Panel Mod

Reply #81
Well, in fact, I didn't embed SciTE, it's Scintilla...

yes i meant scintilla as you might imagine, and scintilla in the first place accepts .api way for calltips and autocompletition like SciTE through it. it was small suggestion in time when you were updating built-in editor, so i thought it would be nice feature.*

anyhow this popups everytime i put WSH panel in dockable panels:

Code: [Select]
Init Scripting Engine Failed (0x800401f3): Invalid class string

If you are seeing this error message, it's probably caused by a container which should have extension_base::set_config() been called on panel creation.

it's probably dockable panels problem, but i just wanted to inform about this behaviour in case you didn't noticed it

*i just now saw your reply

WSH Panel Mod

Reply #82
@2E7AH:
The message is intended to show up when "Script Engine" of WSH Panel is missing.

WSH Panel Mod

Reply #83
ok, i don't want to go exploring jscript right now so i have a simple question regarding NEMO7538's rating script:
the question is how can i know that selected track (although i changed that to now playing track) is in library or not

i want to change this:
[font= "Courier New"]bool = fb.RunContextCommandWithMetadb("Rating/"+((lrating==0) ? "<not set>" : lrating),g_metadb);[/font]

to this if the track isn't in library (and can't be rated):
[font= "Courier New"]bool = fb.RunContextCommandWithMetadb("Playback Statistics (SQL)/Ratings/"+((lrating==0) ? "<not set>" : lrating),g_metadb);[/font]

[edit] it was easy: i put the the last string after [font= "Courier New"]if (g_metadb)...[/font] bracket

WSH Panel Mod

Reply #84
@2E7AH
I'm not very familiar with JScript.
Could you please post your entire modified rating script?
I want to to replace my rating panel made in TIM in the DarkOne config with WSH Panel mod and still haven't got luck until today...

WSH Panel Mod

Reply #85
sure tedgo  here it is:

Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_drag = 0;
var bool;
var g_metadb;
var imgname;
var rating;
var rating_;
var nrating;
var lrating;
var img;
var hofset=16;
var imgw=16;
var g_tfo = fb.TitleFormat("%rating%");
var g_tfo_ = fb.TitleFormat("%rating_sql%");

on_item_focus_change();

function on_paint(gr){
if (g_metadb) {
for (i = 1; i < 6; i++) {
if (rating > 0) {
img = gdi.image(fb.FoobarPath + "Images\\" + ((i > (g_drag ? lrating : rating)) ? "NoStar" : "Star" +  (g_drag ?  "-hover" : "")) + ".png");
}
else
img = gdi.image(fb.FoobarPath + "Images\\" + ((i > (g_drag ? lrating : rating_)) ? "NoStar" : "Star" +  (g_drag ?  "-hover" : "")) + ".png");
gr.DrawImage(img, hofset+imgw*(i-1), 4, 20, 16, 0, 0, 20, 16);
}
}
}

function on_mouse_wheel(delta){}

function on_mouse_lbtn_up(x,y){
if (lrating != rating) {
if (g_metadb) {
bool = fb.RunContextCommand("Rating/"+((lrating==0) ? "<not set>" : lrating));
}
}
if (lrating != rating | lrating == 0) {
if (g_metadb) {
bool = fb.RunContextCommand("Playback Statistics (SQL)/Ratings/"+((lrating==0) ? "<not set>" : lrating));
}
}
}

function on_mouse_move(x, y) {
if (g_metadb) {
g_drag = 1;
nrating = Math.ceil((x-hofset)/imgw);
if (nrating > 5) nrating = 5;
if (nrating != lrating) {
lrating = nrating;
window.Repaint();
}
}
}

function on_mouse_leave() {
on_metadb_changed()
}

function on_item_focus_change() {
if (g_metadb) {window.UnwatchMetadb();
}
g_metadb = fb.GetFocusItem();
if (fb.IsPlaying | fb.IsPaused) g_metadb = fb.GetNowPlaying();
if (g_metadb) {
on_metadb_changed();
window.WatchMetadb(g_metadb);
}
}

function on_metadb_changed() {
g_drag = 0;
rating = g_tfo.EvalWithMetadb(g_metadb);
rating_ = g_tfo_.EvalWithMetadb(g_metadb);
if (rating == "?") {rating = 0;} lrating = rating;
window.Repaint();
}

function on_playback_new_track(metadb) {on_item_focus_change();}
but it's custom to my layout and habits
i don't have a clue about jscript, i only rearanged NEMO7538's code to suite my needs and that is:
 - now playing item instead selected
 - i arrange outside library item's ratings with sql rating and library item's ratings with both sql and official ratings (mainly official)

- if some library item has both sql and official rating, than the official rating will show in wsh (and it's actions will reflect that) and if you reset the offical rating then sql rating will show and wsh actions will reflect accordingly
- official ratings have preference over sql on library items
it will be easier to get use to it if you try it than i explaining

and again it sure can be done in more elegant way by someone who knows jscript and is willing to incorporate offical rating and sql ratins in some logical way, but also this works

[edit]
little change to avoid startup error when hover over wsh and nothing is played
but still can't figure why (line 66/67) script isn't redirecting to selected track when nothing is played

WSH Panel Mod

Reply #86
Looks like exactly what i need (nearly at least )
Thanks!
Now i have a starting point for my rating panel.

I have to enhance it with my different star colours though...
(white for ratings in tags, blue for auto-rating - which i have to insert totally in this script - , yellow for ratings in a database, green for playcount mode)
Will get headache about it still... 

WSH Panel Mod

Reply #87
probably headache

you'll have to define variables for all those tags like in example:

[font= "Courier New"]var g_tfo = fb.TitleFormat("%rating%");
var g_tfo_ = fb.TitleFormat("%rating_sql%");
...[/font]

and change appropriate strings in the script

and then about the color: the script is made in such a way that it accepts nostar.png, star.png and star-hover.png but star and star-hover are connected in this way:

[font= "Courier New"]"NoStar" : "Star" + ... "-hover" ...[/font]

which means that if you want custom star, lets say it is named star_blue.png

[font= "Courier New"]"NoStar" : "Star_blue" + ... "-hover" ...[/font]

you'll have to make also star_blue-hover (not just star-hover) so that script will work
or you can sit and learn jscript or the script/component author will appear and help

WSH Panel Mod

Reply #88
Oh the author helped me in the past a lot.
I'll try to learn jscript so i will do it on my own (or cry for help again... ).

Thanks for your hints
The problem is, i don't use playcount_sql but the official one and so fb.TitleFormat("%rating%") is the same for tags and database...
Therefore I can't use it that way. I'll have to do it with fileinfo and metadb instead (i think).

WSH Panel Mod

Reply #89
T.P. Wang, thanks for the timer example, it works nicely. Not too resource hungry either- using window.Repaint() seems to work ok under on_mouse_move, which is probably repainting the window even more frequently.

Would you be able to add support for artist images? You might need this post. Also, should WSH Panel be able to get art from that new foo_covers component (here)?

Thanks!

WSH Panel Mod

Reply #90
@TomBarlow:
Artist images support is already included in WSH Panel Mod 1.1.7 Alpha (Public version will be released several days later).If you have interest in the Alpha version, please P.M me your email address.

Quote
should WSH Panel be able to get art from that new foo_covers component?

Sure, you can try it now 

WSH Panel Mod

Reply #91
Thanks for the offer, but foo_covers breaks embedded art, so I can't use it, but I kind of need it to specify where my artist images are. I'm not sure where to put them in my config either! The other alternative is writing a script to find the artist pics...

Oh and a small thing, when a wsh panel is positioned in a panel stack splitter with the $movepanel function, the context menu doesn't show up (i.e. Configure...). Is there anything you can do about that? I realise it could be out of your hands, but other panels seem to work OK...

WSH Panel Mod

Reply #92
Quote
Oh and a small thing, when a wsh panel is positioned in a panel stack splitter with the $movepanel function, the context menu doesn't show up (i.e. Configure...). Is there anything you can do about that? I realise it could be out of your hands, but other panels seem to work OK...

I believe it's one bug of PSS that doesn't handle extension_base:get_menu_items() well.

WSH Panel Mod

Reply #93
The following code in WSH panel mod let fb2k crash:

Code: [Select]
function on_playback_new_track(metadb)
{
        var fileInfo=metadb.GetFileInfo();
        
        var value = fileInfo.InfoValue(fileInfo.InfoFind("any invalid value"));
}

It's possible that it also happens with MetaValue/MetaFind. I didn't check it.

WSH Panel Mod

Reply #94
Hi,

i'm just trying to use this powerfull component, but i'm not yet familiar to Jscript enough ...

i want to modify the rating script of NEMO (post #40 : http://www.hydrogenaudio.org/forums/index....t&p=625796)
to update the RATING TAG in the file, not in the db

can someone give me some help please ?

i think i have to replace the methods used by the methods found in the doc :

interface IFbMetadbHandle {
Properties:
   (readonly) String Path;
   (readonly) String RawPath;
   (readonly) int SubSong;
   (readonly) int64 FileSize;
   (readonly) double Length;
   
Methods:
   IFbFileInfo GetFileInfo();
   void UpdateFileInfo(IFbFileInfo);
   // It's encouraged to use this method if you want to update tags
   // if value is a empty string, field will be removed
   void UpdateFileInfoSimple(field1, value1 [, file2, value2 [,...] ]);
}


so, i've replace :

function on_mouse_lbtn_up(x,y){
// fb.trace("button up");
if (lrating !=rating) {if (g_metadb) {
bool = fb.RunContextCommandWithMetadb("Rating/"+((lrating==0) ? "<not set>" : lrating),g_metadb);
}}
}

by

function on_mouse_lbtn_up(x,y){
// fb.trace("button up");
if (lrating !=rating) {if (g_metadb) {
bool = fileInfo.UpdateFileInfoSimple(RATING,lrating);
}}
}

and added in on_paint function this :

var fileInfo=g_metadb.GetFileInfo();

Jscript error on click stars


WSH Panel Mod

Reply #95
Hmm it's hard to tell without the full script, what does the console say when you get an error?

You might be better off defining fileInfo under on_item_focus_change rather than on_paint. I'm not sure really I haven't explored this side of the WSH panel.

WSH Panel Mod

Reply #96
i've given the link to the full script : it is on post #40 of this topic

EDIT: ok, big Thanx Tom, Console report helped me a lot for debugging

it works now

for those interrested in updating the RATING TAG in file, here is the Jscript (thanx to NEMO7538 for his script)

Code: [Select]
function RGB(r,g,b){ return (0xff000000|(r<<16)|(g<<8)|(b)); }

var g_drag = 0;
var bool;
var g_metadb;
var imgname;
var rating;
var nrating;
var lrating;
var img;
var hofset=20;
var imgw=20;
var g_tfo = fb.TitleFormat("%rating%");

on_item_focus_change();

function on_paint(gr){
if (g_metadb) {
for (i = 1; i < 6; i++) {
img = gdi.image(fb.FoobarPath + "Images\\"
+ ((i > (g_drag ? lrating : rating)) ? "NoStar" : "Star" + (g_drag ? "-hover" : "")) + ".png");
gr.DrawImage(img, hofset+imgw*(i-1), 4, 20, 16, 0, 0, 20, 16);
}
}
}

function on_mouse_wheel(delta){}


function on_mouse_lbtn_up(x,y){
// fb.trace("button up");
if (lrating !=rating) {if (g_metadb) {
bool = g_metadb.UpdateFileInfoSimple("RATING",lrating);
}}
}

function on_mouse_move(x, y) {
if (g_metadb) {
g_drag = 1;
nrating = Math.ceil((x-hofset)/imgw);
if (nrating > 5) nrating = 5;
if (nrating != lrating) {
lrating = nrating;
window.Repaint();
}
}
}
function on_mouse_leave() {
on_metadb_changed()
}

function on_item_focus_change() {
if (g_metadb) {window.UnwatchMetadb();}
g_metadb = fb.GetFocusItem();
if (g_metadb) {
on_metadb_changed();
window.WatchMetadb(g_metadb);
}

}
function on_metadb_changed() {
g_drag = 0;
rating = g_tfo.EvalWithMetadb(g_metadb);
if (rating == "?") {rating = 0;}
lrating = rating;
window.Repaint();
}

function on_playback_new_track(metadb) {on_item_focus_change();}
//EOF


For it to work:
  • you need to place "Star.png", "NoStar.png" and "Star-hover.png" in your foobar/Images directory. Sample:

example:


WSH Panel Mod

Reply #97
var fileInfo=g_metadb.GetFileInfo(); <-- don't put this in on_paint. In addition i think it's useless , remove it.

WSH Panel Mod

Reply #98
removed (script updated above)

Merci Nemo

WSH Panel Mod

Reply #99
@fbuser:
Yes, it's a bug applied to MetaValue() and InfoValue(), while idx is invalid, will be fixed in the next release.