Skip to content

Commit

Permalink
Linux: Implemented EffectsWindow successfully, at least with the curr…
Browse files Browse the repository at this point in the history
…ent window design.

Related to issue #382.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent 551f0a6 commit 4ee7490
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 61 deletions.
270 changes: 256 additions & 14 deletions MPfm/MPfm.GTK/Windows/EffectsWindow.cs
Expand Up @@ -17,10 +17,13 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pango;
using MPfm.MVP;
using MPfm.MVP.Views;
using MPfm.Player.Objects;
using Gtk;

namespace MPfm.GTK.Windows
{
Expand All @@ -29,6 +32,9 @@ namespace MPfm.GTK.Windows
/// </summary>
public partial class EffectsWindow : BaseWindow, IDesktopEffectsView
{
EQPreset _preset;
Gtk.ListStore _storePresets = null;

public EffectsWindow(Action<IBaseView> onViewReady) :
base(Gtk.WindowType.Toplevel, onViewReady)
{
Expand Down Expand Up @@ -83,20 +89,185 @@ private void SetFontProperties()
this.label18Value.ModifyFont(FontDescription.FromString(label1FontName));
}

/// <summary>
/// Raises the delete event (when the form is closing).
/// Prevents the form from closing by hiding it instead.
/// </summary>
/// <param name='o'>Object</param>
/// <param name='args'>Event arguments</param>
protected void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
{
// Prevent window from closing
args.RetVal = true;

// Hide window instead
this.HideAll();
}
protected void OnClickSavePreset(object sender, EventArgs e)
{
OnSavePreset(txtPresetName.Text);
}

protected void OnClickDeletePreset(object sender, EventArgs e)
{
//OnDeletePreset(
}

protected void OnClickNormalizePreset(object sender, EventArgs e)
{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.OkCancel, "Are you sure you wish to normalize this preset?");
md.Response += (o, args) => {
if(args.ResponseId == ResponseType.Ok)
OnNormalizePreset();
};
md.Run();
md.Destroy();
}

protected void OnClickResetPreset(object sender, EventArgs e)
{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.OkCancel, "Are you sure you wish to reset this preset?");
md.Response += (o, args) => {
if(args.ResponseId == ResponseType.Ok)
OnResetPreset();
};
md.Run();
md.Destroy();
}

protected void OnClickNewPreset(object sender, EventArgs e)
{

}

protected void OnEQOnToggled(object sender, EventArgs e)
{
OnBypassEqualizer();
}

