Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 15:04 17 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Copying filepath to DOS MMBasic

Author Message
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 08:26pm 12 Aug 2012
Copy link to clipboard 
Print this post

Can someone help me here please?
I'm trying to copy a file's filepath/name from a PC folder (Win XP Home SP2) to an input statement in the PC's DOS box running my MMBasic program (still using MMBasic V3.2c). The program reads a plain song lyrics text file (.txt), then creates a time-stamp for each text line, and finally writes the time-stamped lines as a .lrc lyric file which my media player can read. It automatically starts the song playing using a Windows "SYSTEM" call and then I have to hit a key for each line at an appropriate time to get the time-stamp for that line.

Everything works fine if the filename is directly entered from a program line but I want to be able to do a copy/paste to the DOS box so that subsequent files can be done without constantly re-typing in a new song's filename in lines of code.

Another problem is that I have to click in the DOS box immediately after the song starts, to activate the MMBasic program again. This is less of an issue but it'd be nice not to have to.

I wonder whether this is a "different instance of Windows" problem as Geoff alludes to in the Manual but I don't know enough about such things!

The file/path input lines are in the first few lines of code"

'-----------------------------------------------------
' Greg's ".lrc" Lyric File Timestamping Program
'-----------------------------------------------------
Print "Input file path: use select, shift/right click, copy as path, ctrl v"
Line Input source$ 'Get song text file name
? "Source$=" source$
Open source$ for input As #1 'this doesn't work
'Open "03 Travelin' Soldier.txt" for input as #1 'this works OK

Option Base 1
Dim lyric$(100) 'Allow for 100 lines?
Dim StampedLine$(100)
LineNum = 1

