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: COM Automation Server for 0.9 (Read 592809 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

COM Automation Server for 0.9

What it does

The purpose of this component is to allow other programs to control some aspects of foobar2000.

What it does not do

The component does not enable you to implement foobar2000 components in languages other than C++.

It does not enable you to control or launch more than one instance of foobar2000, be it from the same or different (installation) locations.

Features

The features implemented in 0.7 alpha 2 are:
  • querying information about the foobar2000 instance
  • querying and modifying playback state and settings
  • receiving notifications about changes in the playback state and settings
  • querying and modifying the list of open playlists
  • receiving notifications about changes in the list of open playlists
  • querying the contents of open playlists
  • querying the contents of the media libary
  • performing the default action on a playlist entry (i.e. the equivalent of double-clicking a playlist entry)
  • querying information about tracks through titleformatting
More features are planned for the final version.

Documentation

There is not much documentation yet. The existing documentation as well as the test and demo scripts/applications are included in the installer (except for the proof-of-concept web panel which is to be announced in a separate post).

Compatibility

The component requires foobar2000 0.9 or compatible.

The current release is targeted primarily at Visual Basic 6 and scripting clients. It should be useable with clients written in C++, but it has not been tuned yet for this situation.

The component has been tested successfully with clients written in the following languages:
  • Visual Basic 6
  • VBScript
  • Lua 5.0.2 with LuaCOM (some problems with event callbacks)
  • Python 2.3 with Pythonwin (no event support AFAIK)
  • C# and VB.Net (.Net 1.1)
Known installer issues

The uninstallation function fails to remove some information from the registry. The following batch file can be used to remove the entries in question from the registry:

Code: [Select]
reg delete HKCR\TypeLib\{CB8F14D8-736E-4BB7-ADCF-BE26C39B576B} /f
reg delete HKCR\CLSID\{1bffc1e4-21a6-45af-8831-5ee045281633} /f
reg delete HKCR\Foobar2000.Application.0.7 /f

The file is also available for download (see below). Windows NT4 users have to install reg.exe from the Windows NT4 Resource Kit; reg.exe is a native command on Windows 2000 and XP, I suspect it is present on later versions as well.
You have to close foobar2000 and all programs that use the installed type library to run this successfully.

Disclaimer

This is the last section between you and the download links, but please read this carefully!

This component is a work in progress. It is currently labeled as an alpha version, which is primarily due to the incomplete functionality; I try to make sure there are no bugs in the released versions, but I cannot guarantee it. The (COM) interfaces currently exposed by the component are not the ones that the will be in the final version.

While the exposed functionality is quite limited, it may be sufficient for some people. For example the access to playback controls is rather complete; on the other hand, you only get read access to the open playlists and the media library.

There is no scheduled release date for the final version. I will try to advance this component as time permits.

Download

Installer
Registry cleaner tool (not necessary for latest versions, see below)

COM Automation Server for 0.9

Reply #1
Hi,

First, THX for this wonderful, usefull plugin!!  I'm working on it for a few times on vb6, and I can do all I want, execpt one thing : I can't find a fonction wich would able me to know which tracknumber is playing in the playlist, or wich is selected. Or this will be pretty good for the program I code.... Is this planned for future version, or am I just a blind man?? 

THX

PS : I know you didn't schedule any release dates, but do you know if the next version (even beta like this one) will be come soon?  Because I'm so hungry of a new version

COM Automation Server for 0.9

Reply #2
Version 0.7 only has rudimentary playlist support, a later version will add more functionality in that area, though a release date is completely unknown.

COM Automation Server for 0.9

Reply #3
ok, Thanks

COM Automation Server for 0.9

Reply #4
great work foosion. is there any delphi example too? i remember seeing it in older version ...

i know that this is of much more use to the community, though you can guess what i would prefer . i'm afraid i would have to abandon my lua scripts when 0.9 final comes. not willing to do so, however ...

COM Automation Server for 0.9

Reply #5
foosion, I tried messing with it in mIRC's com scripts, couldnt get alot to work, but the no-argument functions worked fine, like the media library count. Poke me on irc if you know how to use mIRC's com $idents to control foobar further (i couldnt get it to work exactly right after a few hours of fiddling).

Is there a C# example aswell? seeing as you commented it was tested successfully with it.

COM Automation Server for 0.9

Reply #6
Why some formattgin string won't wotk with COMServer, %isplaying% for example every return a "?", but if I put it in foobar2000, it works fine....

COM Automation Server for 0.9

Reply #7
Quote
foosion, I tried messing with it in mIRC's com scripts, couldnt get alot to work, but the no-argument functions worked fine, like the media library count. Poke me on irc if you know how to use mIRC's com $idents to control foobar further (i couldnt get it to work exactly right after a few hours of fiddling).[a href="index.php?act=findpost&pid=355318"][{POST_SNAPBACK}][/a]

Sorry, I have no experience what-so-ever with mIRC scripting. Perhaps you can get some help about COM scripting in general from the mIRC people. I'll see what I can do, if the problem can be traced to my implementation in foo_comserver.

Quote
Is there a C# example aswell? seeing as you commented it was tested successfully with it.[a href="index.php?act=findpost&pid=355318"][{POST_SNAPBACK}][/a]

The C# code for the latest version needs to be cleaned up, before I will include it in the installer.

Quote
Why some formattgin string won't wotk with COMServer, %isplaying% for example every return a "?", but if I put it in foobar2000, it works fine....[a href="index.php?act=findpost&pid=355505"][{POST_SNAPBACK}][/a]

There are several possible reasons for this. A Track (or Tracks) object does not remember where it originated from, so even if you retrieve the tracks contained in a playlist, you will not be able to access any playlist specific information on the returned object.
On the other hand, the FormatTitle method on the Playback object is hardcoded to use a "display level" that does not include all dynamic information. You can use FormatTitleEx to explicitly set a display level. The possible values for the display level come from the fbDisplayLevel enumeration in the type library. The numeric values for the enumeration members are 0 to 3, where 0 corresponds only to basic static information and 3 means all dynamic information including the current bitrate and the like.

COM Automation Server for 0.9

Reply #8
OK, thanks for helping us

COM Automation Server for 0.9

Reply #9
foosion, Thanks for the reply. I'll try to mess with the mIRC Scripting side some more and wait for the C# example aswell.

COM Automation Server for 0.9

Reply #10
There is a bug in the Volume property: if you retrieve the value, it is scaled down by a factor of 0.01; setting the volume works normally.

Please redownload the installer to get a fixed version (no other changes for now).

COM Automation Server for 0.9

Reply #11
Thanks for the heads up.

COM Automation Server for 0.9

Reply #12
Hey, this is really cool.
Thanks for writing this foosion, a friendly foobar2k event sender to other applications is exactly what I needed.

However, I'm running into a strange bug(?).
I have referenced the foobar COM component in my C# project, and have added the following (pseudo)code:
Code: [Select]
private void connectFoobar()
{
// Connect to foobar
foobar = new Application07Class();
foobar.Playback.PositionChanged += new _IVBPlaybackEvents_PositionChangedEventHandler(Playback_PositionChanged);
}

private void Playback_PositionChanged(double dSecondsFromStart, bool bSeekFlag)
{
info.Position = (int)dSecondsFromStart;
// Draw track information to Logitech G15 LCD.
}

This works for 5 or 6 events, then I stop recieving events.

(.. after many edits of this post..)
Aha, it appears calling the garbage collector (GC.Collect()) stops me from recieving COM events. This is why I stop recieving events after 5 or 6 memory-intensive operations. After a couple hundred k's of memory have been moved the GC is called.
I could try to fix this or use a timer instead. I'm glad to have found the cause anyways.

COM Automation Server for 0.9

Reply #13
Short version:

You should store a reference to the Playback object somewhere; then you can safely invoke the GC.

Long version:

There is only a single Playback object on the COM side. This COM object is wrapped into a CLR object of type Playback07Class when you access it in C#. Similarly the delegates you create translate between the COM event mechanism and that of the CLR. After you create and register a delegate, it is only referenced in the wrapper class instance (Playback07Class). So unless you keep a reference to the wrapper object, this object and all the delegates can be finalized by the GC anytime, causing them to clean up things on the COM side, i.e. releasing the reference to the wrapped COM object and removing the event subscriptions.

COM Automation Server for 0.9

Reply #14
foo_comserver2 v0.7 alpha 4

Changes:
  • Added helper COM object to detect if server is running (also supports start and exit events)
  • Updated example for Visual Basic 6
  • Added test script for the helper object for VBScript
  • Added example for C#
  • Uninstaller now cleans registry (self-unregistration of foo_comserver2.dll is still broken)

The helper object can be used to detect when the server is starting or exiting. However proper error handling does not become unncessary because of this: 1) you receive the exit notification after the server has exited, and 2) the notification is only sent if the server terminates gracefully (in other words: when foobar2000 does not crash).
The C# example implements rigorous error checking by protecting every access to the server (the Foobar2000.Application.0.7 object and all objects reachable through it) with a try-catch block.

