HTML Music Page

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", [heads], LL 30, 20
    button #h, "Load Music files", [music], LL 180, 20
    button #h, "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 Music Page" for graphics as #h
    #h "trapclose [quit]; down; fill white" : gosub [notes]
    hfile$ = "HTML Heads.txt" : page$ = "Tune List.htm"
    #h "place 240 300 ; color red"
    if File$ <> "" then
        #h "place 10 300; color black"
        for d = 1 to nhead
            tb = 80 - len(head$(d))
            #h "\";space$(tb);d;" ";head$(d)
        next d
    end if
    #h "flush" : playwave "ping" : wait
[notes]
    #h "font arial 24 bold; color darkgreen; place 240 50"
    #h "\Music Web Page coder" : #h "font arial 14 bold; place 250 80"
    #h "\Ver 1.2 Produced with Liberty Basic" : #h "place 100 120"
    #h "\This will automatically create a web page as tune list.htm listing all"
    #h "\music files in the same folder as active links. You may be aware"
    #h "\though there appears to be no copyright restrictions on using MID"
    #h "\keyboard files, there are on MP3, WMA recorded music tracks etc."'
    #h "\Remove any spaces in filenames to avoid poor format layouts."
    #h "[[file://\\You|\\You]] will first be asked to locate the folder with all the Music Files"
    #h "color black" : return
[files]
    filedialog "To locate the folder Select sample music 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$+"being created !" : notice n$
        open hfile$ for output as #1
        #1 "DUMMY HEADING" : close #1
        File$ = ""
    end if
    return
[heads]
    if File$ = "" then gosub [files]
    close #h
    op$ = "notepad.exe " + DefaultDir$ + hfile$ : run op$
    notice "Any changes will now 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 number of headings to limit of 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$(" " + 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" or temp$ = "MP3" or temp$ = "WMA" then
            nfile = nfile + 1
            if nfile > 5000 then
                notice "Reduce number of files to limit of 5000"
                exit for : goto [quit]
            end if
            file$(nfile) = temp$
        end if
    next x
    if nfile < 5 then notice "FEW MUSIC FILES ??" : File$ = "" : wait
    tx$ = "\"
    #h "cls; place 20 20; font fixedsys 9; color black; fill 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]] Music Files = ";nfile
    #h "flush" : wait
[create]
    if nfile < 5 then notice "NO MUSIC FILES" : wait
    if File$ = "" then gosub [files]
    open "Tune List.htm" for output as #1
    #1 "<html><head><title>tunes</title></head>"
    #1 "<body><body bgcolor=66ff33>"
    #1 "<font face=arial><font size=5><font color=ff0080>"
    #1 "<b><center>"
    for t = 1 to nhead
        t$ ="<br>" + head$(t) : #1 t$
    next t
    #1 "</center><font face=arial><font size=2><font color=000000>"
    #1 "<blockquote>"
    t$ =""
    for n = 1 to nfile
        tlen = len(file$(n))-4 : tune$ = left$(file$(n),tlen)
        t$ = "&nbsp;&nbsp<a href="+file$(n)+">"+tune$+"</a>"
        #1 t$
    next n
    #1 "</blockquote>"
    t$ = "<center>Total music files = " + str$(nfile) + "</center></b>"
    #1 t$
    #1 "</body><html>"
    close #1
    #h "[[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 " + DefaultDir$ + page$ : run op$
    confirm "Continue ?";c$
    if c$ = "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" + Chr$(0) ' "open" or "play" or "print"
    lpszFile$ = cf$ + Chr$(0)
    lpszDir$ = DefaultDir$ + Chr$(0)
    lpszParams$="" + Chr$(0)
    CallDLL #shell32, "ShellExecuteA", hWnd As long,lpszOp$ As ptr,lpszFile$ As ptr,_
        lpszParams$ As ptr,lpszDir$ As ptr,parameter As long, result As long
End Sub