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: JScript Panel (Read 295514 times) previous topic - next topic
0 Members and 5 Guests are viewing this topic.

Re: JScript Panel

Reply #150
Is it possible for JScript panel to determine whether a visualization is actually being displayed? I am particularly interested in the YouTube Video player pop-up ("View\Visualizations\YouTube Video"). I can toggle it on/off with a button, but it seems the on/off state cannot be determined. Consequently it sometimes gets out of sync with other changes in the layout view, i.e. shows when not wanted & hides when wanted.

Perhaps this would require a new callback that would cover all visualizations, if within your skill set?

Thanks for your consideration.

I use utils.WriteIni to save the window state (on or off).
Of course if the video window state is changed not with the button but from the menu the state gets messed-up.

Code: [Select]
//settings ini
ini_file = fb.FoobarPath + "zeremy\\settings.ini";

read_ini_video = function (k) {
return utils.ReadINI(this.ini_file, "video_window", k);
}

function vid0mode() {
video_window_state = read_ini_video("state");
video_window_mode = read_ini_video("mode");
if (video_window_state == "ON") {
utils.WriteIni(this.ini_file, "video_window", "state", "OFF");
buttons.vid0.state = ButtonStates.normal;
fb.RunMainMenuCommand("View/Visualizations/Youtube Video");
} else {
utils.WriteIni(this.ini_file, "video_window", "state", "ON");
buttons.vid0.state = ButtonStates.down;
fb.RunMainMenuCommand("View/Visualizations/Youtube Video");
}
}



Re: JScript Panel

Reply #152
Is it possible for JScript panel to determine whether a visualization is actually being displayed? I am particularly interested in the YouTube Video player pop-up ("View\Visualizations\YouTube Video"). I can toggle it on/off with a button, but it seems the on/off state cannot be determined. Consequently it sometimes gets out of sync with other changes in the layout view, i.e. shows when not wanted & hides when wanted.

Perhaps this would require a new callback that would cover all visualizations, if within your skill set?

Thanks for your consideration.

Yeah, I feel your pain, I've a similar problem myself (not only with YT)...

PS: I will try to make some sound arguments for my feature request for Library Tree soon :)

No, I don't think so. All current callbacks are provided the SDK itself and I'm almost certain nothing like that would exist for any visualisation windows - especially 3rd party ones.

I've been able to add/modify what is already there because of the existing code/notes. Hacking something together outside of that would be way beyond what I'm capable of.

