Wav2mp3 (using serversocket for app to app control)

Post

Posted
Rating:
#1 (In Topic #437)
Guru
BruceSteers is in the usergroup ‘Guru’
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
(attachment removed) (bugfixed 19:00 28 July 2020)
(non resizable version , see below for updated one)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.

<IMG src="https://www.cogier.com/gambas/WavToMP3.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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

  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)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Sorry but the expanding form has gone, it's even smaller than before and the program crashes at line 15 'Public mu As Music'
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
Ps, Sorry i didn't mention , i was experimenting with the resizing controls on a blank app not this one.  :roll:
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
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.
(attachment removed)
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’
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

' 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.. (attachment removed)

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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

It would be nice to be able to double-click the created file and hear the outcome.

So be it :)
It now adds completed mp3s to a list and has a built in audio player using the Music class.
I put in a volume control and would have put in a position control if the blummin music class showed how long an audio file was but without knowing the length of the tune i can't put in a position changer.

Have added other things like now it doesn't just check a file has the .wav extension it uses the unix "file" command to check type is audio/* so you can set to view all files and add any audio file that lame supports to convert.

Am also making options for it to hide the main windows if arguments are passed and just show the terminal view.
And an option for it to ask to confirm/change output folder when run with args.

(attachment removed)
Online now: No Back to the top

Post

Posted
Rating:
#12
Guru
BruceSteers is in the usergroup ‘Guru’
Updated…

Now you can drag-n-drop audio files onto app (Main window or terminal) to add them to the queue.

Also added options to hide the main window and just show the terminal when run with args.
also added option for it ask to confirm/change output directory on the first file.
Haven't tested it fully yet.
Seems to be working fine.

(attachment removed) Compiled 3/Aug/2020
Online now: No Back to the top

Post

Posted
Rating:
#13
Regular
vuott is in the usergroup ‘Regular’
...but I do not understand :? what a conversion website have to do with the creation of Gambas programs...

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.