Made volume more sensitive and suppressed system beep on "invalid" characters

This commit is contained in:
Mark Hamann 2016-03-03 11:39:59 -08:00
parent 4c40f7ebcc
commit daf15ae264
5 changed files with 116 additions and 8 deletions

View file

@ -171,6 +171,7 @@
this.txtAnalysis.Location = new System.Drawing.Point(20, 288);
this.txtAnalysis.Name = "txtAnalysis";
this.txtAnalysis.ReadOnly = true;
this.txtAnalysis.ShortcutsEnabled = false;
this.txtAnalysis.Size = new System.Drawing.Size(884, 177);
this.txtAnalysis.TabIndex = 8;
this.txtAnalysis.Text = "";

View file

@ -28,7 +28,7 @@ using System.Windows.Forms;
namespace MorseTrainer
{
public partial class Form1 : Form
public partial class Form1 : KeyCaptureForm
{
[Flags]
public enum ControlToUpdate
@ -268,6 +268,7 @@ namespace MorseTrainer
private void _runner_MorseEnter(object sender, EventArgs e)
{
_player.Start();
InputtingKeys = true;
String word = _charGenerator.CreateRandomString();
_builder.StartBuildAsync(word, new AsyncCallback(WaveReadyCallback));
}
@ -315,6 +316,7 @@ namespace MorseTrainer
Analyze();
btnStartStop.Text = "Start";
btnStartStop.Enabled = true;
InputtingKeys = false;
}
}
@ -1261,19 +1263,64 @@ namespace MorseTrainer
{
key = MorseInfo.PROSIGN_AR;
}
String expanded = MorseInfo.ExpandProsigns(key.ToString()).ToUpperInvariant();
txtAnalysis.AppendText(expanded);
_recorded.Append(expanded);
processed = true;
if (key == '\b')
{
// backspace
if (txtAnalysis.TextLength > 0)
{
//txtAnalysis.SuspendLayout();
txtAnalysis.Select(txtAnalysis.TextLength-1, 1);
txtAnalysis.ReadOnly = false;
txtAnalysis.SelectedText = "";
txtAnalysis.ReadOnly = true;
//txtAnalysis.Text = txtAnalysis.Text.Remove(txtAnalysis.TextLength - 1);
//txtAnalysis.Select(txtAnalysis.TextLength, 0);
//txtAnalysis.ResumeLayout();
}
processed = true;
}
else if (key == '\u001b')
{
// esc
processed = true;
}
else if (key == '\r')
{
// enter
processed = true;
}
else
{
String expanded = MorseInfo.ExpandProsigns(key.ToString()).ToUpperInvariant();
txtAnalysis.AppendText(expanded);
_recorded.Append(expanded);
processed = true;
}
return processed;
}
protected override bool IsInputKey(Keys keyData)
{
bool retval = base.IsInputKey(keyData);
return retval;
//return base.IsInputKey(keyData);
}
//protected override bool ProcessMorseKey(Keys keyData)
//{
// //return UserKey(keyData);
// return true;
//}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (_runner.IsListenMode)
{
e.Handled = UserKey(e.KeyChar);
if (UserKey(e.KeyChar))
{
e.Handled = true;
}
}
}
#endregion

View file

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MorseTrainer
{
public class KeyCaptureForm : System.Windows.Forms.Form
{
public KeyCaptureForm() : base()
{
_inputtingKeys = false;
}
/// <summary>
/// This override will suppress system beeps for the key in the richtextbox
/// </summary>
/// <param name="m"></param>
/// <returns></returns>
protected override bool ProcessKeyPreview(ref Message m)
{
if (_inputtingKeys && m.Msg == 0x0100)
{
switch ((uint)m.WParam)
{
case 8: // BackSpace
case 13: // Enter
case 46: // DEL
return true;
default:
break;
}
}
return base.ProcessKeyPreview(ref m);
}
/// <summary>
/// When inputting keys, the form handles all key input
/// </summary>
public bool InputtingKeys
{
get
{
return _inputtingKeys;
}
set
{
_inputtingKeys = value;
}
}
private bool _inputtingKeys;
}
}

View file

@ -55,6 +55,9 @@
<Compile Include="Analyzer.cs" />
<Compile Include="CharGenerator.cs" />
<Compile Include="Config.cs" />
<Compile Include="KeyCaptureForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MorseInfo.cs" />
<Compile Include="Comparer.cs" />
<Compile Include="Form1.cs">

View file

@ -339,8 +339,9 @@ namespace MorseTrainer
else if (sample > actualSamples - fade)
{
envelope = (float)(actualSamples - sample) / (float)fade;
}
float instantaneous = (float)Math.Sin((float)(sample % _samplesPerCycle) / _samplesPerCycle * (2 * Math.PI )) * _volume * envelope;
}
float volume = _volume * _volume * _volume;
float instantaneous = (float)Math.Sin((float)(sample % _samplesPerCycle) / _samplesPerCycle * (2 * Math.PI )) * volume * envelope;
waveform[sample] = (Int16)(32767 * instantaneous);
}