Actually, I think it could be covered by a different not visualizations-related check: we need an ability to get the state of the main menu item (e.g. whether it's checked (like radio-button-checked)), this way we can check any item we want, including visualizations. It's like CheckMenuRadioItem, but with arguments from RunMainMenuCommand.

I've found some callbacks in SDK that might be related to this (it should be the same for context menu and main menu):
https://github.com/19379/foo-jscript-panel/blob/master/foobar2000/SDK/menu_helpers.h#L13

This one looks suspiciously close to what we need.

Re: JScript Panel

Reply #153
Just a heads up: since marc2003 indicated he wasn't able to add the ability to get the "visible" vs "hidden" status of visualizations, I asked 3dyd if the property could be provided by foo_youtube.  I now have test version of foo_youtube that's working well. Of course it only applies to the foo_youtube popup visualization, but in this case it should work generally - not just with JScript panel. Hopefully, it will be in the next release of foo_youtube.


Re: JScript Panel

Reply #155
Code: [Select]
v1.1.6.2
- FIX: plman.AddLocations: Original order of files in array is now maintained.
- CHG: plman.AddLocations: Progress dialog stays hidden for short operations.

https://github.com/19379/foo-jscript-panel/releases

@WilB, if you still see a progress dialog, there is nothing else I can do. The SDK function doesn't accept any other parameters that will change the behaviour.

Re: JScript Panel

Reply #156
@marc2003 : Actually it was much simpler than that - mainmenu_commands class has get_display method, which return flags:

Code: [Select]
class NOVTABLE mainmenu_commands : public service_base {
public:
enum {
flag_disabled = 1<<0,
flag_checked = 1<<1,
flag_radiochecked = 1<<2,
flag_defaulthidden = 1<<3,
sort_priority_base = 0x10000,
sort_priority_dontcare = 0x80000000,
sort_priority_last = ~0,
};
...
virtual bool get_display(t_uint32 p_index,pfc::string_base & p_text,t_uint32 & p_flags) {p_flags = 0;get_name(p_index,p_text);return true;}
...
};

I can make a pull request with the implementation, if you want.

PS: Component fails to build under VS2015 unless I change default values from float to integer in DrawImage and FillGradRect methods in script_interface.h:
before:
Code: [Select]
__interface IGdiGraphics: IGdiObj
{
...
STDMETHOD(DrawImage)(IGdiBitmap * image, float dstX, float dstY, float dstW, float dstH, float srcX, float srcY, float srcW, float srcH, [defaultvalue(0.0)]float angle, [defaultvalue(255)]BYTE alpha);
...
STDMETHOD(FillGradRect)(float x, float y, float w, float h, float angle, VARIANT color1, VARIANT color2, [defaultvalue(1.0)] float focus);
... 
};
after:
Code: [Select]
__interface IGdiGraphics: IGdiObj
{
...
STDMETHOD(DrawImage)(IGdiBitmap * image, float dstX, float dstY, float dstW, float dstH, float srcX, float srcY, float srcW, float srcH, [defaultvalue(0)]float angle, [defaultvalue(255)]BYTE alpha);
...
STDMETHOD(FillGradRect)(float x, float y, float w, float h, float angle, VARIANT color1, VARIANT color2, [defaultvalue(1)] float focus);
... 
};

Re: JScript Panel

Reply #157
First of all, no changes are required to make it compile with VS2015. I use it myself.

Secondly, I have no idea what you're trying do checking menu radio/check boxes. None of the visualisations have any that you can query.

Re: JScript Panel

Reply #158
First of all, no changes are required to make it compile with VS2015. I use it myself.
I dunno, may be it is system specific bug, because there was only a single report a lot of time ago in WSH Panel Mod thread with the same problem as mine: https://hydrogenaud.io/index.php/topic,70363.msg722027.html#msg722027

For some reason midl treats float values as strings when generating .idl files (i.e. it changes 1.0 to "1.0"), which results in a compile error.

Secondly, I have no idea what you're trying do checking menu radio/check boxes. None of the visualisations have any that you can query.
I've made a >>pull request<< that hopefully is easier to understand than my rambling here =)

Re: JScript Panel

Reply #159
@marc2003: Thanks for the upgrade to plman.AddLocations.

Its a great improvement. I haven't seen the progress dialogue.

However, foobar2000 add locations seems to ensure that all the added items are visible and also automatically sets focus to the first added item. Is it possible that plman.AddLocations can have, or have options, for that behaviour? As it is items can be added at the end of a playlist where they can't be seen.

I couldn't resolve this in the normal way by putting plman.EnsurePlaylistItemVisible and/or plman.SetPlaylistFocusItem after plman.AddLocations. It seemed as though plman.EnsurePlaylistItemVisible / plman.SetPlaylistFocus actually ran before the tracks were added to the playlist (e.g. I could get them to work if I used them with a short timer delay, but that's not an ideal solution).

Re: JScript Panel

Reply #160
Yes, the operation is asynchronous which means any code in your script will run immediately without knowing or caring when it's going to finish.

However, you can detect when tracks are added to a playlist using on_playlist_items_added. Obviously you don't want code inside this triggering every time tracks are added to a playlist so you can use a variable something like this...

Code: [Select]
var focus = -1;

function add_tracks() {
    //before adding tracks, count existing ones so we know the index to select.
    focus = plman.PlaylistItemCount(plman.ActivePlaylist);
    plman.AddLocations(plman.ActivePlaylist, files);
}

function on_playlist_items_added() {
    if (focus < 0) return; //don't do anything unless we know plman.AddLocations has just run
    plman.SetPlaylistFocusItem(plman.ActivePlaylist, focus);
    focus = -1; // reset the value so this code doesn't run next time tracks are added normally
}

Re: JScript Panel

