Skip to content

Commit

Permalink
EqualizerPresetDetailsPresenter/View: Added logic. Now updating faders.
Browse files Browse the repository at this point in the history
iOS: Changed long press duration from 1 second to 0.7 second.

Related to issue #405 and issue #417.
  • Loading branch information
ycastonguay committed Apr 24, 2013
1 parent 915c35b commit e85d65d
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 152 deletions.
27 changes: 6 additions & 21 deletions MPfm/MPfm.Library/Database/DatabaseFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,49 +438,34 @@ public void DeleteFolders()

#region Equalizers

/// <summary>
/// Select all EQ presets from the database.
/// </summary>
/// <returns>List of EQPresets</returns>
public List<EQPreset> SelectEQPresets()
{
List<EQPreset> eqs = _gateway.Select<EQPreset>("SELECT * FROM EQPresets");
return eqs;
}

/// <summary>
/// Selects an EQ preset from the database.
/// </summary>
/// <param name="name">EQ preset name</param>
/// <returns>EQPreset</returns>
public EQPreset SelectEQPreset(Guid presetId)
{
EQPreset preset = _gateway.SelectOne<EQPreset>("SELECT * FROM EQPresets WHERE EQPresetId = '" + FormatSQLValue(presetId.ToString()) + "'");
return preset;
}

public EQPreset SelectEQPreset(string name)
{
EQPreset preset = _gateway.SelectOne<EQPreset>("SELECT * FROM EQPresets WHERE Name = '" + FormatSQLValue(name) + "'");
return preset;
}

/// <summary>
/// Inserts a new EQ preset into the database.
/// </summary>
/// <param name="eq">EQ preset to insert</param>
public void InsertEQPreset(EQPreset eq)
{
_gateway.Insert<EQPreset>(eq, "EQPresets");
}

/// <summary>
/// Updates an existing EQ preset in the database.
/// </summary>
/// <param name="eq">EQ preset to update</param>
public void UpdateEQPreset(EQPreset eq)
{
_gateway.Update<EQPreset>(eq, "EQPresets", "EQPresetId", eq.EQPresetId);
}

