forked from nivs1978/STR2WAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
100 lines (81 loc) · 3.36 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Text;
namespace PlayString
{
class Program
{
[STAThread]
static void Main(string[] args)
{
if (args.Length == 1 && new List<string>(new string[] { "-?", "/?", "-help", "/help" }).Contains(args[0].ToLowerInvariant()))
{
MessageBox.Show(
"STR2WAVE - Convert BASIC play command string into an 8 bit 44100hz mono WAV file.\n\n"+
"Usage: STR2WAV [string] [file]\n\n"+
"Example:\n"+
"STR2WAV T240L8CDEFGAB test.wav"
);
return;
}
if (args.Length == 2)
{
qbplay.GenerateWAVFile(args[0], args[1]);
return;
}
// if run with no args, do a simple popup
string snd = string.Empty;
if (InputBox("STR2WAV", "Enter PLAY string", ref snd) != DialogResult.OK)
return;
//yea- we gonna play it in the GUI mode hell yea
qbplay.PLAY(snd);
while (qbplay.IsPlaying)
System.Threading.Thread.Sleep(0);
qbplay.Shutdown();
// get *.wav save location
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "WAV Files (*.wav)|*.wav";
if (sfd.ShowDialog() != DialogResult.OK)
return;
qbplay.GenerateWAVFile(snd, sfd.FileName);
}
public static DialogResult InputBox(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
}
}