Reply #161
Code: [Select]
v1.1.7 Beta 1
- FIX: Remove trailing space in "Console" when using fb.Trace.
- FIX: Thumbs sample. Fix issue where using %profile% in the "Custom folder"
       setting would fail if the profile path contained special title formatting
       characters like %()[]'
- CHG: Remove "Grab focus" and "Delay load" from "Configuration" window. Both
       options are forced on for all panels. Don't want to give a panel focus?
       Don't click it! Let me know if you think "Delay load" on all panels has
       noticeable side effects.
- CHG: Some internal refactoring which is why we have a beta. I need more users
       to test I didn't break anything!

https://github.com/19379/foo-jscript-panel/releases

Re: JScript Panel

Reply #162
Sorry, but force "Grab focus" to all panels without an option to disable it is a bad idea...

For example: i have some pure button panels and why should they get focus at all?
Once i click a button i am forced to click in the playlist again to give it the "focus" back or the key buttons will no longer work...

Re: JScript Panel

Reply #163
Fair point. It has been reverted.
Code: [Select]
v1.1.7 Beta 2
- FIX: Remove trailing space in "Console" when using fb.Trace.
- FIX: Thumbs sample. Fix issue where using %profile% in the "Custom folder"
       setting would fail if the profile path contained special title formatting
       characters like %()[]'
- CHG: Remove "Delay load" from "Configuration" window.
- CHG: Remove "Grab focus" from "Configuration" window. Beta 1 only, reverted in Beta2.
- CHG: Some internal refactoring which is why we have a beta. I need more users
       to test I didn't break anything!

https://github.com/19379/foo-jscript-panel/releases

Re: JScript Panel

Reply #164
Code: [Select]
v1.1.7
- FIX: Remove trailing space in "Console" when using fb.Trace.
- FIX: Text Reader sample. Ensure "Open containing folder" works when specifiying
       a folder rather than a full path to a file.
- FIX: Thumbs sample. Fix issue where using %profile% in the "Custom folder"
       setting would fail if the profile path contained special title formatting
       characters like %()[]'
- CHG: Remove "Delay load" from "Configuration" window.

https://github.com/19379/foo-jscript-panel/releases

Re: JScript Panel

Reply #165
Thank you, Marc2000 for saving my life
the Jscript panel is so cool
I have embedded your script to my foobar2000 and it works well
One thing is that when I try to do library import for my last.fm, it seems that the playcount does not update ( i have all last.fm username, password, API )
The library import (run in seperated windows) seems no problem, no error etc but.
Right now, my last.fm playcount is higher than ones in my foobar2000 library
Moreover, the love function is gone
Previously, I have removed the custom_db component as it's making never-ending-crash 

Could you advice what should I do for this situation

Thank you!!!!!!!

 

Re: JScript Panel

Reply #166
Well foo_customdb was never optional - it was absolutely essential to make it work. Anyway, it doesn't matter as I don't support that script any more. Use foo_softplaylists to love/unlove tracks.

Re: JScript Panel

Reply #167
Found a bug where ALL windows freeze, so I have to force restart the system.
I did some experiments and concluded gr.gdiDrawText is a culprit... or maybe Windows.

Steps to reproduce:
1. Windows 10 version 1607 x64
2. Install this skin: http://alibalicou.deviantart.com/art/Eole-608641604
3. Play a music with title containing some non-ANSI characters.
(ex) Track title: ごめんね、いいコじゃいられない。 Album title: TVアニメ「キルラキル」EDテーマ -「ごめんね、いいコじゃいられない。」
4. Repeatedly minimze and restore the foobar2000 window.
Tested on both real/virtual machine.

EDIT: I was unable to reproduce this bug in Windows 7 x64. So this bug is due to Windows 10... well how do I report it to Microsoft and let they fix it? sigh...

Beginner Questions

Reply #168
Thank you for a fantastic foobar component.
Using your complete sample playback buttons, I added a mute button (don't laugh - took me about 2 days and a JavaScript reference book)
As someone who knows nothing about jscript, I would appreciate knowing if what I did makes "sense" or is there a much better/cleaner way to achieve this type of button (display a different image depending on the state & change the tooltip depending on the state). Here is what I did:
1) Defined new variables:
Code: [Select]
var WhichMute = "buttons\\mute.png"; //Initialize the mute button to Not Muted image
var IsMuted = false; //Initialize mute stae = Not muted
2)Added a new button to buttons.update function:
Code: [Select]
 
