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 593947 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

COM Automation Server for 0.9

Reply #125
I have recently found Foobar2000 and love the sound that it produces. My CDs are mainly classical and I have an Access database from which I select what to play. I want to automate this process so have installed this COM Automation Server using VBA. It works fine and I can create & juggle with playlists and also select specific tracks from the media library.

Sadly I cannot work out how to drop those selected tracks into a playlist, nor find any other way to actually play them.

Since I retired I seem to be losing the little grey cells faster than my hair, so I would really appreciate some guidance so that I can actually hear my music.

Thanks

COM Automation Server for 0.9

Reply #126
i'm trying to develop some sort of foo_facets but for a web browser
so i need to get all the tracks in the library at first (to cache them in a web application)

the following code (C#)

Tracks07 foundTracks = foobarApplication.MediaLibrary.GetTracks("a");
for (int i = 0; i < foundTracks.Count; i++)
{
  foundTracks.FormatTitle("%genre%");
}

almost always ends with System.OutOfMemoryException

if i replace %genre% with %album% or %artist% it actually never fails (but works a bit slow - ~25 sec)

foundTracks.Count ~ 19000

any thoughts?

COM Automation Server for 0.9

Reply #127
Does anyone have a working example for php? I've been playing around a little but havn't had alot of success. Not surprising really as this is the first time i have connected a COM object. I've tried a few things that have not given the results i expected, one is;
Code: [Select]
<?php
echo 'Script Started';
echo ('<br><br>');

$foo = new COM('Foobar2000.Application.0.7') or die('cannot connect to fb2k');
echo $foo->Name;
echo '<br>';
echo $foo->ApplicationPath;
echo '<br>';

$lib = $foo->MediaLibrary;
$trks = $lib->GetTracks();
$numtrks = $trks->Count;
echo ($numtrks);
echo (' tracks in library');
echo '<br>';

echo ('<br>');
echo 'Script Finished';
?>


which outputs
Quote
Script Started

foobar2000 v0.9.5.3
C:\Program Files\foobar2000\foobar2000.exe
0 tracks in library

Script Finished


When i use the included vbs example i get a value of 7545 tracks in the library.

Am i doing something wrong here? any help or advice would be appreciated.

COM Automation Server for 0.9

Reply #128
I realize this plugin is not your top-priority but is there any chance you could implement something like playback->GetFFT(channel) or at least playback->GetAudioLevel(channel)? It would be pure awesomeness to be able to make standalone visualizations.

Anyways, thanks for this great plugin and as others also mentioned, tag editing wouldn't hurt 
I just like listening to music

COM Automation Server for 0.9

Reply #129
Does anyone have a working example for php? I've been playing around a little but havn't had alot of success. Not surprising really as this is the first time i have connected a COM object. I've tried a few things that have not given the results i expected, one is;<snip>


To answer my own question...

The problem here was one related to user accounts, the comserver plugin apparently looks for an instance of foobar2000 running as the same user as the one connecting to it, if it doesn't find it it spawns a new instance. So i was running fb2k as the local user and apache was connecting to the com server as SYSTEM, to complicate matters i had fb2k configured to look for config files in the local user profile so the instance spawned as SYSTEM had no library loaded and a default empty playlist.

I changed my apache config to run as the local user and fb2k to look in the application folder for config and now i get the results i expect.

I have only 1 small problem now and that is apache wont connect if fb2k is already running, the comserver seems to like to start its own instance, not in itself a problem but the instance it starts is invisible on the desktop so the only way i can shut it down is via the task manager (end process). If anyone knows how i can sort this out, some input would be great.

Thanks to Hancoque for guiding me with this problem, you saved what little hair i have left :]

COM Automation Server for 0.9

Reply #130
I have only 1 small problem now and that is apache wont connect if fb2k is already running, the comserver seems to like to start its own instance, not in itself a problem but the instance it starts is invisible on the desktop so the only way i can shut it down is via the task manager (end process). If anyone knows how i can sort this out, some input would be great.


i have just stumbled onto the solution to this issue, http://au2.php.net/manual/en/book.exec.php . i will copy and paste the text that solved it for me for anyone who doesnt want to follow the link.

Quote
If you try to launch GUI apps from a service in Vista, you'll have lots of trouble.  As a security feature, Vista mediates the interaction of services with the desktop using 'Interactive Services Detection'.

That means, if you are running PHP as a module of an Apache service, you won't be able to launch GUI apps using any method.  This kind of thing just won't work:

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("notepad.exe", 7, false);

So, if you want to use Apache/PHP as a proxy for launching GUI apps, you'll need to run Apache as a console application.

First, if Apache is already installed as a service, you'll need to set it's startup type to "manual" using the services snap-in.  (%SystemRoot%\system32\services.msc)  Search for Services in the start menu search box.

Then add a shortcut to C:\apache\bin\httpd.exe (or wherever Apache is installed) to your Startup folder, and set that shortcut to start minimized. You can use an app like TrayIt! to force Apache down into the system tray.

