-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathezd2gm-choose
244 lines (229 loc) · 4.37 KB
/
ezd2gm-choose
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env perl
# Single track, EZdrummer to general midi converter
#
# EZdrummer has more articulations than the limited range of general
# midi, so information is lost by doing this.
#
# Examples:
# perl ezd2gm-choose
# perl ezd2gm-choose --path=/midi/source --dest=/my/music
# perl ezd2gm-choose --midi=/some/midi/file.mid
use strict;
use warnings;
use File::Basename qw(basename);
use File::Find::Rule ();
use File::HomeDir ();
use Getopt::Long qw(GetOptions);
use MIDI ();
use Term::Choose qw(choose);
use constant DIR => '/Logic/Bounces'; # nb: personal desired subdirectory - YMMV
my %opts = (
path => File::HomeDir->my_music . DIR, # source directory for midi files
midi => undef,
dest => File::HomeDir->my_music . DIR, # destination directory for processed midi
);
GetOptions( \%opts,
'path=s',
'midi=s',
'dest=s',
) or die 'Error getting command options';
die "No such directory: $opts{path}" unless -d $opts{path};
die "No such directory: $opts{dest}" unless -d $opts{dest};
if ($opts{midi}) {
die "No such file: $opts{midi}" unless -e $opts{midi};
}
else {
# gather the midi files
my @files = File::Find::Rule->file()
->name(qr/\.midi?$/)
->in($opts{path});
unshift @files, 'Quit';
my %files;
my @names = map { basename($_) } @files;
@files{@names} = @files;
my $choice = choose(\@names, { prompt => 'Choose a MIDI file to process:' });
exit if $choice eq 'Quit';
$opts{midi} = $files{$choice};
}
# create the patch mapping
my %map;
while (my $line = readline(DATA)) {
next if $line =~ /^\s*#/;
chomp $line;
$line =~ s/^\s*//;
$line =~ s/\s*(?:#.*)?\s*$//;
next unless $line;
my ($key, $val) = split /\s*=>\s*/, $line;
$map{$key} = $val;
}
my $opus = MIDI::Opus->new({ from_file => $opts{midi} });
my @events;
# process the midi
for my $t ( $opus->tracks ) {
my $score_r = MIDI::Score::events_r_to_score_r($t->events_r);
# map the note events
for my $event (@$score_r) {
# ['note', <start>, <duration>, <channel>, <note>, <velocity>]
if ($event->[0] eq 'note') {
$event->[4] = $map{ $event->[4] } ? $map{ $event->[4] } : $event->[4];
}
push @events, $event;
}
}
# convert to a new opus
my $events_r = MIDI::Score::score_r_to_events_r(\@events);
my $track = MIDI::Track->new;
$track->events_r($events_r);
my $fresh = MIDI::Opus->new({ ticks => $opus->ticks, tracks => [ $track ] });
my $out = "$opts{dest}/ezd2gm-choose.mid";
$fresh->write_to_file($out);
print "Wrote $out\n";
__DATA__
# EZdrummer midinums => general midi patches
# closed hh
11 => 42 # TODO which EZd articulation is this?
22 => 42 # "
61 => 42 # ...
62 => 42
63 => 42
65 => 42
122 => 42
# pedal hh
10 => 44
21 => 44
# open hh
8 => 46
9 => 46
12 => 46
13 => 46
14 => 46
15 => 46
16 => 46
17 => 46
18 => 46
19 => 46
20 => 46
24 => 46
25 => 46
26 => 46
60 => 46
64 => 46
120 => 46
121 => 46
122 => 46
123 => 46
124 => 46
# crash 1
55 => 49
56 => 49
83 => 49
84 => 49
86 => 49
87 => 49
# crash 2
27 => 57
28 => 57
49 => 57
50 => 57
88 => 57
89 => 57
90 => 57
91 => 57
92 => 57
93 => 57
94 => 57
# splash
57 => 55
58 => 55
58 => 55
100 => 55
101 => 55
103 => 55
106 => 55
107 => 55
# china
95 => 52
96 => 52
98 => 52
99 => 52
# ride 1
29 => 51
52 => 51
54 => 51
59 => 51
104 => 51
108 => 51
111 => 51
113 => 51
116 => 51
118 => 51
# ride 2
52 => 59
#59 => 59
110 => 59
115 => 59
119 => 59
# ride bell
30 => 53
53 => 53
85 => 53
88 => 53
90 => 53
92 => 53
93 => 53
97 => 53
100 => 53
102 => 53
105 => 53
109 => 53
112 => 53
114 => 53
117 => 53
# snare
6 => 38
33 => 38
#38 => 38
39 => 38
40 => 38
66 => 38
68 => 38
69 => 38
70 => 38
71 => 38
76 => 38
125 => 38
126 => 38
# sidestick
#37 => 37
67 => 37
127 => 37
# kick
34 => 35
#35 => 35
#36 => 36
# high-mid tom
#48 => 48
81 => 48
82 => 48
# low-mid tom
#47 => 47
79 => 47
80 => 47
# low tom
#45 => 45
77 => 45
78 => 45
# floortom 1
#43 => 43
74 => 43
75 => 43
# floortom 2
#41 => 41
72 => 41
73 => 41
# tambourine
3 => 54
# maracas
2 => 70
# hand clap
1 => 39