Sending changes to a plugin

This commit is contained in:
Norbi Peti 2015-10-19 21:06:15 +02:00
parent c514afacd6
commit 3ecb1440a2
3 changed files with 17 additions and 31 deletions

View file

@ -35,7 +35,8 @@ namespace MCAudioSpectrumAnalyzer
_t = new Timer(); _t = new Timer();
_t.Tick += _t_Tick; _t.Tick += _t_Tick;
//_t.Interval = 25; //40hz refresh rate //_t.Interval = 25; //40hz refresh rate
_t.Interval = 50; //20 Hz //_t.Interval = 50; //20 Hz
_t.Interval = 1000;
_t.Enabled = false; _t.Enabled = false;
_l = left; _l = left;
_r = right; _r = right;

View file

@ -28,18 +28,9 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); 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 // button1
// //
this.button1.Location = new System.Drawing.Point(417, 90); this.button1.Location = new System.Drawing.Point(417, 90);
@ -56,17 +47,13 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(733, 299); this.ClientSize = new System.Drawing.Size(733, 299);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1"; this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
} }
} }

View file

@ -6,6 +6,8 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -15,39 +17,35 @@ namespace MCAudioSpectrumAnalyzer
public partial class Form1 : Form public partial class Form1 : Form
{ {
public static Form1 Instance; public static Form1 Instance;
private static StreamWriter sw = new StreamWriter(new FileStream("output.txt", FileMode.Create));
private static int X = 0;
public Form1() public Form1()
{ {
InitializeComponent(); 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<byte> data) public void Set(List<byte> data)
{ {
if (data.Count < 16) return; 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) private void SetBar(byte index, byte data)
{ {
byte value = (byte)((((double)data) / 255) * 80); byte value = (byte)((((double)data) / 255) * 80);
textBox1.AppendText("SetBar: " + value + "\n"); client.Send(new byte[2] { (byte)(index + 1), data }, 2, new IPEndPoint(IPAddress.Loopback, 5896));
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();
} }
private Analyzer Analyzer;
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
new Analyzer(new ProgressBar(), new ProgressBar(), new ComboBox()).Enable = true; Analyzer.Enable = !Analyzer.Enable;
button1.Enabled = false; button1.Text = (Analyzer.Enable ? "Disable" : "Enable");
button1.Text = "Close to stop";
} }
} }
} }