La matrice wavinfo fa parte della variabile definita come tipo WAVEBLOCK, che poi viene assegnata alla variabile ttt.
Tali designazioni pubbliche avvengono in fase di dichiarazione, per cui se ridimensioni la matrice waveinfo in runtime, la modifica non si riperquoterà in ttt
Ritengo che ci sia un metodo per ottenere quanto da te richiesto, ma ammetto che in VB6 non mi è mai capitato di doverlo fare, anche perché la doppia designazione è inutile, è sufficiente dichiarare solo ttt.
Il codice seguente funziona, ma è gradita la conferma.
ATTENZIONE nel codice le righe:
' TimeDisplay.SetVal 0, 0, WavCount 'Parameters: value, min, max
' TimeDisplay.SetVal VScroll.value
le ho remmate perché nel mio VB6 l'user control non funziona e non ho impiegato tempo per capire perché
Option Explicit
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Type WAVEFMT
signature As String * 4 ' must contain 'RIFF'
RIFFsize As Long ' size of file (in bytes) minus 8
type As String * 4 ' must contain 'WAVE'
fmtchunk As String * 4 ' must contain 'fmt ' (including blank)
fmtsize As Long ' size of format chunk, must be 16
format As Integer ' normally 1 (PCM)
channels As Integer ' number of channels, 1=mono, 2=stereo
samplerate As Long ' sampling frequency: 11025, 22050 or 44100
average_bps As Long ' average bytes per second; samplerate * channels
align As Integer ' 1=byte aligned, 2=word aligned
bitspersample As Integer ' should be 8 or 16
datchunk As String * 4 ' must contain 'data'
samples As Long ' number of samples
End Type
Private Type POINT
x As Long
y As Long
End Type
'----------------------------------------------------------
' 882 comes from:
' 44100 = 1 second
' 441 = 1/100 second
' 882 = 441 * 2 (2 = stereo)
'----------------------------------------------------------
' eliminata dichiarazione tipo WAVEBLOCKS
Private Type SCROLLER
min As Long
max As Long
value As Long
topval As Long 'Position represented by top line of wavform
End Type
Dim Fil As String
Dim WavCount As Long, WavMin() As Integer, WavMax() As Integer
Dim ttt() As Integer ' ttt può essere direttamente la matrice ridimensionabile
Dim LastPt As POINT
Dim VScroll As SCROLLER
Dim WavSpeed As Integer
Private Sub cmdOpen_Click()
LoadWaveForm
End Sub
Private Sub Command1_Click()
MP.CurrentPosition = MP.CurrentPosition + 0.01
End Sub
Private Sub Form_Load()
LabStatus = ""
WavSpeed = 50 'Default value for Speed Change button
SlideSpeed.value = 100
SlideVolume.value = 100
SlideBalance.value = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
MP.FileName = ""
End Sub
Private Sub PicWave_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MP.CurrentPosition = (VScroll.topval + x) / 100
VScroll.value = VScroll.topval + x
End Sub
Private Sub LoadWaveForm()
Dim t1 As Long, tmin As Integer, tmax As Integer
Dim wavh As WAVEFMT
With CM
.FileName = ""
.Filter = "Wav(*.wav)|*.wav"
.ShowOpen
Fil = .FileName
End With
Me.Refresh 'Do this to remove lingering dialog box lines
If Fil = "" Then Exit Sub
If Dir(Fil, vbNormal) = "" Then Exit Sub
MP.FileName = Fil
'-----------------------------------------
' Only allow wavh.bitspersample = 16!!!
'-----------------------------------------
Open Fil For Binary Access Read As #1
Get #1, , wavh
frmMain.Caption = wavh.samplerate
If wavh.samplerate = 44100 Then
ReDim ttt(1 To 882) As Integer
Else
ReDim ttt(1 To 960) As Integer
End If
WavCount = wavh.samples \ UBound(ttt)
ReDim WavMin(WavCount), WavMax(WavCount)
Screen.MousePointer = vbHourglass
ProgressBar1.max = WavCount
ProgressBar1.value = 0
ProgressBar1.Visible = True
WavCount = -1
Do
Get #1, , ttt
'Find min/max to get a better view of the wave
tmin = 0: tmax = 0
'Should look at all values but 'Step 32' speeds it up a bit
'A nice C++ function to find the max/min would be handy here!
For t1 = 1 To UBound(ttt) Step 32
tmin = IIf(ttt(t1) < tmin, ttt(t1), tmin)
tmax = IIf(ttt(t1) > tmax, ttt(t1), tmax)
Next t1
WavCount = WavCount + 1
WavMin(WavCount) = tmin \ 512 + 64 'Long values become +/-64 then
WavMax(WavCount) = tmax \ 512 + 64 'add 64 to make into co-ordinates
If WavCount Mod 100 = 0 Then ProgressBar1.value = WavCount
Loop Until EOF(1)
Close #1
ProgressBar1.Visible = False
ProgressBar1.value = 0
VScroll.min = 0
VScroll.max = WavCount
VScroll.value = 0
' TimeDisplay.SetVal 0, 0, WavCount 'Parameters: value, min, max
DrawWaveData
Screen.MousePointer = vbDefault
End Sub
Private Sub PlaySpeed_Click()
SlideSpeed.value = IIf(SlideSpeed.value = 100, WavSpeed, 100)
End Sub
Private Sub SlideBalance_Change()
MP.Balance = SlideBalance.value * 100 'Balance is +/- 10000
End Sub
Private Sub SlideBalance_Scroll()
SlideBalance_Change
End Sub
Private Sub SlideSpeed_Change()
If SlideSpeed.value <> 100 Then WavSpeed = SlideSpeed.value
frameSpeed.Caption = "Speed:" & SlideSpeed.value & "%"
End Sub
Private Sub SlideSpeed_Scroll()
SlideSpeed_Change
End Sub
Private Sub SlideVolume_Change()
frameVolume.Caption = "Volume:" & SlideVolume.value & "%"
End Sub
Private Sub SlideVolume_Scroll()
SlideVolume_Change
End Sub
Private Sub TimeDisplay_Change(newPacks As Long)
MP.CurrentPosition = newPacks / 100
End Sub
Private Sub Timer1_Timer()
Dim mpos As Long, mvol As Long
If MP.Rate <> SlideSpeed.value / 100 Then MP.Rate = SlideSpeed.value / 100
mvol = -(100 - SlideVolume.value) * 100 'Media Player volume = 0 (max) to -10000 (min)
If MP.Volume <> mvol Then MP.Volume = mvol
mpos = Int(MP.CurrentPosition * 100)
If mpos >= VScroll.min And mpos <= VScroll.max And VScroll.value <> mpos Then
VScroll.value = mpos
DrawWaveData
End If
End Sub
'-------------------------------------------------
' Main drawing routine
'-------------------------------------------------
' MoveToEx and LineTo are GDI functions, many
' times faster than their VB equivalents and
' just as easy to use
'
' Picture containing the wave form is 400 wide
' so change this code to suit your needs
'-------------------------------------------------
Sub DrawWaveData()
Dim t1 As Long, vstart As Long, hline As Integer
vstart = VScroll.value
'Make sure the cursor starts at the left, moves to the middle,
'then the waveform moves until at the end the cursor moves right
If vstart < 200 Or WavCount < 400 Then 'First 200
hline = vstart
vstart = 0
ElseIf vstart > WavCount - 200 Then 'Last 200
hline = vstart - WavCount + 400
vstart = WavCount - 400
Else 'Anything else
hline = 200
vstart = vstart - 200
End If
VScroll.topval = vstart
PicWave.Cls
PicWave.ForeColor = vbGreen
'Draw each line
For t1 = 0 To IIf(WavCount < 400, WavCount, 400)
MoveToEx PicWave.hdc, t1, WavMin(vstart + t1), LastPt
LineTo PicWave.hdc, t1, WavMax(vstart + t1)
'Marks for 0.1 (small) and 1-second (large) intervals
If (vstart + t1) Mod 10 = 0 Then
MoveToEx PicWave.hdc, t1, 128, LastPt
LineTo PicWave.hdc, t1, IIf((vstart + t1) Mod 100 = 0, 100, 120)
End If
Next t1
MoveToEx PicWave.hdc, 0, 64, LastPt 'Draw center line
LineTo PicWave.hdc, 400, 64
PicWave.ForeColor = vbRed 'Draw cursor line
MoveToEx PicWave.hdc, hline, 0, LastPt
LineTo PicWave.hdc, hline, 500
PicWave.Refresh
LabStatus.Caption = VScroll.value & " of " & WavCount & " (" & WavCount / 100 & " seconds)"
' TimeDisplay.SetVal VScroll.value
End Sub
Ho controllato solo la sincronia...