Skip to content

Commit

Permalink
Windows: Wave form display is now working again in Main window! Volum…
Browse files Browse the repository at this point in the history
…e can also be changed.

Related to issue #422.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent d67e6a4 commit ff2041d
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 530 deletions.
24 changes: 9 additions & 15 deletions MPfm/MPfm.MVP/Helpers/ConfigurationHelper.cs
Expand Up @@ -27,38 +27,32 @@ namespace MPfm.MVP.Helpers
/// </summary>
public static class ConfigurationHelper
{
/// <summary>
/// Current user home directory.
/// </summary>
public static string HomeDirectory;
/// <summary>
/// Current user configuration file path.
/// </summary>
public static string PeakFileDirectory;
public static string ConfigurationFilePath;
/// <summary>
/// Current database file path.
/// </summary>
public static string DatabaseFilePath;
/// <summary>
/// Current log file path.
/// </summary>
public static string LogFilePath;

static ConfigurationHelper()
{
// Get assembly directory
//string assemblyDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
//// Get application data folder path
//// Vista/Windows7: C:\Users\%username%\AppData\Roaming\
//// XP: C:\Documents and Settings\%username%\Application Data\
//applicationDataFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\MPfm";

#if IOS || ANDROID
HomeDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
PeakFileDirectory = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "PeakFiles");
#else
HomeDirectory = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".MPfm");
HomeDirectory = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".MPfm");
PeakFileDirectory = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".MPfm", "PeakFiles");
#endif

// Generate file paths
ConfigurationFilePath = Path.Combine(HomeDirectory, "MPfm.Configuration.xml");
DatabaseFilePath = Path.Combine(HomeDirectory, "MPfm.Database.db");
LogFilePath = Path.Combine(HomeDirectory, "MPfm.Log.txt");
LogFilePath = Path.Combine(HomeDirectory, "MPfm.Log.txt");
}

/// <summary>
Expand Down
30 changes: 19 additions & 11 deletions MPfm/MPfm.MVP/Presenters/PlayerPresenter.cs
Expand Up @@ -110,8 +110,12 @@ public override void BindView(IPlayerView view)

var markers = _libraryService.SelectMarkers(_playerService.CurrentPlaylistItem.AudioFile.Id);
View.RefreshMarkers(markers);

}

View.RefreshPlayerVolume(new PlayerVolumeEntity() {
Volume = 100,
VolumeString = "100%"
});
}

void HandleTimerRefreshSongPositionElapsed(object sender, ElapsedEventArgs e)
Expand All @@ -121,16 +125,21 @@ void HandleTimerRefreshSongPositionElapsed(object sender, ElapsedEventArgs e)

//int available = playerService.GetDataAvailable();

// Create entity
PlayerPositionEntity entity = new PlayerPositionEntity();
entity.PositionBytes = _playerService.GetPosition();
entity.PositionSamples = ConvertAudio.ToPCM(entity.PositionBytes, (uint)_playerService.CurrentPlaylistItem.AudioFile.BitsPerSample, 2);
entity.PositionMS = (int)ConvertAudio.ToMS(entity.PositionSamples, (uint)_playerService.CurrentPlaylistItem.AudioFile.SampleRate);
//entity.Position = available.ToString() + " " + Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.Position = Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.PositionPercentage = ((float)_playerService.GetPosition() / (float)_playerService.CurrentPlaylistItem.LengthBytes) * 100;
try
{
entity.PositionBytes = _playerService.GetPosition();
entity.PositionSamples = ConvertAudio.ToPCM(entity.PositionBytes, (uint)_playerService.CurrentPlaylistItem.AudioFile.BitsPerSample, 2);
entity.PositionMS = (int)ConvertAudio.ToMS(entity.PositionSamples, (uint)_playerService.CurrentPlaylistItem.AudioFile.SampleRate);
//entity.Position = available.ToString() + " " + Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.Position = Conversion.MillisecondsToTimeString((ulong)entity.PositionMS);
entity.PositionPercentage = ((float)_playerService.GetPosition() / (float)_playerService.CurrentPlaylistItem.LengthBytes) * 100;
}
catch (Exception ex)
{
Tracing.Log(string.Format("PlayerPresenter - HandleTimerRefreshSongPositionElapsed - Failed to get player position: {0}", ex));
}

// Send changes to view
View.RefreshPlayerPosition(entity);
}

