Skip to content
Permalink
Browse files

iOS: WaveFormView now displays a wave form!

Still lots of work to do though, but it doesn't seem to create a memory leak yet.
Bug fixes to PeakFileGenerator and PlayerPresenter.

Related to issue #361 and issue #405.
  • Loading branch information...
ycastonguay committed Mar 12, 2013
1 parent 75edef4 commit 71c65403f63028b51c360f9faa5463532f1b8cae
@@ -128,18 +128,6 @@ void HandleTimerRefreshSongPositionElapsed(object sender, ElapsedEventArgs e)
View.RefreshPlayerPosition(entity);
}

/// <summary>
/// Handles the player playlist index changed event.
/// </summary>
/// <param name='data'>
/// Playlist index changed data.
/// </param>
protected void HandlePlayerOnPlaylistIndexChanged(PlayerPlaylistIndexChangedData data)
{
// Refresh song information
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
}

/// <summary>
/// Starts playback.
/// </summary>
@@ -266,7 +254,7 @@ public void Next()

// Refresh controls
Tracing.Log("PlayerPresenter.Next -- Refreshing song information...");
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
}
catch(Exception ex)
{
@@ -286,7 +274,7 @@ public void Previous()
playerService.Previous();

// Refresh controls
RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
//RefreshSongInformation(playerService.CurrentPlaylistItem.AudioFile);
Tracing.Log("PlayerPresenter.Previous -- Refreshing song information...");
}
catch(Exception ex)
@@ -157,7 +157,7 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
audioFileLength /= 2;

// Check if peak file exists
if (File.Exists(peakFilePath))
if (File.Exists(peakFilePath))
{
// Delete peak file
File.Delete(peakFilePath);
@@ -189,7 +189,6 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)

// Create buffer
data = Marshal.AllocHGlobal(chunkSize);
//buffer = new byte[chunkSize];
buffer = new float[chunkSize];

// Is an event binded to OnProcessData?
@@ -211,9 +210,12 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
if (cancellationToken.IsCancellationRequested)
{
// Set flags, exit loop
Console.WriteLine("PeakFileGenerator - Cancelling...");
cancelled = true;
IsLoading = false;
OnProcessDone(new PeakFileDoneData());
OnProcessDone(new PeakFileDoneData() {
Cancelled = true
});
break;
}

@@ -234,12 +236,11 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
if (a % 2 == 0)
{
// Left channel
floatLeft[a / 2] = buffer[a];
}
else
floatLeft [a / 2] = buffer [a];
} else
{
// Left channel
floatRight[a / 2] = buffer[a];
floatRight [a / 2] = buffer [a];
}
}

@@ -274,14 +275,12 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
OnProcessData(dataProgress);

// Reset min/max list
//listMinMaxForProgressData.Clear();
listMinMaxForProgressData = new List<WaveDataMinMax>();
}

// Increment current block
currentBlock++;
}
while (read == chunkSize);
} while (read == chunkSize);

// Free channel
channelDecode.Free();
@@ -292,14 +291,12 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
floatRight = null;
buffer = null;
minMax = null;
}
catch (Exception ex)
} catch (Exception ex)
{
// Return exception
//e.Result = ex;
throw ex;
}
finally
} finally
{
// Close writer and stream
gzipStream.Close();
@@ -321,8 +318,7 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)
{
// Delete file
File.Delete(peakFilePath);
}
catch
} catch
{
// Just skip this step.
Tracing.Log("Could not delete peak file " + peakFilePath + ".");
@@ -333,17 +329,20 @@ public void GeneratePeakFile(string audioFilePath, string peakFilePath)

// Set completed
IsLoading = false;
OnProcessDone(new PeakFileDoneData());
});
OnProcessDone(new PeakFileDoneData() {
Cancelled = false
});
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}

/// <summary>
/// Cancels the peak file generation.
/// </summary>
public void Cancel()
{
if(IsLoading)
cancellationTokenSource.Cancel();
if (IsLoading)
if(cancellationTokenSource != null)
cancellationTokenSource.Cancel();
}

/// <summary>
@@ -362,6 +361,7 @@ public List<WaveDataMinMax> ReadPeakFile(string peakFilePath)
long audioFileLength = 0;
int chunkSize = 0;
int numberOfBlocks = 0;

int currentBlock = 0;

try
@@ -530,10 +530,11 @@ public class PeakFileProgressData
}

/// <summary>
/// Defines the data used with the OnProcessDone event (actually nothing).
/// Defines the data used with the OnProcessDone event.
/// </summary>
public class PeakFileDoneData
{
public bool Cancelled { get; set; }
}

/// <summary>
@@ -176,9 +176,9 @@ public void RefreshSongInformation(AudioFile audioFile)

if(audioFile != null)
{
Console.WriteLine("PlayerViewCtrl - RefreshSongInformation - " + audioFile.FilePath);
try
{

// Check if the album art needs to be refreshed
string key = audioFile.ArtistName.ToUpper() + "_" + audioFile.AlbumTitle.ToUpper();
if(_currentAlbumArtKey != key)

0 comments on commit 71c6540

Please sign in to comment.
You can’t perform that action at this time.