summaryrefslogtreecommitdiff
path: root/midicsv-1.1/transpose.pl
diff options
context:
space:
mode:
authorpepper <peppersclothescult@gmail.com>2015-01-19 00:02:46 -0800
committerpepper <peppersclothescult@gmail.com>2015-01-19 00:02:46 -0800
commit760d4d5a0fc89e5b14681879577a80e79795e4a3 (patch)
tree3698995f434a00a904f9fdff64a739eb21f53fdb /midicsv-1.1/transpose.pl
Diffstat (limited to 'midicsv-1.1/transpose.pl')
-rw-r--r--midicsv-1.1/transpose.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/midicsv-1.1/transpose.pl b/midicsv-1.1/transpose.pl
new file mode 100644
index 0000000..d2958cb
--- /dev/null
+++ b/midicsv-1.1/transpose.pl
@@ -0,0 +1,34 @@
+
+ # Transpose all notes in a CSV MIDI file
+
+ # This Perl program is an example of how simple it can
+ # be to transform MIDI files in CSV format. This program
+ # filters a CSV MIDI file from standard input to standard
+ # output, shifting all notes by the value given as
+ # $offset. Notes on the $percussion channel are not
+ # shifted.
+
+ $offset = -12;
+ $percussion = 9;
+
+ while ($a = <>) {
+
+ # Recognise Note_on_c and Note_off_c records and crack into:
+
+ # $1 Start of record
+ # $2 Channel number
+ # $3 Note number
+ # $a Balance of record
+
+ if ($a =~ s/(\d+,\s*\d+,\s*Note_\w+,\s*(\d+),\s*)(\d+)//) {
+ $n = $3;
+ if ($2 != $percussion) {
+ $n += $offset;
+ }
+ if ($n < 0) {
+ next;
+ }
+ $a = "$1$n$a";
+ }
+ print($a);
+ }