Then use any of the methods outlined on the PHP website and you will be able to open a Windows application from PHP and see it's GUI.


the text mentions Vista but it solved this problem for me with XP sp3

COM Automation Server for 0.9

Reply #131
strange... i'm on RTM and ive tried to register it. But when i look at Preferences > Tools > Com Automation server it says the server is " Not Running: Operation unavailable" and all three paths are " Not available".


I had the same problem.  I noticed on installation that it closed my active Foobar2000.  So I wondered if something in the installation went wrong because I had Foobar2000 open.  So I tried installation again with the Preferences > Tools > Com Automation server dialog open, and it gave me some kind of error about a .dll file not available.  Finally, I ran the installation a third time with Foobar2000 not open and now it looks like the server is running.

The installer should definately tell the user to close Foobar2000 before proceeding, since you may cause errors if they have the config open; and especially if you will forcibly close Foobar2000 and the user is in the middle of ripping a CD or something.

COM Automation Server for 0.9

Reply #132
Yes, all right. I need it just for a QIP plug-in. But when I install the COM Server, my foobar2000 crashes... Do you happen to know what I am doing wrong...? Thanks a lot!

Moderation: Removed useless full quote of the first post.

COM Automation Server for 0.9

Reply #133
Just made this for the mIRC users out there. It basically is a alias that fetches the song playing and echoes it out.

/np {
  .comopen fb2k Foobar2000.Application.0.7
  if ($comerr) { echo comopen failed | halt }
  if ($com(fb2k, Playback, 3, dispatch* pb)) {
    $com(pb, FormatTitle, 3, bstr, foobar2000 now playing: % $+ artist% - % $+ title% ['[' % $+ album% ']'])
    echo $com(pb).result
  }
  .comclose pb
  .comclose fb2k
}


You can edit the format string as long as you make sure to escape percent signs (%) as these have a special meaning in mIRC scripts (variables).
just concatenate using the $+ operator as shown above.


@splint3r:
Services can interact with the desktop via the means of window station API. I used this once when I had to interact with Winamp from a service once.

Code: [Select]
bool GetCurWinampSong(string &s)
{
#define WM_WA_IPC WM_USER
#define IPC_GETLISTPOS 125
#define IPC_GETPLAYLISTTITLE 212

    s="<not playing>";
    /* -- Open user's window station "WinSta0". -- */
    HWINSTA hWinStaUser = OpenWindowStation("WinSta0", FALSE, MAXIMUM_ALLOWED);      
    /* -- Set process window station to "WinSta0", this enables the process to
            access objects in the window station such as desktops. -- */
    if (SetProcessWindowStation(hWinStaUser)) {
        /* -- Open user's desktop "Default". -- */
        HDESK hDeskUser = OpenDesktop("Default", 0, FALSE, MAXIMUM_ALLOWED);
        /* -- Set thread desktop to "Default". -- */            
        if (SetThreadDesktop(hDeskUser)) {

            // Now as we are locked on to user's desktop, we can access users's windows.
            HWND hwnd_winamp;
            hwnd_winamp = FindWindow("Winamp v1.x", 0);
            if (IsWindow(hwnd_winamp))
            {
                s="<other error>";
                DWORD dwPid;
                GetWindowThreadProcessId(hwnd_winamp, &dwPid);
                HANDLE hProcess;
                hProcess = OpenProcess(PROCESS_VM_READ, FALSE, dwPid);
                if (!hProcess)
                {
                    s = "<Can not open winamp process>";
                    return false;
                }
                int plpos = SendMessage(hwnd_winamp, WM_WA_IPC, 0, IPC_GETLISTPOS);
                char *szTitle, *pTitle;
                pTitle = (char*)SendMessage(hwnd_winamp, WM_WA_IPC, plpos, IPC_GETPLAYLISTTITLE);
                SIZE_T read, datalen;
                datalen = 1024;
                szTitle = (char*)GlobalAlloc(GPTR, datalen+1);
                if (ReadProcessMemory(hProcess, pTitle, szTitle, datalen, &read))
                {
                    s = szTitle;
                }
                else
                {
                    s = "<Could not get winamp title!>";
                }

                GlobalFree((HGLOBAL)szTitle);
                CloseHandle(hProcess);
            }
        }
        if (hDeskUser) {
            CloseDesktop(hDeskUser);
        }
    }
    if (hWinStaUser) {
        CloseWindowStation(hWinStaUser);
    }
    return true;
}


COM Automation Server for 0.9

Reply #134
This mIRC alias searches the Media Library.
usage: /fbsearch QUERY
example: /fbsearch artist HAS beatles