/// <summary>
/// Deletes an EQ preset from the database.
/// </summary>
/// <param name="eqPresetId">EQ preset identifier</param>
public void DeleteEQPreset(Guid eqPresetId)
{
// Delete item
Expand Down
1 change: 1 addition & 0 deletions MPfm/MPfm.Library/Database/Interfaces/IDatabaseFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public interface IDatabaseFacade
List<string> SelectDistinctArtistNames();
List<string> SelectDistinctArtistNames(AudioFileFormat audioFileFormat);
EQPreset SelectEQPreset(string name);
EQPreset SelectEQPreset(Guid presetId);
List<EQPreset> SelectEQPresets();
Folder SelectFolderByPath(string path);
List<Folder> SelectFolders();
Expand Down
91 changes: 65 additions & 26 deletions MPfm/MPfm.MVP/Presenters/EqualizerPresetDetailsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,94 @@
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using MPfm.Player.Objects;

namespace MPfm.MVP.Presenters
{
public class EqualizerPresetDetailsPresenter : BasePresenter<IEqualizerPresetDetailsView>, IEqualizerPresetDetailsPresenter
{
readonly IPlayerService playerService;
readonly IPlayerService _playerService;
readonly ILibraryService _libraryService;

public EqualizerPresetDetailsPresenter(IPlayerService playerService)
public EqualizerPresetDetailsPresenter(IPlayerService playerService, ILibraryService libraryService)
{
// Set properties
this.playerService = playerService;
_playerService = playerService;
_libraryService = libraryService;
}

public void SetEQParam(int index, float value)
public override void BindView(IEqualizerPresetDetailsView view)
{
// Set EQ and update UI
playerService.UpdateEQBand(index, value, true);
View.UpdateFader(index, value);
}

public void BypassEQ()
{
playerService.BypassEQ();
}
base.BindView(view);

public void AutoLevel()
{
}

public void Reset()
{
playerService.ResetEQ();
for (int a = 0; a < 18; a++)
View.UpdateFader(a, 0);
view.OnNormalizePreset = NormalizePreset;
view.OnResetPreset = ResetPreset;
view.OnSavePreset = SavePreset;

ResetPreset();
}

public void LoadPreset(string presetName)
public void NormalizePreset()
{
try
{
// TODO: Add from Windows code
}
catch(Exception ex)
{
Console.WriteLine("An error occured while normalizing the equalizer preset: " + ex.Message);
View.EqualizerPresetDetailsError(ex);
}
}

public void SavePreset(string presetName)
public void ResetPreset()
{
try
{
_playerService.ResetEQ();
View.RefreshFaders(new List<KeyValuePair<string, float>>() {
new KeyValuePair<string, float>("55 Hz", 0),
new KeyValuePair<string, float>("77 Hz", 0),
new KeyValuePair<string, float>("110 Hz", 0),
new KeyValuePair<string, float>("156 Hz", 0),
new KeyValuePair<string, float>("220 Hz", 0),
new KeyValuePair<string, float>("311 Hz", 0),
new KeyValuePair<string, float>("440 Hz", 0),
new KeyValuePair<string, float>("622 Hz", 0),
new KeyValuePair<string, float>("880 Hz", 0),
new KeyValuePair<string, float>("1.2 kHz", 0),
new KeyValuePair<string, float>("1.8 kHz", 0),
new KeyValuePair<string, float>("2.5 kHz", 0),
new KeyValuePair<string, float>("3.5 kHz", 0),
new KeyValuePair<string, float>("5 kHz", 0),
new KeyValuePair<string, float>("7 kHz", 0),
new KeyValuePair<string, float>("10 kHz", 0),
new KeyValuePair<string, float>("14 kHz", 0),
new KeyValuePair<string, float>("20 kHz", 0)
});
}
catch(Exception ex)
{
Console.WriteLine("An error occured while reseting the equalizer preset: " + ex.Message);
View.EqualizerPresetDetailsError(ex);
}
}

public void DeletePreset(string presetName)
public void SavePreset(EQPreset preset)
{
try
{
_libraryService.UpdateEQPreset(preset);
}
catch(Exception ex)
{
Console.WriteLine("An error occured while saving the equalizer preset: " + ex.Message);
View.EqualizerPresetDetailsError(ex);
}
}
}
}
Expand Down
36 changes: 26 additions & 10 deletions MPfm/MPfm.MVP/Presenters/EqualizerPresetsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public override void BindView(IEqualizerPresetsView view)
{
base.BindView(view);

view.OnBypassEqualizer = BypassEqualizer;
view.OnAddPreset = AddPreset;
view.OnLoadPreset = LoadPreset;
view.OnEditPreset = EditPreset;
Expand All @@ -54,7 +55,15 @@ public override void BindView(IEqualizerPresetsView view)

private void BypassEqualizer()
{
_playerService.BypassEQ();
try
{
_playerService.BypassEQ();
}
catch(Exception ex)
{
Console.WriteLine("An error occured while bypassing the equalizer: " + ex.Message);
View.EqualizerPresetsError(ex);
}
}

private void AddPreset()
Expand All @@ -66,14 +75,26 @@ private void AddPreset()
}
catch(Exception ex)
{
Console.WriteLine("An error occured while refreshing markera: " + ex.Message);
Console.WriteLine("An error occured while adding an equalizer preset: " + ex.Message);
View.EqualizerPresetsError(ex);
}
}

private void LoadPreset(Guid presetId)
{

try
{
EQPreset preset = _presets.FirstOrDefault(x => x.EQPresetId == presetId);
if(preset != null)
{
_playerService.ApplyEQPreset(preset);
}
}
catch(Exception ex)
{
Console.WriteLine("An error occured while loading an equalizer preset: " + ex.Message);
View.EqualizerPresetsError(ex);
}
}

