Older Version
Newer Version
StPendl
Jun 3, 2009
HTML Music
The automatically creates a web page Tune List.htm of links to up to 5000 MID, MP3, and WMA files in a folder to be uploaded to a site. Though there are of course copyright restrictions of even allowing others to play MP3 etc music tracks online let alone download copies, there appear to no such restrictions on the many thousands of MID file available on the Internet. You can see an example of some of my favourite MIDis using a Tune List.htm from the PC Music Page at http://www.sigord.co.uk/
The code below is mostly straightforward, much based on kind help provided over the years by such as Alyce and Stefan. You will notice it can safely be compacted into a single file with Windows Iexpress wherever that is kept, as when first run it needs to locate the folder with all the sound files in order to save the HTML Heads.txt holding the headings, and Tune List.htm for uploading.
Notice there are Error traps such as warning if you are not logged onto the folder with the sound files, also preventing anyone using more than 10 headings, or 5000 sound files. Likewise the main window #h is closed when notepad is used. Those like me with even a limited knowledge of HTML should be able to change such as the colours or font size created with Tune List.htm.
Gordon
' Auto music web page for MID, MP3, WMA only
nomainwin
dim head$(20) : dim file$(5000)
dim info$(1,1) : dim dir$(10,3) : File$ =""""
[start]
WindowWidth = 800 : WindowHeight = 600
button #h,"Set the Headings","Set the Headings", [heads], LL 30, 20
button #h,"Load"Load Musicfiles",files", [music], LL 180, 20
button #h,"Create"Create Web Page",", [create], LL 330, 20
button #h,"" Test Web Page",", [test], LL 480, 20
button #h,"" Show HTML code",", [html], LL 630, 20
open"HTML"HTML MusicPage"Page" for graphics as #h
#h"trapclose"trapclose [quit]; down; fillwhite"white" : gosub [notes]
hfile$ ="HTML Heads.txt""HTML Heads.txt" : page$ ="Tune List.htm"#h "place"Tune List.htm"
#h "place 240 300 ; colorred"red"
if File$ <>"" then#h "place"" then
#h "place 10 300; colorblack"black"
for d = 1 to nhead
tb = 80 - len(head$(d))
#h"\";space$(tb);d;" ";head$(d)"\";space$(tb);d;" ";head$(d)
next d
end if
#h"flush""flush" : playwave"ping""ping" : wait
[notes]
#h"font"font arial 24 bold; color darkgreen; place 24050"#h "\Music50"
#h "\Music Web Pagecoder" : #h "fontcoder" : #h "font arial 14 bold; place 25080"#h "\Ver80"
#h "\Ver 1.2 Produced with LibertyBasic" : #h "placeBasic" : #h "place 100120"#h "\This120"
#h "\This will automatically create a web page as tune list.htm listingall"#h "\musicall"
#h "\music files in the same folder as active links. You may beaware"#h "\thoughaware"
#h "\though there appears to be no copyright restrictions on usingMID"#h "\keyboardMID"
#h "\keyboard files, there are on MP3, WMA recorded music tracksetc."'#h "\Removeetc."'
#h "\Remove any spaces in filenames to avoid poor formatlayouts."#h "[[file:\\You|\\You]]layouts."
#h "[[file://\\You|\\You]] will first be asked to locate the folder with all the MusicFiles"#h "color black"Files"
#h "color black" : return
[files]
filedialog"To"To locate the folder Select sample musicfile", "*.mid;*.mp3;wma",file", "*.mid;*.mp3;wma", File$
if File$ ="""" then [quit]
File$ = upper$(File$)
sFile$ = noPath$(File$)
plen = len(File$)-len(sFile$)
path$ = left$(File$,plen) : DefaultDir$ = path$
files DefaultDir$,hfile$ , info$(
test$ = DefaultDir$ + hfile$
if val(info$(0, 0)) = 0 then
n$ =test$+"beingtest$+"being created!"!" : notice n$
open hfile$ for output as #1
#1"DUMMY HEADING""DUMMY HEADING" : close #1
File$ =""""
end if
return
[heads]
if File$ ="""" then gosub [files]
close #h
op$ ="notepad.exe ""notepad.exe " + DefaultDir$ + hfile$ : run op$
notice"Any"Any changes will nowdisplay"display"
open hfile$ for input as #2
nhead = 0: ok = 0
while ok = 0
if eof(#2) = 0 then
nhead = nhead + 1
if nhead > 10 then
notice"Reduce"Reduce number of headings to limit of10"10"
close #2 : goto [start]
end if
line input #2, i$: head$(nhead)=i$
else
ok = 1
end if
wend
close #2
goto [start]
[music]
if File$ ="""" then gosub [files]
ext$ ="*.*""*.*"
files path$, ext$, dir$()
qtyFiles = val(dir$(0, 0))
'reformat the file information
for x = 1 to qtyFiles
dir$(x, 1) =right$(" "right$(" " + dir$(x, 1), 9)
next x
sorting =int(rnd(1)*4)
sort dir$(), qtyFiles, 1, sorting : nfile = 0
for x = 1 to qtyFiles
temp$ = dir$(x, 0) : chk$ = upper$(right$(temp$,3))
if chk$ ="MID""MID" or temp$ ="MP3""MP3" or temp$ ="WMA""WMA" then
nfile = nfile + 1
if nfile > 5000 then
notice"Reduce"Reduce number of files to limit of5000"5000"
exit for : goto [quit]
end if
file$(nfile) = temp$
end if
next x
if nfile < 5 then notice"FEW"FEW MUSIC FILES??"??" : File$ ="""" : wait
tx$ ="\"#h "cls;"\"
#h "cls; place 20 20; font fixedsys 9; color black; fillwhite"white"
for s = 1 to nfile
tx$ = tx$ + file$(s) +" "" "
if len(tx$) > 75 then #h tx$ : tx$ ="\""\"
next s
#h"[[file:\\";space$(35);"Total|\\";space$(35);"Total]]"[[file://\\";space$(35);"Total|\\";space$(35);"Total]] Music Files =";nfile#h "flush"";nfile
#h "flush" : wait
[create]
if nfile < 5 then notice"NO"NO MUSICFILES"FILES" : wait
if File$ ="""" then gosub [files]
open"Tune List.htm""Tune List.htm" for output as #1
#1"<html><head><title>tunes</title></head>"#1 "<body><body bgcolor=66ff33>"#1 "<font"<html><head><title>tunes</title></head>"
#1 "<body><body bgcolor=66ff33>"
#1 "<font face=arial><font size=5><fontcolor=ff0080>"#1 "<b><center>"color=ff0080>"
#1 "<b><center>"
for t = 1 to nhead
t$="<br>"="<br>" + head$(t) : #1 t$
next t
#1"</center><font"</center><font face=arial><font size=2><fontcolor=000000>"#1 "<blockquote>"color=000000>"
#1 "<blockquote>"
t$=""=""
for n = 1 to nfile
tlen = len(file$(n))-4 : tune$ = left$(file$(n),tlen)
t$ ="  <a href="+file$(n)+">"+tune$+"</a>""  <a href="+file$(n)+">"+tune$+"</a>"
#1 t$
next n
#1"</blockquote>""</blockquote>"
t$ ="<center>Total"<center>Total music files ="" + str$(nfile) +"</center></b>""</center></b>"
#1 t$
#1"</body><html>""</body><html>"
close #1
#h"[[file://\\";space$(30);"Test|\\";space$(30);"Test]]"[[file://\\";space$(30);"Test|\\";space$(30);"Test]] the page or display the HTML code?"?"
wait
[test]
if File$ ="""" then gosub [files]
CALL ShellExecute hWnd, page$
wait
[html]
if File$ ="""" then gosub [files]
close #h
op$ ="notepad.exe ""notepad.exe " + DefaultDir$ + page$ : run op$
confirm"Continue ?";c$"Continue ?";c$
if c$ ="yes""yes" then goto [start] else end
[quit] close #h : end
function noPath$(t$)
while instr(t$,"\")"\")
t$ = mid$(t$, 2)
wend
noPath$ = t$
end function
Sub ShellExecute hWnd, cf$
parameter = _SW_SHOWNORMAL ' set up for viewing
lpszOp$ ="open""open" + Chr$(0) '"open""open" or"play""play" or"print""print"
lpszFile$ = cf$ + Chr$(0)
lpszDir$ = DefaultDir$ + Chr$(0)
lpszParams$=""lpszParams$="" + Chr$(0)
CallDLL #shell32,"ShellExecuteA","ShellExecuteA", hWnd As long,lpszOp$ As ptr,lpszFile$ As ptr,_
lpszParams$ As ptr,lpszDir$ As ptr,parameter As long, result As long
End Sub