From 3ecb1440a29a10ca635a6c3912be28d4d41d456e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 19 Oct 2015 21:06:15 +0200 Subject: [PATCH] Sending changes to a plugin --- MCAudioSpectrumAnalyzer/Analyzer.cs | 3 ++- MCAudioSpectrumAnalyzer/Form1.Designer.cs | 13 --------- MCAudioSpectrumAnalyzer/Form1.cs | 32 +++++++++++------------ 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/MCAudioSpectrumAnalyzer/Analyzer.cs b/MCAudioSpectrumAnalyzer/Analyzer.cs index 95b8bd7..c545532 100644 --- a/MCAudioSpectrumAnalyzer/Analyzer.cs +++ b/MCAudioSpectrumAnalyzer/Analyzer.cs @@ -35,7 +35,8 @@ namespace MCAudioSpectrumAnalyzer _t = new Timer(); _t.Tick += _t_Tick; //_t.Interval = 25; //40hz refresh rate - _t.Interval = 50; //20 Hz + //_t.Interval = 50; //20 Hz + _t.Interval = 1000; _t.Enabled = false; _l = left; _r = right; diff --git a/MCAudioSpectrumAnalyzer/Form1.Designer.cs b/MCAudioSpectrumAnalyzer/Form1.Designer.cs index 1c1c708..223abb5 100644 --- a/MCAudioSpectrumAnalyzer/Form1.Designer.cs +++ b/MCAudioSpectrumAnalyzer/Form1.Designer.cs @@ -28,18 +28,9 @@ /// private void InitializeComponent() { - this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // textBox1 - // - this.textBox1.Location = new System.Drawing.Point(25, 29); - this.textBox1.Multiline = true; - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(349, 156); - this.textBox1.TabIndex = 0; - // // button1 // this.button1.Location = new System.Drawing.Point(417, 90); @@ -56,17 +47,13 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(733, 299); this.Controls.Add(this.button1); - this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; } } diff --git a/MCAudioSpectrumAnalyzer/Form1.cs b/MCAudioSpectrumAnalyzer/Form1.cs index d446b8f..0d95989 100644 --- a/MCAudioSpectrumAnalyzer/Form1.cs +++ b/MCAudioSpectrumAnalyzer/Form1.cs @@ -6,6 +6,8 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; +using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -15,39 +17,35 @@ namespace MCAudioSpectrumAnalyzer public partial class Form1 : Form { public static Form1 Instance; - private static StreamWriter sw = new StreamWriter(new FileStream("output.txt", FileMode.Create)); - private static int X = 0; public Form1() { InitializeComponent(); - Instance = this; //TODO: Send to a Java plugin instead + Instance = this; + Analyzer = new Analyzer(new ProgressBar(), new ProgressBar(), new ComboBox()); } public void Set(List data) { if (data.Count < 16) return; - data.ForEach(entry => SetBar(entry, entry)); + for (int i = 0; i < data.Count / 2; i++) + if (data[i] == 0) + SetBar((byte)i, 1); + else + SetBar((byte)i, (byte)(data[i] * 2)); } - + + private UdpClient client = new UdpClient(AddressFamily.InterNetwork); private void SetBar(byte index, byte data) { byte value = (byte)((((double)data) / 255) * 80); - textBox1.AppendText("SetBar: " + value + "\n"); - sw.WriteLine(string.Concat("#", X++, ",64,0" + ":@")); - sw.WriteLine(string.Concat("scoreboard players set t", (X + 1).ToString(), " tracks ", value)); - sw.WriteLine(""); - } - - ~Form1() - { - sw.Close(); + client.Send(new byte[2] { (byte)(index + 1), data }, 2, new IPEndPoint(IPAddress.Loopback, 5896)); } + private Analyzer Analyzer; private void button1_Click(object sender, EventArgs e) { - new Analyzer(new ProgressBar(), new ProgressBar(), new ComboBox()).Enable = true; - button1.Enabled = false; - button1.Text = "Close to stop"; + Analyzer.Enable = !Analyzer.Enable; + button1.Text = (Analyzer.Enable ? "Disable" : "Enable"); } } }