#!/usr/bin/perl # # dx7sysex2lv2presets - SysEx patchset to LV2 converter for # Dexed.lv2 - LV2 plugin # # This generator converts DX7 SYSEX to LV2 suitable sounds for Dexed # # (c) by H. Wirtz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Hints: # https://github.com/rogerallen/dxsyx/blob/master/dx7-sysex-format.txt # # $ hexdump -v -s6 -e '/1 "%_ad# "' -e '/1 "%02X hex"' -e '/1 " | %03i dec"' -e '/1 " | %03o oct"' -e '/1 " | _%c\_\n"' rom1A.syx |less # $DXSYX="/usr/local/bin/dxsyx"; $LV2_BUNDLE_NAME="dexed.lv2"; $LV2_URI="https://github.com/dcoredump/".$LV2_BUNDLE_NAME; $LV2_INSTALL_PATH="/zynthian/zynthian-my-plugins/lv2"; @CMD_OPTION=@ARGV; while($option=shift(@CMD_OPTION)) { if($option=~/^-(.+)\s*/) { if($1=~/b/i) { $option{'bank'}=1; } elsif($1=~/n/i) { $option{'voice_no'}=1; } } } while($SYSEX=shift(@ARGV)) { next if($SYSEX=~/^-/); $BANK=$SYSEX; $BANK=~s{.*/}{}; # removes path $BANK=~s{\.[^.]+$}{}; # removes extension $_LV2_BUNDLE_NAME="dexed_lv2"; $voice_no=0; open(SYSEX,"$DXSYX -y $SYSEX |") || die ("Cannot open \'$DXSYX -y $SYSEX\': $!"); while($s=) { chop($s); next if($s=~/^\s*$/); next if($s=~/^\s*---\s*$/); next if($s=~/^\s*filename/); if($s=~/^\s+voice_name:\s+(.+)\s*/) { my($voice)=$1; $voice_no++; $voice=~s/\s+$//; # right trim my($voice_name)=$voice; $voice=~tr/[ %ยง&-*+\"\'`\!\$\%\?\/\<\>\[\]\^\{\}]\|/_/; $voice=~s/%3c/_/i; $voice=~s/%3e/_/i; $voice=~s/%5b/_/i; $voice=~s/%5d/_/i; $voice=~s/%5e/_/i; $voice=~s/%7b/_/i; $voice=~s/%7d/_/i; $voice=~s/%7c/_/i; if(defined($option{'voice_no'}) && defined($option{'bank'})) { if($voice_no<10) { $voice=$BANK."__0".$voice_no."__".$voice; } else { $voice=$BANK."__".$voice_no."__".$voice; } } elsif(defined($option{'bank'})) { $voice=$BANK."__".$voice; } elsif(defined($option{'voice_no'})) { $voice=$voice_no."__".$voice; } if($deeaxe_voice) { print $deeaxe_voice " ] .\n"; close($deeaxe_voice); } my($path)=$LV2_INSTALL_PATH."/".$_LV2_BUNDLE_NAME."-".$voice.".lv2"; if(!-d $LV2_INSTALL_PATH) { mkdir($LV2_INSTALL_PATH) || die("Cannot create dir \'$LV2_INSTALL_PATH\':$!\n"); } if(!-d $path) { mkdir($path) || die("Cannot create dir \'$path\':$!\n"); } print "Writing ".$path."/".$voice.".ttl\n"; write_manifest($path,$voice); open($deeaxe_voice,">".$path."/".$voice.".ttl") || die ("Cannot open \'".$path."/".$voice.".ttl\': $!"); write_preset_header($voice,$voice_name); next; } else { print $deeaxe_voice " ] , [\n"; } if($s=~/^\s+(.+):\s*(\d+)/) { print_lv2_port($1,$2); } } if($deeaxe_voice) { print $deeaxe_voice " ] .\n"; close($deeaxe_voice); } close(SYSEX); } sub write_preset_header { ($voice,$voice_name)=@_; print $deeaxe_voice "\@prefix atom: .\n"; print $deeaxe_voice "\@prefix lv2: .\n"; print $deeaxe_voice "\@prefix pset: .\n"; print $deeaxe_voice "\@prefix rdf: .\n"; print $deeaxe_voice "\@prefix rdfs: .\n"; print $deeaxe_voice "\@prefix state: .\n"; print $deeaxe_voice "\@prefix xsd: .\n"; print $deeaxe_voice "\n"; #print $deeaxe_voice "<".$LV2_URI."#".$voice.">\n"; print $deeaxe_voice "<>\n"; print $deeaxe_voice " a pset:Preset ;\n"; print $deeaxe_voice " lv2:appliesTo <".$LV2_URI."> ;\n"; #print $deeaxe_voice " rdfs:label \"".$voice_name."\" ;\n"; print $deeaxe_voice " lv2:port [\n"; print_lv2_port("cutoff","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("resonance","0.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("output","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("engine","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("polymono","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("pitch_bend_range","1"); print $deeaxe_voice " ] , [\n"; print_lv2_port("pitch_bend_step","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("mod_wheel_range","99"); print $deeaxe_voice " ] , [\n"; print_lv2_port("mod_wheel_assign","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("foot_ctrl_range","99"); print $deeaxe_voice " ] , [\n"; print_lv2_port("foot_ctrl_assign","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("breath_ctrl_range","99"); print $deeaxe_voice " ] , [\n"; print_lv2_port("breath_ctrl_assign","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("aftertouch_range","99"); print $deeaxe_voice " ] , [\n"; print_lv2_port("aftertouch_assign","0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("master_tune","0.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op1_enable","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op2_enable","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op3_enable","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op4_enable","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op5_enable","1.0"); print $deeaxe_voice " ] , [\n"; print_lv2_port("op6_enable","1.0"); } sub write_manifest { ($path,$voice)=@_; open(MANIFEST,">$path/manifest.ttl")||die("Cannot open \'$path/manifest.ttl\': $!\n"); print MANIFEST "\@prefix atom: .\n"; print MANIFEST "\@prefix lv2: .\n"; print MANIFEST "\@prefix pset: .\n"; print MANIFEST "\@prefix rdf: .\n"; print MANIFEST "\@prefix rdfs: .\n"; print MANIFEST "\@prefix state: .\n"; print MANIFEST "\@prefix xsd: .\n"; print MANIFEST "\n"; #print MANIFEST "<".$LV2_URI."#".$voice.">\n"; print MANIFEST "<".$voice.".ttl>\n"; print MANIFEST " lv2:appliesTo <".$LV2_URI."> ;\n"; #print MANIFEST " a pset:Bank $BANK ;\n"; print MANIFEST " a pset:Preset ;\n"; print MANIFEST " rdfs:label \"".$voice."\" ;\n"; print MANIFEST " rdfs:seeAlso <".$voice.".ttl> .\n"; close(MANIFEST); } sub print_lv2_port { ($port_name,$port_val)=@_; # Specials if($port_name eq "algorithm_num") { $port_val+=1; } if($port_name=~/op\d_osc_detune/) { $port_val-=7; } print $deeaxe_voice " lv2:symbol \"".$port_name."\" ;\n"; $port_val.=".0" if($port_val!~/\./); print $deeaxe_voice " pset:value ".$port_val."\n"; }