patch: looping info

Hi, I needed up-to-date/second information for a script watching as moc is playing.
I'm quite sure it's not really the proper way to do this, but unless someone comes up with a better idea, here's the patch for it.
What it does:
Add's the options -I and --infoloop as well as the required code to main.c for a looping --info.

Comments are welcome ;-)

moc-2.3.2-infoloop.patch

--- main.c 2005-09-25 09:59:15.000000000 +0200
+++ main.c 2005-10-25 00:39:48.000000000 +0200
@@ -55,6 +55,7 @@
int next;
int previous;
int get_file_info;
+ int loop_file_info;
int toggle_pause;
int recursively;
int playit;
@@ -289,6 +290,17 @@
interface_cmdline_play_first (server_sock);
if (params->get_file_info)
interface_cmdline_file_info (server_sock);
+ while (params->loop_file_info) {
+ printf("\nINFO COMPLETE\n\n");
+ if (fflush(stdout)) {
+ options_free ();
+ decoder_cleanup ();
+ compat_cleanup ();
+ exit; // error
+ }
+ sleep(2);
+ interface_cmdline_file_info (server_sock);
+ }
send_int (server_sock, CMD_DISCONNECT);
}
else if (params->only_server)
@@ -374,6 +386,7 @@
"-n --nosync Don't synchronize the playlist with other clients.\n"
"-A --ascii Use ASCII characters to draw lines.\n"
"-i --info Print the information about the currently played file.\n"
+"-I --infoloop Print the information about the currently played file in a loop.\n"
"-e --recursively Make a playlist from the content of the directory given\n"
" at the command line.\n"
, prg_name);
@@ -476,6 +489,7 @@
{ "nosync", 0, NULL, 'n' },
{ "ascii", 0, NULL, 'A' },
{ "info", 0, NULL, 'i' },
+ { "infoloop", 0, NULL, 'I' },
{ "recursively", 0, NULL, 'e' },
{ 0, 0, 0, 0 }
};
@@ -486,7 +500,7 @@
memset (&params, 0, sizeof(params));
options_init ();

- while ((ret = getopt_long(argc, argv, "VhDSFR:macpsxT:C:M:PUynArfiGel",
+ while ((ret = getopt_long(argc, argv, "VhDSFR:macpsxT:C:M:PUynArfiIGel",
long_options, &opt_index)) != -1) {
switch (ret) {
case 'V':
@@ -528,6 +542,11 @@
params.get_file_info = 1;
params.dont_run_iface = 1;
break;
+ case 'I':
+ params.get_file_info = 1;
+ params.dont_run_iface = 1;
+ params.loop_file_info = 1;
+ break;
case 'p':
params.play = 1;
params.dont_run_iface = 1;

BTW: is it possible to attach files somehow?

http://www.savefile.com/files/6084783
md5sum: c2b40275ac514cfcddb56603275fd7be

You are right that this is not a good way :)

Do you really need this?
This can be achived in the shell with someting like:

for i in `seq 1 5`; do mocp -i; sleep 2; done

It's not possible for a regullar user to attach a file.
--
Damian Pietras - MOC developer

This was my first intention (though it's not a shell script), but when doing it this way, I observed several crashes of moc. I don't really know about the real reason for them (server was just gone), but since it didn't crash after looping within moc (yet), I thought the external polling might have something to do with it.
As a side effect this avoids unintentionally "respawning" moc when the server was shut down on purpose, which happens if I start a new instance with --info every few seconds.

Originally I didn't want to have the client polling and instead hoped on getting a notification from the server if the state changed (not time, but track info), but I didn't really find the code required for this.

If it crashes it should be fixed. I will not accept such features in MOC, sorry.

--
Damian Pietras - MOC developer

Well, finding the reason of the crash "in the midst of the night" is a bit difficult, since I don't know the exact time (algorithm-wise) when it crashed. Could just as well have been some audio file that moc didn't like (although that would be one hell of a coincidence, considering how often it died). However, besides the fact that I found the terminal back at the black shell without music playing, there was no indication of the crash.

Back to feature: I'd hardly consider my patch a feature (or did you mean the random feature [ie crash]? ;-). I simply wanted to provide it in case someone would like to have it as well and with the hope, someone could point to a better solution. So in the best case it was something I would have considered for the "Patches"-page. Sorry if I offended you.

Yet, if you would consider helping me by "pointing" at how to get the notification from the server (or that this isn't possible; I admit when trying to get this working with some 2.2*-version, I gave up), I'd be very thankful.

Bye, Jörg

You didn't offend me, I kust thought you want this path to be included in MOC.

As for notifications: what exactly you want to do?
In MOC there are events, whey are send from the server using server.c:add_event_all(). The first parameter is one of events from protocol.h (EV_* constants). Maybe this is what you are looking for?

--
Damian Pietras - MOC developer