this.buttons.mute = new _.button(bs*5, 5, bs, bs,
{normal : WhichMute},
function () { MyVolumeMute(); },
IsMuted ? "Mute On" : "Mute Off");
3) Add a function to determine the current volume state & set the desired image
Code: [Select]
function MyVolumeMute()
{
if(fb.Volume == -100)
{
     WhichMute = "buttons\\mute.png";
fb.VolumeMute();
IsMuted = false;
}
else
{
WhichMute = "buttons\\muted.png";
fb.VolumeMute ();
IsMuted = true;
}
buttons.update();
window.Repaint (); //If I don't do this, icon does not change unless I move mouse off image
}

Thanks for your help.





Re: JScript Panel

Reply #169
@extratype, Not that I can do anything because I don't have windows 10, are you able to reproduce with a single instance of JScript panel in your layout containing just this code?

Code: [Select]
var font = gdi.Font("Segoe UI", 16); // assuming Segoe UI is still default on 10??

function on_paint(gr) {
    gr.GdiDrawText("Track title: ごめんね、いいコじゃいられない。 Album title: TVアニメ「キルラキル」EDテーマ -「ごめんね、いいコじゃいられない。」", font, 0, 0, 0, window.Width, window.Height, 0);
}

@vince_57, I really need to add some notes about customising buttons that would help people out.

First of all, those relative paths should only be used for images I bundle with the component. If you upgrade the component, any of your own custom images added to those folders would be lost. Instead, you should keep your images folder separate and specify the full path to it. My button code is already designed to handle full paths or my own relative paths.

Code: [Select]
{normal : fb.ProfilePath + "my_images\\mute.png"}

Always use fb.ProfilePath as that points towards your configuration folder (%appdata%\foobar2000) in normal installation mode or the program folder in portable mode. Obviously you'll need to create the folders/move images as necessary.

As for your own button, it does have issues.

1) You're assuming the volume is always going to be unmuted when the script initialises. I think this is a mistake.
2) There are so many different ways of changing the volume such as using keyboard shortcuts, sliders, media keys, other buttons, scrolling your mouse over the volume indicator on the status bar etc...

It seems you missed the clues already included with the script for how the play/pause button updates itself without special code inside the button click function. Note the on_playback_starting, on_playback_pause and on_playback_stop functions.

Code: [Select]
function on_playback_stop() {
buttons.update();
window.Repaint();
}

function on_playback_pause() {
buttons.update();
window.Repaint();
}

function on_playback_starting() {
buttons.update();
window.Repaint();
}

All these functions prefixed with on_ are special functions called callbacks and they are triggered by foobar itself no matter how the playback state changes. Again there are many more ways than just clicking your own custom button.

Luckily there is one for when the volume changes so we just need to copy the same code in to it...

Code: [Select]
function on_volume_change() {
buttons.update();
window.Repaint();
}

So now you can simplify your button back to something like...

Code: [Select]
    this.buttons.mute = new _.button(bs * 4, 0, bs, bs, {normal : fb.Volume == - 100 ? fb.ProfilePath + "my_buttons\\muted.png" : fb.ProfilePath + "my_buttons\\mute.png"}, function () { fb.VolumeMute(); }, fb.Volume == - 100 ? "Unmute" : "Mute");





Getting Started With JScript (Customizing Buttons)