protected void OnScaleChangeValue1(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
//string index = vscale.Name.Replace("vscale", "");
//Console.WriteLine("EffectsWindow - OnScaleChangeValue - value: {0} name: {1} index: {2}", vscale.Value, vscale.Name, index);
label1Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label1.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue2(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label2Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label2.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue3(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label3Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label3.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue4(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label4Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label4.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue5(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label5Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label5.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue6(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label6Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label6.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue7(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label7Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label7.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue8(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label8Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label8.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue9(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label9Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label9.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue10(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label10Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label10.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue11(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label11Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label11.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue12(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label12Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label12.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue13(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label13Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label13.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue14(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label14Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label14.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue15(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label15Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label15.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue16(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label16Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label16.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue17(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label17Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label17.Text, (float)vscale.Value);
}

protected void OnScaleChangeValue18(object o, Gtk.ChangeValueArgs args)
{
var vscale = (Gtk.VScale)o;
label18Value.Text = FormatEQValue(vscale.Value);
OnSetFaderGain(label18.Text, (float)vscale.Value);
}

private string FormatEQValue(double value)
{
string strValue = string.Empty;
if(value > 0)
strValue = "+" + value.ToString("0.0").Replace(",",".") + " dB";
else
strValue = value.ToString("0.0").Replace(",",".") + " dB";
return strValue;
}

#region IEqualizerPresetsView implementation

Expand All @@ -109,10 +280,29 @@ protected void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)

public void EqualizerPresetsError(Exception ex)
{
Gtk.Application.Invoke(delegate{
StringBuilder sb = new StringBuilder();
sb.AppendLine("An error occured in the EqualizerPresets component:");
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
}

public void RefreshPresets(IEnumerable<EQPreset> presets, Guid selectedPresetId, bool isEQBypassed)
{
Console.WriteLine("EffectsWindow - RefreshPresets - presets.Count: {0} selectedPresetId: {1} isEQBypassed: {2}", presets.Count(), selectedPresetId, isEQBypassed);
Gtk.Application.Invoke(delegate{
chkEQOn.Active = isEQBypassed;

_storePresets = new ListStore(typeof(string));
foreach(var preset in presets)
_storePresets.AppendValues(preset.Name);
comboPreset.Model = _storePresets;
});
}

public void RefreshOutputMeter(float[] dataLeft, float[] dataRight)
Expand All @@ -138,6 +328,16 @@ public void RefreshVolume(float volume)

public void EqualizerPresetDetailsError(Exception ex)
{
Gtk.Application.Invoke(delegate{
StringBuilder sb = new StringBuilder();
sb.AppendLine("An error occured in the EqualizerPresetDetails component:");
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
}

public void ShowMessage(string title, string message)
Expand All @@ -146,6 +346,48 @@ public void ShowMessage(string title, string message)

public void RefreshPreset(EQPreset preset)
{
Console.WriteLine("EffectsWindow - RefreshPreset");
Gtk.Application.Invoke(delegate{
_preset = preset;

txtPresetName.Text = preset.Name;
label1Value.Text = FormatEQValue(preset.Gain0);
vscale1.Value = preset.Gain0;
label2Value.Text = FormatEQValue(preset.Gain1);
vscale2.Value = preset.Gain1;
label3Value.Text = FormatEQValue(preset.Gain2);
vscale3.Value = preset.Gain2;
label4Value.Text = FormatEQValue(preset.Gain3);
vscale4.Value = preset.Gain3;
label5Value.Text = FormatEQValue(preset.Gain4);
vscale5.Value = preset.Gain4;
label6Value.Text = FormatEQValue(preset.Gain5);
vscale6.Value = preset.Gain5;
label7Value.Text = FormatEQValue(preset.Gain6);
vscale7.Value = preset.Gain6;
label8Value.Text = FormatEQValue(preset.Gain7);
vscale8.Value = preset.Gain7;
label9Value.Text = FormatEQValue(preset.Gain8);
vscale9.Value = preset.Gain8;
label10Value.Text = FormatEQValue(preset.Gain9);
vscale10.Value = preset.Gain9;
label11Value.Text = FormatEQValue(preset.Gain10);
vscale11.Value = preset.Gain10;
label12Value.Text = FormatEQValue(preset.Gain11);
vscale12.Value = preset.Gain11;
label13Value.Text = FormatEQValue(preset.Gain12);
vscale13.Value = preset.Gain12;
label14Value.Text = FormatEQValue(preset.Gain13);
vscale14.Value = preset.Gain13;
label15Value.Text = FormatEQValue(preset.Gain14);
vscale15.Value = preset.Gain14;
label16Value.Text = FormatEQValue(preset.Gain15);
vscale16.Value = preset.Gain15;
label17Value.Text = FormatEQValue(preset.Gain16);
vscale17.Value = preset.Gain16;
label18Value.Text = FormatEQValue(preset.Gain17);
vscale18.Value = preset.Gain17;
});
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions MPfm/MPfm.GTK/Windows/MainWindow.cs
Expand Up @@ -509,7 +509,7 @@ protected void OnAboutActionActivated(object sender, System.EventArgs e)
text += "\nThe BASS.NET audio library is © 2005-2012 radio42.";


MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, text);
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, text);
md.Run();
md.Destroy();
}
Expand Down Expand Up @@ -809,7 +809,7 @@ public void PlayerError(Exception ex)
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
Expand Down Expand Up @@ -910,7 +910,7 @@ public void RefreshSongBrowser(IEnumerable<AudioFile> audioFiles)
catch(Exception ex) {
Console.WriteLine("RefreshSongBrowser - Exception: " + ex.Message + "\n" + ex.StackTrace);
throw ex;
//MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "An error occured while refreshing the Song Browser: " + ex.Message + "\n" + ex.StackTrace);
//MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "An error occured while refreshing the Song Browser: " + ex.Message + "\n" + ex.StackTrace);
//md.Run();
//md.Destroy();
}
Expand Down
4 changes: 2 additions & 2 deletions MPfm/MPfm.GTK/Windows/SyncMenuWindow.cs
Expand Up @@ -212,7 +212,7 @@ public void SyncMenuError(Exception ex)
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
Expand All @@ -221,7 +221,7 @@ public void SyncMenuError(Exception ex)
public void SyncEmptyError(Exception ex)
{
Gtk.Application.Invoke(delegate{
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, ex.Message);
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, ex.Message);
md.Run();
md.Destroy();
});
Expand Down
2 changes: 1 addition & 1 deletion MPfm/MPfm.GTK/Windows/SyncWindow.cs
Expand Up @@ -158,7 +158,7 @@ public void SyncError(Exception ex)
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine(ex.StackTrace);
MessageDialog md = new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, sb.ToString());
md.Run();
md.Destroy();
});
Expand Down

0 comments on commit 4ee7490

Please sign in to comment.