The helper object is implemented in a separate EXE (COMServer2Helper.exe). This EXE starts when a client accesses the Foobar2000.ApplicationHelper.0.7 object and - assuming all clients behave correctly - exits when it is no longer needed. At the moment the server also keeps a reference to the helper as long as it is running, so in effect the helper always runs when foobar2000 is running. This may change in future versions so that the helper is only running when it is indeed used by clients.

If you do not want to use the helper, you can unregister it running the following command on the command line:
Code: [Select]
COMServer2Helper.exe /UnregServer

To reenable the helper, use:
Code: [Select]
COMServer2Helper.exe /RegServer

(The commands are actually not case-sensitive... )

Disabling the helper has no negative effects on the server.

COM Automation Server for 0.9

Reply #15
Quote
Short version:
You should store a reference to the Playback object somewhere; then you can safely invoke the GC.

Yay, this and the new C# example have allowed me to finish my code.
I now have a very efficient application which shows Foobar2000 information on a Logitech G15 LCD. Thanks for making it possible.

COM Automation Server for 0.9

Reply #16
We'll be working on a foobar2000 display in GTSdll v2 (for mIRC spamming and such).

COM Automation Server for 0.9

Reply #17
I was just wondering how much functionality this plugin would eventually provide. It would be very cool to be able to script repetitive stuff using this plugin. For example, when I (legally) download an album in the format of an APE cd image and a cue file, within a zip file, I have to:

1. Extract the file

2. Reencode APE to FLAC

3. Embed cue-sheet in FLAC usign CUESHEET tag

4. Move .flac to D:\music\artist\album

5. Add it to foobar's database

6. Delete all the original files.

Almost all of this can be done through foobar and its components, so if I could access this functionality from COM, it would be very easy to make a JScript or similar completely automating this.

I'm not sure how easy it would be for you to provide the functionality of other components that might/might not be installed, perhaps this could be done within the plugins themselves, eg. foo_comserver would provide a QueryComponents function through which a script can discover, if, for example "diskwriter" is available, and retrieve an interface through which its functionality can be accessed.

I have no idea on how this would best be done, but it would be very very cool if it was possible

And of course using COM instead of some sort of internal scripting makes many other cool things possible, eg. in the example above, the resultant file could also be added to iTunes's library using it's COM interface, and even transcoded and loaded onto an iPod. The ultimate in laziness.

COM Automation Server for 0.9

Reply #18
The functionality available through foo_comserver2 will always be a subset of what can be done programmatically on the foobar2000 side. So for the most part this will be things that every component could do using just the SDK. This will include access to the playback engine (mostly complete already), the playlist, the media library (not much there right now, but not much to add either) and perhaps tagging (haven't decided yet).

As for access to other (third-pary) components, well, many of those (including masstagger and converter) cannot be controlled from other components anyway, so binding them to COM is not possible without extra work (by the author of the specific component).

In short, automating what you sketched out above will stay a dream for the foreseeable future.

COM Automation Server for 0.9

Reply #19
Error:  "This application has failed to start because shared.dll was nout fid.  Re-installing the application may fix this problem."

ERROR (CORE) : Failed to load DLL: foo_comserver2.dll, reason: Unable to load DLL.

sad    i wanted to try this out, too...
-=- Darkain Dragoon -=-

COM Automation Server for 0.9

Reply #20
oh, heh, i'm sorry, i found the problem... it installed to the wrong foobar installation on my system.  (thats what i get for having billions of test installs of every app imaginable)...

however, now that COM stuff is wokring, LuaCOM isnt.  it just keep crashing.  oh well.  i'll look into it more a bit later. 
-=- Darkain Dragoon -=-

COM Automation Server for 0.9

Reply #21
It seems the Playback.Back and Playback.Forward commands do not work.

I've tried recompiling my program.

I've installed foobar2000 and the COM Automation Server on a clean copy of Windows XP.

COM Automation Server for 0.9

Reply #22
Quote
It seems the Playback.Back and Playback.Forward commands do not work.[a href="index.php?act=findpost&pid=367249"][{POST_SNAPBACK}][/a]
Well, they simply do not exist. There are only Playback.Previous() and Playback.Next().

COM Automation Server for 0.9

Reply #23
Quote
Quote
It seems the Playback.Back and Playback.Forward commands do not work.[a href="index.php?act=findpost&pid=367249"][{POST_SNAPBACK}][/a]
Well, they simply do not exist. There are only Playback.Previous() and Playback.Next().
[a href="index.php?act=findpost&pid=367262"][{POST_SNAPBACK}][/a]

Sorry, that is what I meant. I should clarify by saying that when I use the Previous() and Next() commands, they don't move to the next or previous item in the playlist.

COM Automation Server for 0.9

Reply #24
Thanks for reporting. This was due to a bug in the SDK. Fixed version of COM server should be up tomorrow.