Reply #170
marc2003;
Thank you for your response - I just "felt" like my way to add a button was a bit funky.
It seems like your JScript Panel is designed for folks who are already knowledgeable and not for rank beginners like me (I did some programming in Fortran and C, in a non-GUI environment many, many years ago).
So, for someone like me who does not know JavaScript, or Windows "event driven" programming, or C++, or etc, would you say to them:
1)You are in way over your head & should stop asking questions
2)You need to 1st learn x,y,z  topics (here are some good references), then understand the JScript Panel and foobar specific implementation by studying a,b,c, and then come back to this forum
3) Something else?
Thanks
==================================================================
Just to show you how confused I am, here are my notes as I was installing/experimenting with JScript Panel
JScript Panel is a component for foobar2000 (aka fb2k)
After installing JScript Panel component, it is added to the fb2k window by right-click on an available (or create a new) fb2k panel, and in the Add New UI Element dialog, go to the section Utility, and select JScript Panel.
JScript panel allow you to create and run programs written in the Microsoft JScript language ?
JavaScript is a programming language available in web browsers  (Internet Explorer, Firefox, etc). The web browser contain a JavaScript interpreter to parse and run the JavaScript programs, which can be written in plain text with a simple text editor like notepad. JScript is a Microsoft implementation of JavaScript.
JScript Panel statements use the same syntax as the JavaScript language (?)
JScript Panel does not support all of the standard functions available with javascript, because javascript assumes it is running within a web browser(?)
For example, if you  enter & run the following code in the JScript Panel Configuration, you will get the "Aw, crashed :(" display:
alert("Hello World");
The error message states: The value of the property 'alert' is null or undefined, not a Function object.
It would seem logical that any JavaScript statement related to html would also not work in JScript Panel

foobar components are implemented as a .dll file. The name always starts with foo_.
The actual JScript panel component is foo_jscript_panel.dll and is located in the folder \user-components\foo_jscript_panel\.  The location of the folder \user-components depends on whether foobar was installed as a "Standard Installation" or "Portable Installation"
The DLL for JScript Panel (foo_jscript_panel.dll) is 2 to 3 times larger most of the foobar2000 system installed DLLs (foo_albumlist.dll, foo_converter.dll, etc)
Filetypes
A .js file is a javascript file. A .js filetype will be interpreted by JScript panel, and the javascript commands executed
A .txt file is a text file which can contain javascript statements or just "normal" text
If you paste the contents of a .txt file which contains javascript statements into the JScript Panel Configuration, or Import the .txt file containing javascript statements, it has effectively become a .js file

What programming language is used in JScript Panel:
What is the ECMA Script engine used by JScript panel?
In the JScript Panel Configuration there is an option for Script Engine: JScript9 or JScript, which seems to indicate the engine is the Microsoft JScript IE9-11 or some earlier version of Microsoft JScript (5.8?)
But when I look at the file, jscript.api, it shows "http://developer.mozilla.org/en/docs/Core_JavaScript_1.5", which seems like the earlier version of JavaScript from Mozilla as implemented in Firefox 1.0?

If I want to learn the basic syntax, etc of the scripting language used in JScript Panel, should I study a reference on JScipt Version 9, JavaScript, JavaScript Version 1.5, or something else?

Where is the ECMA Script engine used by JScript panel?
Is the engine built into JScript Panel or does JScript panel use some engine already installed elsewhere?