Do
Line Input #1, lyric$(LineNum) 'Read file & count lines
LineNum = LineNum + 1
Loop Until EOF(#1)
Close #1

For count = 1 to 10 'Display first ten lines
Print lyric$(count)
Next count

Print: Print "Make sure song is zeroed in player!" 'Keypad prompt
Line Input "Hit Return when ready", Dummy$: Print

SYSTEM START "" "C:\Program Files\iTunes\iTunes.exe" /Min "03 Travelin' Soldier.m4a"
Timer=0 'Start song & zero timer

Line = 1
Do While line <= linenum
GoSub GetTimeStamp 'Get timestamp for each line
StampedLine$(line) = TStamp$ +lyric$(line) 'and add the lyrics
Print StampedLine$(line)
line = line + 1
Loop

Outputfile$ = left$(source$,len(source$-4))+".lrc"
Open Outputfile$ for Output as #2
'Open "03 Travelin' Soldier.lrc" for output as #2
Print #2, StampedLine$ 'write the timestamped .lrc file
Close #2
Print "Lyric .lrc file written"

GetTimeStamp:
If Inkey$ = "" Then GoTo GetTimeStamp
key$ = Inkey$
msecs = Timer
fminutes = msecs/60000
iminutes = fix(fminutes)
fseconds = (fminutes - iminutes)*60
Endif
TStamp$ = "["+ format$(iminutes,"%02g") +":"+ format$(fseconds,"%05.2f") +"]"
Return
Edited by paceman 2012-08-14
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 12:20am 13 Aug 2012
Copy link to clipboard 
Print this post

Greg
If you are trying to use ctrl v to do a paste in the dos box then that is not the way. Right click on the dos box title bar, select edit then select paste. Not sure if that works while MMBasic is running a program. See if it gets you some progress.
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 12:28am 13 Aug 2012
Copy link to clipboard 
Print this post

Paceman,

I am able to open a file using a 'string$' on a virtual Windows 7 as I can on the real MM.

When you are pasting in are you sure there is nothing extra in the filename (an extension,/ or \) ?

How does it 'not work'? Do you get a MMbasic error?

Anthony.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:18am 13 Aug 2012
Copy link to clipboard 
Print this post

  BobD said   Greg
If you are trying to use ctrl v to do a paste in the dos box then that is not the way. Right click on the dos box title bar, select edit then select paste. Not sure if that works while MMBasic is running a program. See if it gets you some progress.


Hi Bob,
Yes, it needs to be running my MMbasic program in the DOS box so that it can input the filename (or full path filename). I tried your suggestion but when I right click on the title bar (with my program running), the drop-down box doesn't give a paste option - and CTRLV directly in the box doesn't paste either - nothing seems to paste.
Greg
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:42am 13 Aug 2012
Copy link to clipboard 
Print this post

  ajkw said   Paceman,

I am able to open a file using a 'string$' on a virtual Windows 7 as I can on the real MM.
When you are pasting in are you sure there is nothing extra in the filename (an extension,/ or \) ?
How does it 'not work'? Do you get a MMbasic error?
Anthony.


Hi Anthony,
Yes, if the filename is typed in to the DOS box it accepts it as per normal and opens it properly, but I want to be able to paste it there with CTRLV.
When I do a right click and copy file path on the file in the Win Explorer box it copies the whole path and filename, double slashes and all of course - but it won't paste that with CTRLV into the DOS box with my program running and the query waiting. The same problem occurs if just the filename only is copied (from the same directory that I have my MMBasic.exe and my MMBasic program in.
The error doesn't show of course until after I've hit the CTRLV and then hit the return to conclude the "Line Input" statement. At that point it bombs with "Error: no such file or directory" at the "Open" statement - and nothing shows up at the "Source$=..." print statement.
Greg
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 03:06am 13 Aug 2012
Copy link to clipboard 
Print this post

Greg,

Ok, then it appears we are back to what BobD says. You cannot paste into a DOS box with ctrl v. This is also common behaviour with a linux terminal (i.e. it is not just windows).

You should be able to right click the title bar or even in the window itself to bring up a 'paste' option.

I can paste text to the MMBasic command prompt or a input cursor in Win 7 using the right click method.

Is there a system command to get to the Clipboard????

Cheers,
Anthony.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 04:07am 13 Aug 2012
Copy link to clipboard 
Print this post

  ajkw said   Greg,

You should be able to right click the title bar or even in the window itself to bring up a 'paste' option.
I can paste text to the MMBasic command prompt or a input cursor in Win 7 using the right click method.
Is there a system command to get to the Clipboard????
Cheers,
Anthony.

Hi Anthony/Bob,
This is embarassing - when I right clicked on the title bar of the DOS box there wasn't a "Paste" option - but there was an 'Edit" option which of course had a "Paste" - Duhh! Sorry about that!

I'll try your suggestion anyway Anthony and see if I can find a system command to access the clipboard - that would be neater. At least I can progress a bit now.

Thanks both of you for the help.
Greg
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 04:09am 13 Aug 2012
Copy link to clipboard 
Print this post

  BobD said   Greg
If you are trying to use ctrl v to do a paste in the dos box then that is not the way. Right click on the dos box title bar, select edit then select paste. Not sure if that works while MMBasic is running a program. See if it gets you some progress.

Bob - you spelt it out even - I'll read it more carefully in future.
Greg
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 06:35pm 13 Aug 2012
Copy link to clipboard 
Print this post

Greg, there may be another way to skin this cat.

If you use the DIR command to display all the files that you want to process in the session, and redirect the output to a text file, your MMBasic program could read the file names from the text file. This would save all the cut-and-pasting.

For example, maybe you want to set up the lyrics files for all the .m4a files that start with the letter 'a'.

Here are two ways to redirect the output of "DIR a*.m4a" to a file. One overwrites, the other appends.

DIR a*.m4a /B > lyrics.dat This will write the output to a new file called lyrics.dat, deleting the old file if one existed.

DIR a*.m4a /B >> lyrics.dat This will append the results to the end of the lyrics.dat file. It will create the file if none exists.

The /B option removes any header and footer information, just leaving the file names.

Hope that helps

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 09:33pm 13 Aug 2012
Copy link to clipboard 
Print this post

I think I have it sussed!
Using Win7 64bit, doing a paste of the file path into MMBasic includes quotes.

Try this, which removes the first and last characters from the source$

Print "Input file path: use select, shift/right click, copy as path, ctrl v"
Line Input source$ 'Get song text file name
? "Source$=" source$
source$=mid$(source$,2,len(source$)-2)
? "Source$=" source$
Open source$ for input As #1 'this doesn't work
'Open "03 Travelin' Soldier.txt" for input as #1 'this works OK
print "OK"
close #1


The b...dy quotes were staring me in the face for so long....

Jim
VK7JH
MMedit   MMBasic Help
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 06:03am 15 Aug 2012
Copy link to clipboard 
Print this post

  James_From_Canb said   Greg, there may be another way to skin this cat.
If you use the DIR command to display all the files that you want to process in the session, and redirect the output to a text file, your MMBasic program could read the file names from the text file. This would save all the cut-and-pasting.

James


Hi James,
Would you believe I'd already done exactly that about 18 months ago using "SmallBasic" to convert lyric .lrc files that already had a timestamp (from the MiniLyrics program), to the format readable by my media player (DViCo TViX 4051). SmallBasic runs in a normal Windows window , not the DOS box, and it uses a RUN command to access system commands. Here's the relevant part below:

'Greg's .lrc file conversion program - written using "SmallBASIC Version (0xAABBCC)"
'----------------------------------------------------------- ------------------------
CLS
PRINT "Input full path file or folder to convert - use select, right click, copy path...,
'Ctrl v, return.
LINPUT source
PRINT
name= ISFILE(source) 'check if input is a file or a folder
IF name<>0 THEN 'i.e. input is a file, not an album
file= source
GOSUB convertfile
BEEP
END
ENDIF
'Input not a file, then it is a folder. Create temporary "zzonglist".txt file in that folder
changedir="cd "+source 'set up RUN command variable to change to that folder
'create RUN command variable for listing .lrc files from the album folder
'and re-direct the output lyrics file list (zzonglist.txt) to that folder.
'The "zz..." name places it at end of sorted list.
songlist= "dir *.lrc"+CHR(47)+"b"+">zzonglist.txt" 'CHR(47) is "/"
RUN changedir+"&"+songlist 'run the cd and .lrc list commands and create the zzonglist file
songlist= source+"zzonglist.txt" 'build full filePath for zzonglist.txt
OPEN songlist FOR INPUT AS #1 'open the zzonglist.txt file
REPEAT 'repeat for each lyric file in the list
LINEINPUT #1, file 'read the first, or subsequent lyric file names from "zzonglist.txt"
file= source +file 'add the path
GOSUB convertfile
UNTIL EOF(1)
CLOSE #1
KILL songlist 'delete the temporary "zzonglist.txt" file
BEEP
END

------------------------------------------

I wanted to see if I could use MMBasic for everything though, rather than have two "Basics" on my PC which causes trouble with auto launching files etc - and I wanted to try to become more proficient with MMBasic. Also I hadn't written any SmallBasic for more than a year and it has pretty minimal documentation but it is free!

I did actually manage to convert a song today using my MMBasic code (now modified somewhat) below. The copy/paste works OK if you right click etc. on the title bar as Bob and Anthony said, and then hit return, but it's pretty clunky still. The SYSTEM START command won't accept a variable which holds the music filename to open and I can only type the filename directly into the line.

It does at least launch the iTunes player though now at the right time, (I have it minimised ready to go) so that helps. I then have to remember to quickly click back into the DOS box before I start hitting a key to get a line's timestamp - it would help if I didn't have to do that because it stuffs the timing up a bit.
As I said; a bit clunky.

Current code:

'-----------------------------------------------------
' Greg's ".lrc" Lyric File Timestamping Program
'-----------------------------------------------------
Print "Paste textfile name = ";
Line Input source$ 'Get song text file name
? "Source$ = " source$
Open source$ for input As #1

Option Base 1
Dim lyric$(100) 'Allow for 100 lines?
Dim StampedLine$(100)
LineNum = 1

Do
Line Input #1, lyric$(LineNum) 'Read file & count lines
LineNum = LineNum + 1
Loop Until EOF(#1)
Close #1

'----------------------------------------------------------- -------

Outputfile$ = left$(source$,len(source$)-4) + ".lrc"
Open Outputfile$ for OUTPUT as #1 'Setup & open output .lrc file

'song$ = left$(source$,len(source$)-4)+".m4a"
SYSTEM START "" "03 Travelin' Soldier.m4a" 'Start the song

Timer=0 'Zero the timer

Line = 1: Print
Do While line <= Linenum
Print lyric$(line) 'Display line
GoSub GetTimeStamp 'Get timestamp for line
StampedLine$(line) = TStamp$ +lyric$(line) 'and add the lyrics
Print StampedLine$(line) 'Display timestamped line
Print #1, StampedLine$(line) 'Write line to .lrc file
line = line + 1
Loop
Close #1
Print "Timestamped .lrc file written."
End

'----------------------------------------------------------- --------
GetTimeStamp:
If Inkey$ = "" Then GoTo GetTimeStamp 'Loop waiting for keypress
key$ = Inkey$ 'Save key for future use
msecs = Timer
if line = 1 then msecs1=msecs
fminutes = (msecs-msecs1)/60000
iminutes = fix(fminutes)
fseconds = (fminutes - iminutes)*60
Endif
TStamp$= "["+format$(iminutes,"%02g")+":"+format$(fseconds,"%05.2f")+"]"
Return

------------------------------------------------------------ --------

Cheers,
GregEdited by paceman 2012-08-16
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 06:22am 15 Aug 2012
Copy link to clipboard 
Print this post

  TassyJim said  
I think I have it sussed!
Using Win7 64bit, doing a paste of the file path into MMBasic includes quotes.
Try this, which removes the first and last characters from the source$

Jim


Hi Jim,
I gave that a go but it didn't work, either to directly paste to the DOS box query, or using the right click on the title bar and then edit/paste. The latter does work though if you use the normal CTRLC from the Windows folder file list and then right click/edit/paste on the DOS box title bar.

If you check out the post I just sent to James though and have any ideas about removing the "clunkiness", I'd definitely like to know.

Greg
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 02:20pm 15 Aug 2012
Copy link to clipboard 
Print this post

You seem to be making some progress.
One trick I use which might be useful is to create a batch file and then run the batch file using SYSTEM.
Your program could recreate the batch file for each song and the SYSTEM command would call the same batch file each time so no need for a variable in the command line.

Windows 7 definitely places quotes around the file names so you should allow for this to make the program more portable.
This code checks for leading quotes and removes them as required:
(The *** is there to help see and leading or training spaces)
Print "Input file path: use select, shift/right click, copy as path, ctrl v"
Line Input source$
? "Source$= ***";source$;"***"
if left$(source$,1)=chr$(34) then
source$=mid$(source$,2,len(source$)-2)
? "Source$= ***";source$;"***"
endif
Open source$ for input As #1
print "OK"
close #1


It is good to se that MMBasic can handle long file names and spaces in the path (which is why Windows puts quotes around it)

Two outputs from the above code using rightclick in the menu, edit, paste:
DOS MMBasic Version 3.2C
Copyright 2011, 2012 Geoff Graham

Input file path: use select, shift/right click, copy as path, ctrl v
"C:\apps\ccom\netusage\netusage.tkn"
Source$= ***"C:\apps\ccom\netusage\netusage.tkn"***
Source$= ***C:\apps\ccom\netusage\netusage.tkn***
OK
>

DOS MMBasic Version 3.2C
Copyright 2011, 2012 Geoff Graham

Input file path: use select, shift/right click, copy as path, ctrl v
"C:\Users\Owner\Documents\TurboCAD Deluxe 16\Backups\house addition windows.bak"
Source$= ***"C:\Users\Owner\Documents\TurboCAD Deluxe 16\Backups\house addition windo
ws.bak"***
Source$= ***C:\Users\Owner\Documents\TurboCAD Deluxe 16\Backups\house addition window
s.bak***
OK


Jim

VK7JH
MMedit   MMBasic Help
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 05:05am 16 Aug 2012
Copy link to clipboard 
Print this post

  TassyJim said   You seem to be making some progress.
One trick I use which might be useful is to create a batch file and then run the batch file using SYSTEM.
Your program could recreate the batch file for each song and the SYSTEM command would call the same batch file each time so no need for a variable in the command line.

Jim

Hi again Jim,
I've incorporated the "quote stripping" and I'll have a go at the batch file thing too. I've just realised my timestamps are off by one line though and I'm cogitating on how to best display and handle that, and also that along with songs with delayed starts (which is most of them).

I'll get back to you when it's a goer!

Greg
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 02:09pm 16 Aug 2012
Copy link to clipboard 
Print this post

Greg, try this. It incorporates the best of both. Unfortunately I can't test it fully as I don't have any lyric files. ie, all care, no responsibility...

Main points:
It uses a subroutine to pass the filename
It incorporates the batch files, so the parameter is held in the batch file
It redirects output (note use of the NUL device - very useful for hiding unwanted messages)
It allows either a file name or string that can be used in a DIR command
It deletes its work files after they are used

Possible enhancement:
Ignore files if they have already been processed

As for the timestamp being put on the wrong line, you need to put it on line-1, but it will take a bit of coding to deal with the first and last line.


'-----------------------------------------------------
' Greg's ".lrc" Lyric File Timestamping Program
'-----------------------------------------------------

Option Base 1

Start:

'Get song text file name or DIR parameter
Line Input "Paste textfile name (or Type DIR parameter like a*.m4a): "; source$

' Remove left and right quotes, if they exist.
if left$(source$,1)=chr$(34) then source$=mid$(source$,2,len(source$)-2)
? "Source$ is ..." + source$ + "..."

'The input can be either a file name or a string to be used with the DIR command.
' Check if there's an asterix in the input. If there is, it's a wildcard
' so the input must for the DIR command.

SourceLen = Len(Source$)
bSingleFile = True ' unless we find otherwise
For n = 1 to SourceLen
if mid$(Source$,n,1) = "*" then
bSingleFile = False ' found a wildcard, so not a single file
exit for
endif
Next n

If bSingleFile then
ProcessFile(Source$)
else
Open "RunMe.bat" for output as #1
OutString$ = "DIR " + Source$ + " /ON /B > lyrics.dat"
' ? "About to write DIR command to batch file: " + OutString$
Print #1, OutString$
Print #1, "Exit"
Close #1

'Run batch that redirects DIR results to lyrics.dat.
'Redirect all messages from the batch file to nul (ie, not displayed)
SYSTEM "RunMe.bat > nul"
KILL "RunMe.bat" 'Clean up

'Now read each file name from the lyrics.dat file and process it
Open "Lyrics.dat" for input as #1
FileCount = 0
Do
Line Input #1, FileName$
FileCount = FileCount + 1
? "About to process music file " + Str$(FileCount) + ": " + FileName$
ProcessFile(FileName$)
Loop until EOF(#1)
Close #1
KILL "Lyrics.dat"
endif

? "*******************************************************"

Input "Process another? "; Reply$
If Ucase$(Reply$) = "Y" Then
GOTO Start
Endif

END
'---------------------------------------------------------

SUB ProcessFile(FileName$)
Dim lyric$(100) 'Allow for 100 lines?
Dim StampedLine$(100)
FileLines = 1

Open FileName$ for input as #2
Do
Line Input #2, lyric$(FileLines) 'Read file & count lines
FileLines = FileLines + 1
Loop Until EOF(#2)
Close #2

Open "OpenItunes.bat" for OUTPUT as #2
OutputString$ = "SYSTEM START " + chr$(34) + "C:\Program Files\iTunes\iTunes.exe" + chr$(34)
OutputString$ = OutputString$ + " " + chr$(34) + FileName$ + chr$(34)
' ? OutputString$
Print #2 OutputString$
Close #2

SYSTEM "OpenItunes.bat"

'song$ = left$(source$,len(source$)-4)+".m4a"
'SYSTEM START "" "03 Travelin' Soldier.m4a" 'Start the song

Outputfile$ = left$(source$,len(source$)-4) + ".lrc"
Open Outputfile$ for OUTPUT as #2 'Setup & open output .lrc file

Timer=0 'Zero the timer

Line = 1: Print
Do While line <= FileLines
Print lyric$(line) 'Display line
GoSub GetTimeStamp 'Get timestamp for line
StampedLine$(line) = TStamp$ +lyric$(line) 'and add the lyrics
Print StampedLine$(line) 'Display timestamped line
Print #1, StampedLine$(line) 'Write line to .lrc file
line = line + 1
Loop
Close #2
Print "Timestamped .lrc file written."
KILL "OpenItunes.bat"
End Sub

'----------------------------------------------------------- --------
GetTimeStamp:
If Inkey$ = "" Then GoTo GetTimeStamp 'Loop waiting for keypress
key$ = Inkey$ 'Save key for future use
msecs = Timer
if line = 1 then msecs1=msecs
fminutes = (msecs-msecs1)/60000
iminutes = fix(fminutes)
fseconds = (fminutes - iminutes)*60
Endif
TStamp$= "["+format$(iminutes,"%02g")+":"+format$(fseconds,"%05.2f")+"]"
Return

My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:12pm 16 Aug 2012
Copy link to clipboard 
Print this post

  James_From_Canb said   Greg, try this. It incorporates the best of both. Unfortunately I can't test it fully as I don't have any lyric files. ie, all care, no responsibility...

Main points:
It uses a subroutine to pass the filename
It incorporates the batch files, so the parameter is held in the batch file
It redirects output (note use of the NUL device - very useful for hiding unwanted messages)
It allows either a file name or string that can be used in a DIR command
It deletes its work files after they are used

Possible enhancement:
Ignore files if they have already been processed

As for the timestamp being put on the wrong line, you need to put it on line-1, but it will take a bit of coding to deal with the first and last line.



Holey Moley James,

Talk about support; many thanks for that. I'll digest what you've done and give it a go tonight after I feed myself - then get back to you. My wife's gone to see the folks in Tassie for a few days so I'm spending more time than usual in front of this screen and I need a walk!

Cheers,
Greg
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 05:38am 17 Aug 2012
Copy link to clipboard 
Print this post

  James_From_Canb said   Greg, try this. It incorporates the best of both. Unfortunately I can't test it fully as I don't have any lyric files. ie, all care, no responsibility...

Main points:
It uses a subroutine to pass the filename
It incorporates the batch files, so the parameter is held in the batch file
It redirects output (note use of the NUL device - very useful for hiding unwanted messages)
It allows either a file name or string that can be used in a DIR command
It deletes its work files after they are used



Hi James,
Progress progress - the code below's working but a few caveats.

1.For some reason the True/False test doesn't seem to work correctly - it seems to find a "*" when just a filename is put in so it goes on and writes the batch file and then works as it should from there.

2.Also I had to insert double quotes again to make it accept the OutString$ for the RunMe.bat file. It shouldn't be in that Loop anyway but at least I could get it running!

I've fixed the line number and start/finish line number problem - it's not perfect, but not bad. I'll probably have to manually timestamp the first line of each song because some song's lyrics start quickly and others are well delayed. Either way, getting it right for the first line isn't easy.

There were a couple other bugs I've swatted and iTunes is not starting yet either but I haven't looked into that yet.

Thanks for your help again,
Greg

'----------------------------------------------------------- ------
' Greg's Lyric File Timestamping Program - MMBasic
' converts plain .txt lyric files to timestamped .lrc lyric files
'----------------------------------------------------------- ------

Option Base 1
Start:

' Input can be either a file name or a string to be used with the DIR command
' Check if there's an asterix in the input. If so it's a wildcard so the input
' must be for the DIR command.

Line Input "Paste textfile name or DIR parameter (e.g. 03*.txt): "; source$
'strip any encompassing quotes
if left$(source$,1) = chr$(34) then source$ = mid$(source$,2,len(source$)-2)
? "Source$ is ..." + source$ + "...":?

SourceLen = Len(Source$)
bSingleFile = True 'unless we find otherwise
For n = 1 to SourceLen
if mid$(Source$,n,1) = "*" then
bSingleFile = False 'found a wildcard, so not a single file
exit for
endif
Next n

If bSingleFile then 'input is single file so process it
ProcessFile(Source$)
else 'input is a DIR command so write batch file
Open "RunMe.bat" for output as #1
OutString$ = "DIR "+ chr$(34) + Source$ + chr$(34) + " /O:N /B >lyrics.dat"
' ? "About to write DIR command to batch file: " + OutString$
Print #1, OutString$
Print #1, "Exit"
Close #1

'Run batch that redirects DIR results to lyrics.dat.
'Redirect all messages from the batch file to nul (ie, not displayed)
SYSTEM "RunMe.bat > nul"
KILL "RunMe.bat" 'Clean up

'Now read each file name from the lyrics.dat file and process it
Open "Lyrics.dat" for input as #1
FileCount = 0
Do
Line Input #1, FileName$
FileCount = FileCount + 1
? "About to process music file " + Str$(FileCount) + ": " + FileName$
ProcessFile(FileName$)
Loop until EOF(#1)
Close #1
KILL "Lyrics.dat"
endif

? "*********************************************************** *"

Input "Process another? "; Reply$
If Ucase$(Reply$) = "Y" Then
GOTO Start
Endif

END
?"********************************************************** ****"

SUB ProcessFile(FileName$)
Dim lyric$(100) 'Allow for 100 lines?
Dim StampedLine$(100)
FileLines = 1

Open FileName$ for input as #2
Do
Line Input #2, lyric$(FileLines) 'Read file & count lines
FileLines = FileLines + 1
Loop Until EOF(#2)
Close #2

Open "OpenItunes.bat" for OUTPUT as #2
OutputString$ = "SYSTEM START " + chr$(34) + "C:\Program Files\iTunes\iTunes.exe" + chr$(34)
OutputString$ = OutputString$ + " " + chr$(34) + FileName$ + chr$(34)
' ? OutputString$
Print #2 OutputString$
Close #2

SYSTEM "OpenItunes.bat"

'song$ = left$(source$,len(source$)-4)+".m4a"
'SYSTEM START "" "03 Travelin' Soldier.m4a" 'Start the song

Outputfile$ = left$(source$,len(source$)-4) + ".lrc"
Open Outputfile$ for OUTPUT as #2 'Setup & open output .lrc file

Timer=0 'Zero the timer

Line = 1: Print
Do While line <= FileLines
If line= 1 then
print "[00:00.00]"; 'display "false" timestamp for 1st line
print #2, "[00:00.00]"+lyric$(line) 'write "false" timestamped 1st line
EndIf
Print lyric$(line) 'display the line
If line= FileLines then
Pause 1000 'display last line for a second
Exit 'exit Do Loop & close file
EndIf
GoSub GetTimeStamp 'get timestamp for following line
StampedLine$(line+1) = TStamp$ +lyric$(line+1) 'and add the lyrics
Print #2, StampedLine$(line+1) 'write line to .lrc file
Print TStamp$; 'display timestamp for next line
line = line + 1
Loop
Close #2
Print "Timestamped .lrc file written."
KILL "OpenItunes.bat"
End Sub

'----------------------------------------------------------- --------
GetTimeStamp:
If Inkey$ = "" Then GoTo GetTimeStamp 'Loop waiting for keypress
key$ = Inkey$ 'Save key for future use
msecs = Timer
fminutes = msecs/60000
iminutes = fix(fminutes)
fseconds = (fminutes - iminutes)*60
Endif
TStamp$= "["+format$(iminutes,"%02g")+":"+format$(fseconds,"%05.2f")+"]"
Return

Edited by paceman 2012-08-18
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:35pm 17 Aug 2012
Copy link to clipboard 
Print this post

Point 1: Yep. My bad coding and testing there.
At the top of the program put two new lines

True = 1
False = 0

They're not automatically defined.

Point 2: More bad coding, especially as you said the files would have spaces in them. Oops.

Just a suggestion: if you press a key at the start of the first line, could your code put that timestamp at the beginning of line one, and use your current logic for the rest of the lines? Alternately, carry that logic through for the rest of the program. Each keypress represents the start of a new line, even though you press the key at the end of the previous line. Just ignore the last keypress for the end of the final line. I hope that made some sort of sense.

Remove the word SYSTEM from the batch file that starts itunes. SYSTEM is an MMbasic keyword, not a DOS keyword. ie just START itunes.Edited by James_From_Canb 2012-08-18
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 05:30am 18 Aug 2012
Copy link to clipboard 
Print this post

  James_From_Canb said   Point 1: Yep. My bad coding and testing there.
At the top of the program put two new lines
True = 1
False = 0
They're not automatically defined.
Point 2: More bad coding, especially as you said the files would have spaces in them. Oops.
Just a suggestion: if you press a key at the start of the first line, could your code put that timestamp at the beginning of line one, and use your current logic for the rest of the lines? Alternately, carry that logic through for the rest of the program. Each keypress represents the start of a new line, even though you press the key at the end of the previous line. Just ignore the last keypress for the end of the final line. I hope that made some sort of sense.

Remove the word SYSTEM from the batch file that starts itunes. SYSTEM is an MMbasic keyword, not a DOS keyword. ie just START itunes.


Hi James,

I didn't know true/false had to be defined - learning, learning!
Fixed a few more things:
1.Got iTunes starting OK now. The START command seems to need the "" before the "songfile.m4a" - it doesn't start iTunes without it. SS64 mentions that too.
2.iTunes starts OK with just the song filename (in quotes). It doesn't need the program to be defined. I've got iTunes already going minimised before I start though so that it starts quickly, so that's probably why.
3.All seems to work OK now with a filename as the source$ input but with a directory query e.g. *.m4a input there's a bug in the line:
Line Input #2, lyric$(FileLines)

about ten lines into ProcessFile(FileName$)subroutine. It returns an ERROR "Line is too long". ???? This is a bit weird because it works OK with a file source input and the filename coming from the Songlist.dat file looks OK with the *.m4a source input.

The timing and line display part is working pretty well now. The key is pressed about two thirds the way along the line that is currently displayed. The time that it reads is then ready for the next line and is immediately displayed with the next line so you can read it to be ready for the subsequent one - bit tricky!

Current code below - and thanks again.

'----------------------------------------------------------- ------
' Greg's Lyric File Timestamping Program - MMBasic
' converts plain .txt lyric files to timestamped .lrc lyric files
'----------------------------------------------------------- ------

Option Base 1
True = 1
False = 0

Start:

' Input can be either a file name or a string to be used with the DIR command
' Check if there's an asterix in the input. If so it's a wildcard so the input
' must be for the DIR command.

Line Input "Paste textfile name or DIR parameter (e.g. 03*.txt): "; source$
'strip any encompassing quotes
if left$(source$,1) = chr$(34) then source$ = mid$(source$,2,len(source$)-2)

SourceLen = Len(Source$)
bSingleFile = True 'unless we find otherwise
For n = 1 to SourceLen
if mid$(Source$,n,1) = "*" then
bSingleFile = False 'found a wildcard, so not a single file
exit for
endif
Next n

If bSingleFile then 'input is single file so process it
ProcessFile(Source$)
else 'input is a DIR command so write batch file
Open "RunMe.bat" for output as #1
OutString$ = "DIR "+ chr$(34) + Source$ + chr$(34) + " /O:N /B >SongList.dat"
' About to write DIR command to batch file: " + OutString$
Print #1, OutString$
Print #1, "Exit"
Close #1

' Run batch that redirects DIR results to lyrics.dat.
' Redirect all messages from the batch file to nul (ie, not displayed)
SYSTEM "RunMe.bat > nul"
KILL "RunMe.bat" 'Clean up

'Now read each file name from the SongList.dat file and process it
Open "SongList.dat" for input as #1
FileCount = 0
Do
Line Input #1, FileName$
FileCount = FileCount + 1
? "About to process music file " + Str$(FileCount) + ": " + FileName$
ProcessFile(FileName$)
Loop until EOF(#1)
Close #1
KILL "SongList.dat"
endif

? "*********************************************************** *"

Input "Process another? "; Reply$
If Ucase$(Reply$) = "Y" Then
GOTO Start
Endif

END

?"********************************************************** ****"
SUB ProcessFile(FileName$)
Dim lyric$(100) 'Allow for 100 lines?
Dim StampedLine$(100)
FileLines = 1

'Read lyrics .txt file & count lines

Open FileName$ for input as #2
Do
Line Input #2, lyric$(FileLines)
FileLines = FileLines + 1
Loop Until EOF(#2)
Close #2

'Setup batch file to start iTunes playing ***need to allow for .mp3 etc***
'OutputString$ command format: ...START "" "MusicFile$"...
'The "" is apparently necessary - they can bracket the window title.

Open "OpenItunes.bat" for OUTPUT as #2
MusicFile$ = left$(Filename$,len(Filename$)-4)+".m4a"
OutputString$ = "START "+chr$(34)+chr$(34)+" "+chr$(34)+MusicFile$+chr$(34)
' ? OutputString$
Print #2, OutputString$
Close #2
SYSTEM "OpenItunes.bat" 'start the song playing

'Setup output .lrc file

Outputfile$ = left$(source$,len(source$)-4) + ".lrc"
Open Outputfile$ for OUTPUT as #2

Timer=0 'Zero the timer

Line = 1: Print
Print "[00:00.00]"; 'display "false" timestamp for 1st line
Print #2, "[00:00.00]"+lyric$(line) 'write "false" timestamped 1st line

Do While line <= 10 'FileLines
Print lyric$(line) 'display the line
If line= FileLines then
Pause 1000 'display last line for a second
Exit 'exit Do Loop & close file
EndIf
GoSub GetTimeStamp 'get timestamp for following line
StampedLine$(line+1) = TStamp$ +lyric$(line+1) 'and add the lyrics
Print #2, StampedLine$(line+1) 'write line to .lrc file
Print TStamp$; 'display timestamp for next line
line = line + 1
Loop
Close #2
Print: Print "Timestamped .lrc file written."
KILL "OpenItunes.bat"
End Sub

'----------------------------------------------------------- --------
GetTimeStamp:
If Inkey$ = "" Then GoTo GetTimeStamp 'Loop waiting for keypress
key$ = Inkey$ 'Save key for future use
msecs = Timer
fminutes = msecs/60000
iminutes = fix(fminutes)
fseconds = (fminutes - iminutes)*60
Endif
TStamp$= "["+format$(iminutes,"%02g")+":"+format$(fseconds,"%05.2f")+"]"
Return



Edited by paceman 2012-08-19
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:02pm 18 Aug 2012
Copy link to clipboard 
Print this post

Ok, that's because your original program prompted for .txt files containing lyrics. I'll send you a message abou it, rather than fill up the forum posts.

My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024