Code: [Select]
/fbsearch {
  .comopen fb2k Foobar2000.Application.0.7
  if ($comerr) { echo comopen failed | halt }
  if ($com(fb2k, MediaLibrary, 3, dispatch* ml)) {
    if ($com(ml, GetTracks, 3, bstr, $1-, dispatch* tracks)) {
      if ( $com(tracks, Count, 2) ) {
        echo Count: $com(tracks).result results

        var %n = $com(tracks).result
        var %m = 0
        while (%m < %n) {
         ; works if you only want paths> echo Track %m $+ : $comval(tracks, %m, Path)
          $com(tracks, Item, 3, integer, %m, dispatch* track)
          $com(track, FormatTitle, 3, bstr, % $+ artist% - % $+ title%)
          echo $+($chr(20), $com(track).result)
          .comclose track
          inc %m
        }
      }
    }
  }
  .comclose tracks
  .comclose ml
  .comclose fb2k
}


COM Automation Server for 0.9

Reply #135
Any chance this could be updated for 1.0.x versions?

COM Automation Server for 0.9

Reply #136
Any chance this could be updated for 1.0.x versions?


Works for me in 1.0. I used it with an album cover art plugin(that requires it) and was able to download the covers for all my albums.

COM Automation Server for 0.9

Reply #137
Any chance this could be updated for 1.0.x versions?


Works for me in 1.0. I used it with an album cover art plugin(that requires it) and was able to download the covers for all my albums.


Are you using Album Art Download XUI?
If so, could you let me know how to run that within Foobar2000?
If not, which cover art plugin are you using?

Thanks!

COM Automation Server for 0.9

Reply #138
Album-art:
http://sourceforge.net/projects/album-art/

Make sure you follow the Com Automation server install instructions.

Have foobar2000 open. Then open the Album-art program. Go to the FILE menu, New menu, select foobar browser. Then choose either the entire library or a particular Tab that is open. Then select the check boxes for albums that don't have album art and at the bottom click the button "Get Artwork for selection. It's fairly explanatory after that.

COM Automation Server for 0.9

Reply #139
Album-art:
http://sourceforge.net/projects/album-art/

Make sure you follow the Com Automation server install instructions.

Have foobar2000 open. Then open the Album-art program. Go to the FILE menu, New menu, select foobar browser. Then choose either the entire library or a particular Tab that is open. Then select the check boxes for albums that don't have album art and at the bottom click the button "Get Artwork for selection. It's fairly explanatory after that.



Thank you for the quick reply!  I have been using the program with foobar 0.9.6.9, but will now try it with foobar 1.0 instead.

COM Automation Server for 0.9

Reply #140
While I wrapped foobar COM object in some code I want to print some data to console
Is it possible?
I found nothing related in .idl file
If not with this COM server maybe somehow to pass strings to foobar console through piping to running foobar process?

COM Automation Server for 0.9

Reply #141
Hello!

I have tried to write a simple application to control the Foobar by it, but I have not found any methods to add/remove files to playlist.
Are such methods available in interface? Where could I found them?

If such methods are not available in the interfave - is it planned to add such methods?

Aleksandr.

 

COM Automation Server for 0.9

Reply #142
Is it possible to get the index of track in the playlist which is being currently played?

COM Automation Server for 0.9

Reply #143
python example:
Code: [Select]
    fb2k = win32com.client.Dispatch("Foobar2000.Application.0.7")
    trk = fb2k.Playback.FormatTitle("%path%")
    apl = fb2k.Playlists.ActivePlaylist
    cnt = 0
    for x in apl.GetTracks():
        cnt += 1
        if x.FormatTitle("%path%") == trk: print cnt

[edit] it's just example as active playlist doesn't necessarily mean that it's playing playlist and assuming there are no duplicates in playlist, but solution through numbering GetTracks() and using it as %list_index% workaround

COM Automation Server for 0.9

Reply #144
python example:
[edit] it's just example as active playlist doesn't necessarily mean that it's playing playlist and assuming there are no duplicates in playlist, but solution through numbering GetTracks() and using it as %list_index% workaround

This variant is not universal, but it seems to be a suitable workaround.

2 All: As I see - the project is frozen now. Is there source codes available? I think - users which are interested in it - they could write the necessary functionality themselves and then place the corrected code here.

COM Automation Server for 0.9

Reply #145
I have found that the path equality is not enough condition. If the .cue sheet is being played - all the tracks have the same path.
The titile, artist, track length and album should also be compared.
This method is implemented in my application. On note - the playlist shall no contain any doubles, as was said above.

COM Automation Server for 0.9

Reply #146
Can't get it to work with latest 1.1b1

com object gets assigned: <COMObject Foobar2000.Application.0.7> but any interface like Playback, Playlist etc. raises error

COM Automation Server for 0.9

Reply #147
above problem can be avoided by leaving foo_comserver2.dll in foobar's components folder, as installer hardcodes the path to the dll in 2 reg keys (logically)

COM Automation Server for 0.9

Reply #148
@foosion: would it be not much of trouble to extend this wrapper also to DSP manager and converter

COM Automation Server for 0.9

Reply #149
Providing what DSP manager and Converter functionality specifically?
Full-quoting makes you scroll past the same junk over and over.