private void EditPreset(Guid presetId)
Expand All @@ -85,7 +106,7 @@ private void EditPreset(Guid presetId)
}
catch(Exception ex)
{
Console.WriteLine("An error occured while refreshing markera: " + ex.Message);
Console.WriteLine("An error occured while editing an equalizer preset: " + ex.Message);
View.EqualizerPresetsError(ex);
}
}
Expand All @@ -98,17 +119,12 @@ private void RefreshPresets()
{
try
{

_presets = _libraryService.SelectEQPresets().ToList();
_presets.Add(new EQPreset(){
EQPresetId = Guid.Empty,
Name = "Bypass"
});
View.RefreshPresets(_presets);
}
catch(Exception ex)
{
Console.WriteLine("An error occured while refreshing markera: " + ex.Message);
Console.WriteLine("An error occured while refreshing equalizer presets: " + ex.Message);
View.EqualizerPresetsError(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,5 @@ namespace MPfm.MVP.Presenters.Interfaces
{
public interface IEqualizerPresetDetailsPresenter : IBasePresenter<IEqualizerPresetDetailsView>
{
void SetEQParam(int index, float value);
void BypassEQ();
void AutoLevel();
void Reset();

void LoadPreset(string presetName);
void SavePreset(string presetName);
void DeletePreset(string presetName);
}
}

12 changes: 6 additions & 6 deletions MPfm/MPfm.MVP/Presenters/PlayerPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public PlayerPresenter(ITinyMessengerHub messageHub, IPlayerService playerServic
timerRefreshSongPosition.Interval = 100;
timerRefreshSongPosition.Elapsed += HandleTimerRefreshSongPositionElapsed;

// Initialize player
Device device = new Device(){
DriverType = DriverType.DirectSound,
Id = -1
};
playerService.Initialize(device, 44100, 1000, 100);
// // Initialize player
// Device device = new Device(){
// DriverType = DriverType.DirectSound,
// Id = -1
// };
// playerService.Initialize(device, 44100, 1000, 100);
//playerService.OnPlaylistIndexChanged += HandlePlayerOnPlaylistIndexChanged;

// Subscribe to events
Expand Down
48 changes: 20 additions & 28 deletions MPfm/MPfm.MVP/Presenters/SplashPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using MPfm.MVP.Presenters.Interfaces;
using MPfm.MVP.Services.Interfaces;
using MPfm.MVP.Views;
using MPfm.Sound.BassNetWrapper;

namespace MPfm.MVP.Presenters
{
Expand All @@ -28,22 +29,15 @@ namespace MPfm.MVP.Presenters
/// </summary>
public class SplashPresenter : BasePresenter<ISplashView>, ISplashPresenter
{
readonly IInitializationService initializationService;
readonly IInitializationService _initializationService;
readonly IPlayerService _playerService;

#region Constructor and Dispose

/// <summary>
/// Initializes a new instance of the <see cref="SplashPresenter"/> class.
/// </summary>
public SplashPresenter(IInitializationService initializationService)
public SplashPresenter(IInitializationService initializationService, IPlayerService playerService)
{
this.initializationService = initializationService;
_initializationService = initializationService;
_playerService = playerService;
}

#endregion

#region ISplashPresenter implementation

public void Initialize(Action onInitDone)
{
TaskScheduler taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Expand All @@ -53,23 +47,21 @@ public void Initialize(Action onInitDone)
#endif

Task.Factory.StartNew(() =>
{
Console.WriteLine("SplashPresenter - Starting initialization service...");
View.RefreshStatus("Loading...");
initializationService.Initialize();
View.RefreshStatus("Initialization done!");
Console.WriteLine("SplashPresenter - Initialization service done!");
}).ContinueWith((a) =>
{
Console.WriteLine("SplashPresenter - Notifying view...");
View.InitDone();
Console.WriteLine("SplashPresenter - Raising action...");
onInitDone.Invoke();
Console.WriteLine("SplashPresenter - Action raised successfully!");
{
View.RefreshStatus("Loading...");
_initializationService.Initialize();
}).ContinueWith((a) =>
{
// Initialize player
Device device = new Device(){
DriverType = DriverType.DirectSound,
Id = -1
};
_playerService.Initialize(device, 44100, 1000, 100);
View.InitDone();
onInitDone.Invoke();
View.RefreshStatus("Initialization done!");
}, taskScheduler);
}

#endregion

}
}
7 changes: 4 additions & 3 deletions MPfm/MPfm.MVP/Services/Interfaces/ILibraryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ public interface ILibraryService
Dictionary<string, List<string>> SelectDistinctAlbumTitles(AudioFileFormat format);
Dictionary<string, List<string>> SelectDistinctAlbumTitles(AudioFileFormat format, string artistName);

void InsertMarker(Marker marker);
Marker SelectMarker(Guid markerId);
List<Marker> SelectMarkers(Guid audioFileId);
void InsertMarker(Marker marker);
void UpdateMarker(Marker marker);
void DeleteMarker(Guid markerId);

void InsertLoop(Loop Loop);
Loop SelectLoop(Guid LoopId);
List<Loop> SelectLoops(Guid audioFileId);
void InsertLoop(Loop Loop);
void UpdateLoop(Loop Loop);
void DeleteLoop(Guid LoopId);

void InsertEQPreset(EQPreset preset);
EQPreset SelectEQPreset(Guid presetId);
IEnumerable<EQPreset> SelectEQPresets();
void InsertEQPreset(EQPreset preset);
void UpdateEQPreset(EQPreset preset);
void DeleteEQPreset(Guid presetId);
}
Expand Down
Loading

0 comments on commit e85d65d

Please sign in to comment.