1- Imports System.ComponentModel
1+ Imports System.ComponentModel
22Imports System.Formats.Tar
33Imports System.IO
44Imports System.Windows.Forms.VisualStyles.VisualStyleElement
@@ -7,6 +7,15 @@ Public Class frmMain
77
88 Dim filesToPrcess As List( Of String )
99
10+ ''' <summary>
11+ ''' Execute a process, wait for it to finish and redirect output if needed.
12+ ''' </summary>
13+ ''' <param name="processName"></param>
14+ ''' <param name="processArgs"></param>
15+ ''' <param name="outStr"></param>
16+ ''' <param name="redirOut"></param>
17+ ''' <param name="redirErr"></param>
18+ ''' <returns></returns>
1019 Function ExecuteProcess(processName As String , processArgs As String , ByRef outStr As String , redirOut As Boolean , redirErr As Boolean ) As Integer
1120 Try
1221 Dim myProcess As New Process()
@@ -41,6 +50,9 @@ Public Class frmMain
4150
4251 End Function
4352
53+ ''' <summary>
54+ ''' Processes the files one by one and calls the required function based by the file extension.
55+ ''' </summary>
4456 Sub ProcessFiles()
4557 Dim ret As Integer = 0
4658
@@ -49,9 +61,11 @@ Public Class frmMain
4961 If file.EndsWith( ".bas" , StringComparison.OrdinalIgnoreCase) Then
5062 Dim sharpFileName As String
5163 If optUseFilename.Checked = True Then
64+ 'Use the specified file name
5265 sharpFileName = txtFileName.Text.ToUpper()
5366 Else
5467 If Path.GetFileNameWithoutExtension(file).Length > txtFileName.MaxLength Then
68+ 'Truncate the file name if it is longer than 7 characters (or 16 for Sharp 1500)
5569 sharpFileName = Path.GetFileNameWithoutExtension(file).Substring( 0 , txtFileName.MaxLength).ToUpper()
5670 txtLog.Text &= "Warning! Filename is longer than " & txtFileName.MaxLength & " characters! It will be truncated to " & sharpFileName & vbCrLf & vbCrLf
5771 Else
@@ -75,10 +89,17 @@ Public Class frmMain
7589 End If
7690 txtLog.Text &= "Done." & vbCrLf
7791
92+ 'Always scroll the Log to the end.
7893 txtLog.SelectionStart = txtLog.Text.Length
7994 txtLog.ScrollToCaret()
8095 End Sub
8196
97+ ''' <summary>
98+ ''' Converts a BAS file to audio file
99+ ''' </summary>
100+ ''' <param name="fileName">The file name and path to the BAS file</param>
101+ ''' <param name="sharpFileName">The final name of the file on tape</param>
102+ ''' <returns></returns>
82103 Function ProcessBAS(fileName As String , sharpFileName As String )
83104 Dim out As String = ""
84105 Dim ret As Integer
@@ -88,6 +109,7 @@ Public Class frmMain
88109
89110 My.Application.DoEvents()
90111
112+ 'Convert to binary IMG file first.
91113 imgFile = String .Concat(fileName.AsSpan( 0 , fileName.Length - 3 ), "IMG" )
92114
93115 ret = ExecuteProcess( "ptools\bas2img.exe" , "--pc=" & cmbPcModel.Text & " """ & fileName & """ """ & imgFile & """" , out , True , False )
@@ -104,6 +126,7 @@ Public Class frmMain
104126
105127 My.Application.DoEvents()
106128
129+ 'Convert binary IMG to WAV file.
107130 wavFile = Path.GetDirectoryName(fileName) & "\" & sharpFileName & ".WAV"
108131 If optRename.Checked Then
109132 If My.Computer.FileSystem.FileExists(wavFile) Then
@@ -130,6 +153,7 @@ Public Class frmMain
130153 txtLog.Text &= "Deleting temporary img file: " & imgFile & vbCrLf & vbCrLf
131154 My.Computer.FileSystem.DeleteFile(imgFile)
132155
156+ 'Convert to MP3 if requested.
133157 If optMp3.Checked Then
134158 My.Application.DoEvents()
135159 mp3File = String .Concat(wavFile.AsSpan( 0 , wavFile.Length - 3 ), "MP3" )
@@ -142,6 +166,7 @@ Public Class frmMain
142166 mp3File = String .Concat(wavFile.AsSpan( 0 , wavFile.Length - 4 ), " (" & index & ").MP3" )
143167 End If
144168 End If
169+ '-c number of audio tracks (1=mono), -C bitrate for MP3 (=128kbps), rate = sample rate
145170 ret = ExecuteProcess( "sox\sox.exe" , """" & wavFile & """ -c 1 -C 128 """ & mp3File & """ rate 16000" , out , False , True )
146171 txtLog.Text &= out & vbCrLf
147172 If ret <> 0 Then
@@ -159,12 +184,19 @@ Public Class frmMain
159184 Return 0
160185 End Function
161186
187+ ''' <summary>
188+ ''' Converts an audio file to BAS file
189+ ''' </summary>
190+ ''' <param name="fileName">The file name and path to the audio file</param>
191+ ''' <param name="isMp3">If it is MP3 instead of WAV</param>
192+ ''' <returns></returns>
162193 Function ProcessWAV(fileName As String , isMp3 As Boolean )
163194 Dim out As String = ""
164195 Dim ret As Integer
165196 Dim wavFile As String = fileName
166197 Dim basFile As String
167198
199+ 'Convert MP3 to WAV first if required.
168200 If isMp3 Then
169201 My.Application.DoEvents()
170202 wavFile = String .Concat(fileName.AsSpan( 0 , fileName.Length - 3 ), "WAV" )
@@ -177,6 +209,7 @@ Public Class frmMain
177209 wavFile = String .Concat(fileName.AsSpan( 0 , fileName.Length - 4 ), " (" & index & ").WAV" )
178210 End If
179211 End If
212+ '-c number of audio tracks (1=mono), -b bit depth, rate = sample rate
180213 ret = ExecuteProcess( "sox\sox.exe" , """" & fileName & """ -c 1 -b 8 """ & wavFile & """ rate 16000" , out , False , True )
181214 txtLog.Text &= out & vbCrLf
182215 If ret <> 0 Then
@@ -189,6 +222,7 @@ Public Class frmMain
189222 End If
190223 End If
191224
225+ 'Convert WAV to BAS file
192226 basFile = String .Concat(wavFile.AsSpan( 0 , wavFile.Length - 3 ), "BAS" )
193227 If optRename.Checked Then
194228 If My.Computer.FileSystem.FileExists(basFile) Then
@@ -226,6 +260,7 @@ Public Class frmMain
226260 filesToPrcess.Clear()
227261 txtLog.Clear()
228262
263+ 'Add only the supported files to the process queue
229264 For Each file In files
230265 If file.EndsWith( ".bas" , StringComparison.OrdinalIgnoreCase) OrElse
231266 file.EndsWith( ".wav" , StringComparison.OrdinalIgnoreCase) OrElse
@@ -252,6 +287,7 @@ Public Class frmMain
252287 Text = My.Application.Info.Title & " v" & My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor
253288 filesToPrcess = New List( Of String )
254289
290+ 'Load settings
255291 cmbPcModel.Text = My.Settings.pcModel
256292
257293 If My.Settings.outputFormat = 1 Then
@@ -287,13 +323,16 @@ Public Class frmMain
287323
288324 Private Sub cmbPcModel_SelectedIndexChanged(sender As Object , e As EventArgs) Handles cmbPcModel.SelectedIndexChanged
289325 If cmbPcModel.Text = "1500" Then
326+ 'The only Sharp PC model that supports 16 characters file names.
290327 txtFileName.MaxLength = 16
291328 Else
329+ 'All others support a maximum of 7 characters.
292330 txtFileName.MaxLength = 7
293331 End If
294332 End Sub
295333
296334 Private Sub frmMain_Closing(sender As Object , e As CancelEventArgs) Handles MyBase .Closing
335+ 'Save settings
297336 My.Settings.pcModel = cmbPcModel.Text
298337
299338 If optMp3.Checked Then
0 commit comments