I am confused about the various files included with JScript panel, particulalrly about .txt files which are not code (and can't be used in a script) and .txt files which really are code (and can be pasted in the jScript Panel Configuration window or imported when my script is run).
In the foo_jscript_panel folder there are several files and sub-folders:
\docs: Contains .txt files
\samples
CHANGELOG.txt: List of JScript Panel versions and changes/fixes made in each version
foo_jscript_panel_dll: The actual JScript Panel Panel component
interface.api: A list of the custom functions available in JScript Panel (not part of the javascript language). These are the JScript panel functions which interface with foobar2000 and Windows (the operating system)
jscript.api: A list of the javascript language functions available in JScript Panel. Not all of the javascript functions are made available in JScript Panel
Both of the .api files (interface.api and jscript.api) are not code, and are not needed for JScript panel to work.  I think they are documenting what is made available in JScript panel
LICENSE.txt: License info. for the JScript Panel program.
License - <Name>.txt : License information for any samples included in the JScript Panel installation. For example: LICENSE - BoxBlurFilter.txt is the livcense info. for the sample script BoxBlur.txt

Looking at the files in the \docs directory:
What is the purpose of the file jscript.api?
Is this file for documentation only & is a complete list of jscript (javascript?) APIs supported by JScript panel?

What is the purpose of the file interface.api?
Is this file for documentation only & is a complete list of the non-jscript/javascript APIs supported by JScript panel?
Is the naming convention in interface.api an indication of what the "actual" API & SDK is?
fb. = Functions that interface to foobar2000 APIs. Normally, accessing these functions requires the SDK for that program and a program (written in C++?) to call the fb2k SDK API
gdi. = Functions that interfaces to various classes in the Windows SDK .GDI(+?) API
gr. = Same as gdi. but are used "in on_paint" (?)
plman. = interfaces to foobar2000 SDK playlist_manager Class API
window. = interfaces to the Microsoft Windows SDK API

What is the purpose of Flags.txt?
Some of the Windows APIs allow for multiple values in a parameter. This file lists those APIs supported by JScript which use these multiple-value parameters.
Using the first line in flags. txt as an example:  // Flags, used with GdiDrawText()
The values shown should be used whenever I use GdiDrawText() in a script. Does this actually apply to  gr.GdiDrawText (as listed in interface.api)?
Each line like: var DT_TOP = 0x00000000;  sets the value for each of the parameter mutliple values.

It looks like, I can import the entire flags.txt or just use the parts of flags.txt for the APIs I actually use in the script?

What is the purpose of the file interface.txt?
Is this file for documentation only and shows the details of the available "methods" & parameters used by each JScript Panel API?
It looks like the interface "groupings" match to the names used in interface.api. So:
interface IFbUtils {.. Is the I(nterface) for Fb(2k) for the Utils group

What is the purpose of Helpers.txt?
This file shows some potentially "helpful" code that can be used in a script. This helpful code includes:
-The values needed to set a specific color color - allows a script to specify a color using a nice English description like "Aqua" instead of 0xFF00FFFF.
-Useful "standalone" functions not related to another function?? For example:?
-"Helper" functions. " A helper function is a function that performs part of the computation of another function. Helper functions are used to make your programs easier to read by giving descriptive names to computations. They also let you reuse computations, just as with functions in general."
For example, the function in helpers.txt function stringFormat(), looks like it sets values for the optional parameter flags, as used in the gr.DrawSting API?

What Is the purpose of Callbacks.txt?
Is this file for documentation only and lists the "callback" functions available in JScript Panel?
"A callback function, also known as a higher-order function, is a function that is passed to another function (let’s call this other function “otherFunction”) as a parameter, and the callback function is called (or executed) inside the otherFunction."
For example, in the callbacks.txt is the line: function on_mouse_move(x, y, mask) {}
In one of the sample scripts, playback buttons.txt,  is the line: function on_mouse_move(x, y) {buttons.move(x, y);}
So the playback buttons script is calling the (callback) function on_mouse_move and passing the function buttons.move as a parameter to on-mouse_move ?
From marc2003: All these functions prefixed with on_ are special functions called callbacks and they are triggered by foobar itself no matter how the playback state changes.

Re: JScript Panel

Reply #171
@marc2003 The Win 10 default system font is Verdana.

Re: JScript Panel

Reply #172
If I want to learn the basic syntax, etc of the scripting language used in JScript Panel, should I study a reference on JScipt Version 9, JavaScript, JavaScript Version 1.5, or something else?
I learned from w3schools.com's JavaScript tutorial. Search on "learn javascript" to find other sources.

Learning Java

Reply #173
I learned from w3schools.com's JavaScript tutorial. Search on "learn javascript" to find other sources.
Jailhouse: Thanks for the link.
Is it correct to say that certain elements of JavaScript do Not work in JScript panel?
Specifically:
1) Anything to do Output (alert, write, etc)
2)Anything to do with Debugging (console.log, debugger)
3) Anything which involves HTML, Browser, Ajax, or JSON

Re: JScript Panel

Reply #174
Well foo_customdb was never optional - it was absolutely essential to make it work. Anyway, it doesn't matter as I don't support that script any more. Use foo_softplaylists to love/unlove tracks.
Thank you, Marc2000 for you kindly answer
What would happen for the playcount sync between Last.fm and foobar2000 in the JScript?
Do you plan to bring that function back?