Page 1 of 2

Wav2mp3 (using serversocket for app to app control)

Posted: Saturday 25th July 2020 7:03pm
by BruceSteers
This started off as a simple tool so i could right click a .wav audio file and convert it to mp3 using LAME.
It uses the wav folder name as album and parent folder as artist or can be set manually.
you can also select different bitrate settings.

It seemed to work fine, i can select files from a filechooser and add manually in the gui or pass arguments (wav file paths) to it at launch.

but if i selected more than one file on the desktop and right clicked to "Open with Wav2mp3" then it wouldn't launch as one program with multiple arguments it would launch multiple instances of the program with one argument each.

So i needed a way to check if the program was already running and send the arguments to that one instead.

I found a way using a ServerSocket control so the 1st instance of the app sets up a listening socket and any subsequent apps that load use a simple shell command to tell the 1st app to add the files to its queue and exit.

I'm sure the app could use some more error handling/debugging/refining but could provide some insights for some for resolving a similar issue.
So i guess it's beta , i've only just made it so may be some quirks.
I plan to add more options (quality, priority, etc)

attachment contains source and app
Wav2mp3.zip
(bugfixed 19:00 28 July 2020)
(non resizable version , see below for updated one)

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Monday 27th July 2020 2:24pm
by cogier
I like the way you get the program to load 'Lame'. I thought the program could do with being a little more flexible regarding the size of the Form. So I messed with the Form and include the same code with an expanding Form. You can now move the central partition as well.

Image
Wav2mp3_CO-0.0.36.tar.gz
(15.42 KiB) Downloaded 358 times

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 8:49am
by BruceSteers
Lol you beat me to it :D

only last night i was experimenting with the vsplit and hsplit containers and setting the Layout[] params

I also found a little bug
seems if only a single instance was loaded the server sockets wasn't being set to listen

I think it was here..

Code: Select all

  Else ' we are only instance so just add args to queue and start server socket
   For c = 1 To a.Count - 1
    ListBox1.Add(a[c])
   Next
  ServerSocket1.Listen()
  Endif
(19:00 20/July/20)

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 3:14pm
by cogier
Sorry but the expanding form has gone, it's even smaller than before and the program crashes at line 15 'Public mu As Music'

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 6:30pm
by BruceSteers
aah sorry yeah i'd made some other changes like the terminal now has a separate form, is resizable and remembers it's pos/size.
was experimenting seing if any of the controls could convert the audio like the image controls can convert formats but to no success.
Seems i left the Music control deffinition in the declartations :(

I'll try to merge both our changes later. (sorry i'm new to "CO" production)
I'll upload the orig with the changes for now to the old posts.

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 6:35pm
by BruceSteers
Ps, Sorry i didn't mention , i was experimenting with the resizing controls on a blank app not this one. :roll:

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 10:26pm
by BruceSteers
I tried , for ages and couldn't quite figure out how to merge the changes my friend,
Sorry tried to get my head around how you were doing things but in the end i figured it'd be easier for me to do it the way i figured out last night. (i feel bad you wasted your time)

So it's resizeable now (thanks for the nudge) and on exit it will save it's window size, position and the fileview/queuelist split position.
Wav2mp3.zip

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Tuesday 28th July 2020 11:20pm
by BruceSteers
Any views on how i've handled the multiple launching issue with the server socket?
Re. selecting multiple files from desktop and selecting "Open with wav2mp3" made multiple instances of the app load instead of one with multiple args.

I couldn't find any other way , i tried a pipe , but sending text to a pipe was only showing in the gambas IDE i couldn't get the app to react.

In searching for a solution i found on the gambas main development page BenoƮt Minisini saying to someone that gambas apps do not have a way (built in) to receive commands from another process directly and somebody else mentioned the use of sockets as a way around but hadn't tried.
so I tried :D

Anyone know of any other ways around this issue?

I might trim this app down to a bare bones "just add files to a list" so it just handles the multiple launches and could be handy code for someone else.

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Thursday 30th July 2020 3:03pm
by cogier
The program does what it says on the tin. It would be nice to be able to double-click the created file and hear the outcome.
Anyone know of any other ways around this issue?
You could have done this with a 'Task'. I put up an example of this on the Farm called TaskExample. This however only does one background task but you can look at the fun we had maxing out all 8 cores of a processor at once here.

Re: Wav2mp3 (using serversocket for app to app control)

Posted: Thursday 30th July 2020 6:55pm
by BruceSteers
Cool cheers I'll check that out.
I figured how to do the same thing with a pipe last night, itried that first but got stuck..
I was stuck getting a pipe command to not hang the program until the pipe gets some input.
Then i found a workaround setting a timer event to read the pipe but send it a signal first.
Ie.
Shell "echo \"\" >/tmp/fifo1"
Hfile= Pipe "/tmp/fifo1" for read
Etc.

Then the pipe wouldn't hang as it would read the echo and if another process has echoed the pipe it catches that text too so I trimmed the output and checked if It wasnt blank.

Serversocket I'd say was favourable in this case though as pipe uses physical drive.

The pipe code anyway for our fellow gambassers :) ......

Code: Select all

' Gambas class file

Public hFile As File

Public Sub Timer1_Timer() ' timer is set to 2 second interval and enabled in form.
Dim LiveLine, MsgText As String

Shell "echo '' >/tmp/FIFO1"
hFile = Pipe "/tmp/FIFO1" For Read

Do
  Read #hFile, LiveLine, -256
  If Not LiveLine Then Break
 MsgText = LiveLine
Loop
MsgText = Trim(MsgText)
Debug "MsgText='"; MsgText; "'"

' if the MsgText is not blank then something else has been sent to the pipe so this is where your 
' program can react to the message.
If MsgText <> "" Then TextArea1.Text = "Recieved text from pipe /tmp/FIFO1\n'" & MsgText & "'"
End

Public Sub Form_Close()
Kill "/tmp/FIFO1"
Debug "Exitting..."
End

the folder..
Simple pipe example.zip
Gambas docs looks like i should be able to use the "Watch" arg with the Pipe command and trigger a File_Read() event but I couldn't figure out that one, I found all variables of the Pipe command to hang waiting for a message then let go.
So i just used the read option.