-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cs
196 lines (150 loc) · 5.65 KB
/
init.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
$Instruments::Version = "1.4.2";
$Instruments::NotationVersion = "3";
exec("./classes/InstrumentData.cs");
exec("./classes/InstrumentsNamespace.cs");
exec("./classes/InstrumentsBindset.cs");
if ($Pref::Instruments::SampleFilesCopied $= "") {
$Pref::Instruments::SampleFilesCopied = false;
}
if (!isObject(Instruments)) {
// Shared between client and server
new ScriptObject(Instruments) {
class = "InstrumentsNamespace";
// Constants are shared by both client and server code
// They're just here to make it easier for me in case I want to change something later
// Don't think that changing any of these will allow you do get around any server-side limitations
// They won't.
// Don't change these unless you want to fuck something up
const["HIGHEST_DELAY"] = 5000;
const["LOWEST_DELAY"] = 50;
const["DEFAULT_DELAY"] = 500;
const["HIGHEST_TEMPO"] = mFloor(60000 / 50);
const["LOWEST_TEMPO"] = mFloor(60000 / 5000);
const["DEFAULT_TEMPO"] = 120;
const["MAX_PHRASE_LENGTH"] = 255;
const["SONG_ORDER_LIMIT"] = 120;
const["MAX_SONG_PHRASES"] = 50;
const["MIN_SONG_PHRASES"] = 20;
const["NUM_KEY_ROWS"] = 6;
const["NUM_KEY_COLUMNS"] = 14;
const["MAX_BINDS"] = 84;
const["DISALLOWED_KEYS"] = "escape\tf1\tf10\tf11\tf12\tNUMLOCK\tNUMPADMULT\t`\t~\tCAPSLOCK\tSCROLLLOCK" TAB
"insert\thome\tpageup\tdelete\tend\tpagedown";
const["MAX_FILENAME_LENGTH"] = 32;
const["INSTRUMENT_LIST_CHUNK_SIZE"] = 6;
const["FILE_LIST_CHUNK_SIZE"] = 6;
const["MAX_PACKET_LENGTH"] = 170; // The actual limit is 250 chars, but let's play it safe
// Old constants before an update changed them or made them more flexible
const["OLD_MAX_SONG_PHRASES"] = 20;
};
}
function Instruments::isKeyAllowed(%this, %key) {
if (getWordCount(%key) > 1 || getWordCount(%key) < 1) {
return false;
}
%disallowed = Instruments.const["DISALLOWED_KEYS"];
%count = getFieldCount(%disallowed);
for (%i = 0; %i < %count; %i++) {
%disallowedKey = getField(%disallowed, %i);
if (%key $= %disallowedKey) {
return false;
}
}
return true;
}
// The built-in `fileCopy` function doesn't work for .zip files
function Instruments::copyFile(%this, %source, %destination) {
if (!isFile(%source)) {
return false;
}
%read = new FileObject();
%success = %read.openForRead(%source);
%write = new FileObject();
%success = %success && %write.openForWrite(%destination);
if (%success) {
while (!%read.isEoF()) {
%line = %read.readLine();
%write.writeLine(%line);
}
}
%read.close();
%read.delete();
%write.close();
%write.delete();
if (!%success) {
return false;
}
return isFile(%destination);
}
function Instruments::copySampleFiles(%this, %type) {
%type = strLwr(%type);
if (%type $= "bindset") {
%path = "Add-Ons/System_Instruments/common/files/sampleBindsets/*.txt";
}
else if (%type $= "phrase") {
%path = "Add-Ons/System_Instruments/common/files/samplePhrases/*.txt";
}
else if (%type $= "song") {
%path = "Add-Ons/System_Instruments/common/files/sampleSongs/*.txt";
}
else {
return;
}
%folderPath = "instruments/" @ %type @ "s/";
createPath("config/client/" @ %folderPath);
createPath("config/server/" @ %folderPath);
%success = true;
for (%file = findFirstFile(%path); %file !$= ""; %file = findNextFile(%path)) {
%clientPath = "config/client/" @ %folderPath @ fileName(%file);
%serverPath = "config/server/" @ %folderPath @ fileName(%file);
if (!isFile(%clientPath)) {
if (!Instruments.copyFile(%file, %clientPath)) {
%success = false;
}
}
if (!isFile(%serverPath)) {
if (!Instruments.copyFile(%file, %serverPath)) {
%success = false;
}
}
}
if (%success) {
$Pref::Instruments::CopiedSampleFiles = true;
}
}
if (!$Pref::Instruments::CopiedSampleFiles) {
Instruments.copySampleFiles("bindset");
Instruments.copySampleFiles("phrase");
Instruments.copySampleFiles("song");
}
function Instruments::init(%this) {
%type = -1;
// I don't know if I'm going to use even half of these -- adding just in case I need them later
$Instruments::Types::Warning["General"] = %type++;
$Instruments::Types::Warning["Loading"] = %type++;
$Instruments::Types::Warning["Saving"] = %type++;
$Instruments::Types::Warning["Deleting"] = %type++;
$Instruments::Types::Warning["Renaming"] = %type++;
$Instruments::Types::Warning["Playing"] = %type++;
$Instruments::Types::Warning["Phrase"] = %type++;
$Instruments::Types::Warning["SongPhrase"] = %type++;
$Instruments::Types::Warning["Song"] = %type++;
$Instruments::Types::Warning["Bindset"] = %type++;
$Instruments::Types::Warning["Permissions"] = %type++;
$Instruments::Types::Warning["Instrument"] = %type++;
// Magic numbers
// Don't change these
%notePitches = "1\t1.06\t1.12\t1.19\t0.945\t1\t1.06\t1.12\t1.19\t1.2625\t0.8925\t0.945";
// There doesn't seem to be a consistent pattern so it was pretty much trial and error
%noteIntervals = "C\tC\tC\tC\tF\tF\tF\tF\tF\tF\tC\tC";
$Instruments::Notes = "C\tCS\tD\tDS\tE\tF\tFS\tG\tGS\tA\tAS\tB";
%notes = $Instruments::Notes;
%length = getFieldCount(%noteIntervals);
for (%n = 0; %n < %length; %n++) {
// Used to convert melodic notes to "interval" note (actual C or F sound file of corresponding octave)
$Instruments::NoteToInterval[getField(%notes, %n)] = getField(%noteIntervals, %n);
// Used to determine how much said note will be pitched up or down
$Instruments::NoteToPitch[getField(%notes, %n)] = getField(%notePitches, %n);
}
}
Instruments.init();