-
Notifications
You must be signed in to change notification settings - Fork 1
/
ibnkv2_packunpack.cs
170 lines (143 loc) · 7.6 KB
/
ibnkv2_packunpack.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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Be.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ibnktool
{
public class IBNKProjectV2
{
public string version;
public uint globalID;
public string InstrumentManifsest = "instruments.json";
public string OscillatorManifest = "oscillator.json";
public string RandomEffectsManifest = "randeff.json";
public string SensorEffectsManifest = "senseff.json";
public string EnvelopesManifest = "env.json";
public string PercussionMapsManifest = "percmap.json";
public string PercussionsManifest = "percussions.json";
public string List = "_list.json";
}
class IBNKUnpackerv2
{
public Dictionary<int, string> Instruments = new Dictionary<int, string>();
public Dictionary<int, string> Oscillators = new Dictionary<int, string>();
public Dictionary<int, string> RandomEffects = new Dictionary<int, string>();
public Dictionary<int, string> SensorEffects = new Dictionary<int, string>();
public Dictionary<int, string> Envelopes = new Dictionary<int, string>();
public Dictionary<int, string> PercussionMaps = new Dictionary<int, string>();
public Dictionary<int, string> Percussions = new Dictionary<int, string>();
public Dictionary<int, string> List = new Dictionary<int, string>();
private Dictionary<JInstrumentv2, string> ListPathLookup = new Dictionary<JInstrumentv2, string>(); // Weirdest list i've made to date.
public void unpackV2(string output, InstrumentBankv2 bank)
{
var w = new IBNKProjectV2();
w.version = "JAUDIO_V2";
w.globalID = (uint)bank.id;
Directory.CreateDirectory($"{output}/Instruments/");
Directory.CreateDirectory($"{output}/Oscillators/");
Directory.CreateDirectory($"{output}/Envelopes/");
Directory.CreateDirectory($"{output}/RandomEffects/");
Directory.CreateDirectory($"{output}/SensorEffects/");
Directory.CreateDirectory($"{output}/PercussionMaps/");
Directory.CreateDirectory($"{output}/Percussions/");
for (int i = 0; i < bank.Instruments.Length; i++)
{
if (bank.Instruments[i] != null)
{
File.WriteAllText($"{output}/Instruments/INST_{i}.json", JsonConvert.SerializeObject(bank.Instruments[i], Formatting.Indented));
Instruments[i] = $"Instruments/INST_{i}.json";
ListPathLookup[bank.Instruments[i]] = $"Instruments/INST_{i}.json";
}
util.consoleProgress("Unpacking Instruments", i + 1, bank.Instruments.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.Oscillators.Length; i++)
{
if (bank.Oscillators[i] != null)
{
File.WriteAllText($"{output}/Oscillators/OSCI_{i}.json", JsonConvert.SerializeObject(bank.Oscillators[i], Formatting.Indented));
Oscillators[i] = $"Oscillators/OSCI_{i}.json";
}
util.consoleProgress("Unpacking Oscillators", i + 1, bank.Oscillators.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.Envelopes.Length; i++)
{
if (bank.Envelopes[i] != null)
{
File.WriteAllText($"{output}/Envelopes/ENV_{i}.json", JsonConvert.SerializeObject(bank.Envelopes[i], Formatting.Indented));
Envelopes[i] = $"Envelopes/ENV_{i}.json";
}
util.consoleProgress("Unpacking Envelopes", i + 1, bank.Envelopes.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.RandEffects.Length; i++)
{
if (bank.RandEffects[i] != null)
{
File.WriteAllText($"{output}/RandomEffects/RAND_{i}.json", JsonConvert.SerializeObject(bank.RandEffects[i], Formatting.Indented));
RandomEffects[i] = $"RandomEffects/RAND_{i}.json";
}
util.consoleProgress("Unpacking RandEffects", i + 1, bank.RandEffects.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.SenseEffects.Length; i++)
{
if (bank.SenseEffects[i] != null)
{
File.WriteAllText($"{output}/SensorEffects/SENS_{i}.json", JsonConvert.SerializeObject(bank.SenseEffects[i], Formatting.Indented));
SensorEffects[i] = $"SensorEffects/SENS_{i}.json";
}
util.consoleProgress("Unpacking SenseEffects", i + 1, bank.SenseEffects.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.PercussionMaps.Length; i++)
{
if (bank.PercussionMaps[i] != null)
{
File.WriteAllText($"{output}/PercussionMaps/PMAP_{i}.json", JsonConvert.SerializeObject(bank.PercussionMaps[i], Formatting.Indented));
PercussionMaps[i] = $"PercussionMaps/PMAP_{i}.json";
}
util.consoleProgress("Unpacking PercussionMaps", i + 1, bank.PercussionMaps.Length, true);
}
Console.WriteLine();
for (int i = 0; i < bank.Percussions.Length; i++)
{
if (bank.Percussions[i] != null)
{
File.WriteAllText($"{output}/Percussions/PERC_{i}.json", JsonConvert.SerializeObject(bank.Percussions[i], Formatting.Indented));
Percussions[i] = $"Percussions/PERC_{i}.json";
ListPathLookup[bank.Percussions[i]] = $"Percussions/PERC_{i}.json";
}
util.consoleProgress("Unpacking Percussions", i + 1, bank.Percussions.Length, true);
}
Console.WriteLine();
for (int i=0; i < bank.List.Length; i++)
{
var cLI = bank.List[i];
if (cLI == null )
{
List[i] = null;
continue;
}
var str = ListPathLookup[cLI];
List[i] = str;
}
File.WriteAllText($"{output}/{w.InstrumentManifsest}", JsonConvert.SerializeObject(Instruments, Formatting.Indented));
File.WriteAllText($"{output}/{w.OscillatorManifest}", JsonConvert.SerializeObject(Oscillators, Formatting.Indented));
File.WriteAllText($"{output}/{w.RandomEffectsManifest}", JsonConvert.SerializeObject(RandomEffects, Formatting.Indented));
File.WriteAllText($"{output}/{w.SensorEffectsManifest}", JsonConvert.SerializeObject(SensorEffects, Formatting.Indented));
File.WriteAllText($"{output}/{w.EnvelopesManifest}", JsonConvert.SerializeObject(Envelopes, Formatting.Indented));
File.WriteAllText($"{output}/{w.PercussionsManifest}", JsonConvert.SerializeObject(Percussions, Formatting.Indented));
File.WriteAllText($"{output}/{w.PercussionMapsManifest}", JsonConvert.SerializeObject(PercussionMaps, Formatting.Indented));
File.WriteAllText($"{output}/{w.List}", JsonConvert.SerializeObject(List, Formatting.Indented));
Console.WriteLine();
Console.WriteLine("Writing ibnk.json");
File.WriteAllText($"{output}/ibnk.json", JsonConvert.SerializeObject(w, Formatting.Indented));
Console.WriteLine("\nDone");
}
}
}