Expand Down Expand Up @@ -332,8 +341,7 @@ public void SetVolume(float volume)
{
try
{
// Set volume and refresh UI
Tracing.Log("PlayerPresenter.SetVolume -- Setting volume to " + volume.ToString("0.00") + "%");
//Tracing.Log("PlayerPresenter.SetVolume -- Setting volume to " + volume.ToString("0.00") + "%");
_playerService.Volume = volume / 100;
View.RefreshPlayerVolume(new PlayerVolumeEntity(){
Volume = volume,
Expand Down
54 changes: 6 additions & 48 deletions MPfm/MPfm.MVP/Services/InitializationService.cs
Expand Up @@ -52,20 +52,12 @@ public InitializationService(IAudioFileCacheService audioFileCacheService, ISync
/// </summary>
public void Initialize()
{
//// Get application data folder path
//// Vista/Windows7: C:\Users\%username%\AppData\Roaming\
//// XP: C:\Documents and Settings\%username%\Application Data\
//applicationDataFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\MPfm";
// Create missing directories
if(!Directory.Exists(ConfigurationHelper.HomeDirectory))
Directory.CreateDirectory(ConfigurationHelper.HomeDirectory);
if (!Directory.Exists(ConfigurationHelper.PeakFileDirectory))
Directory.CreateDirectory(ConfigurationHelper.PeakFileDirectory);

// Check if the .MPfm directory exists
string directoryPath = ConfigurationHelper.HomeDirectory;
if(!Directory.Exists(directoryPath))
{
// Create directory
Directory.CreateDirectory(directoryPath);
}

// Create trace listener and start logging
CreateTraceListener();
Tracing.Log("====================================================================");

Expand All @@ -76,7 +68,6 @@ public void Initialize()
#endif

Tracing.Log("Started on " + DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString());
Tracing.Log("InitializationService.Initialize -- Starting initialization...");

// Load data needed to start the application
LoadConfiguration();
Expand All @@ -102,44 +93,11 @@ void LoadConfiguration()
// Check for configuration file
Tracing.Log("InitializationService.CreateConfiguration -- Checking for configuration file...");
if (File.Exists(ConfigurationHelper.ConfigurationFilePath))
{
// Load configuration file
MPfmConfig.Instance.Load();
}

//ConfigurationHelper.Save(ConfigurationHelper.ConfigurationFilePath, MPfmConfig.Instance);
//EQPreset preset = EQPresetHelper.Load("/Users/animal/Documents/test.txt");
//EQPresetHelper.Save("/Users/animal/Documents/test.txt", new EQPreset());


// Also create peak file directory if it doesn't exist

//// Check if the configuration file exists
//if (File.Exists(configurationFilePath))
//{
// // Load configuration values
// config.Load();

// // Load peak file options
// bool? peakFileUseCustomDirectory = Config.GetKeyValueGeneric<bool>("PeakFile_UseCustomDirectory");
// string peakFileCustomDirectory = Config.GetKeyValue("PeakFile_CustomDirectory");

// // Set peak file directory
// if (peakFileUseCustomDirectory.HasValue && peakFileUseCustomDirectory.Value)
// {
// // Set custom peak file directory
// PeakFileFolderPath = peakFileCustomDirectory;
// }
// else
// {
// // Set default peak file directory
// PeakFileFolderPath = applicationDataFolderPath + "\\Peak Files\\";
// }
//}
//else
//{
// // Set default peak file directory
// PeakFileFolderPath = applicationDataFolderPath + "\\Peak Files\\";
//}
}

void LoadLibrary()
Expand Down
1 change: 0 additions & 1 deletion MPfm/MPfm.MVP/Services/PlayerService.cs
Expand Up @@ -64,7 +64,6 @@ public PlayerService(ITinyMessengerHub messageHub)

public void Initialize(Device device, int sampleRate, int bufferSize, int updatePeriod)
{
// Initialize player
_player = new MPfm.Player.Player(device, sampleRate, bufferSize, updatePeriod, true);
_player.OnPlaylistIndexChanged += HandleOnPlaylistIndexChanged;
_player.OnAudioInterrupted += HandleOnAudioInterrupted;
Expand Down
2 changes: 0 additions & 2 deletions MPfm/MPfm.Windows/Classes/Forms/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff2041d

Please sign in to comment.