more or less fully-functional binding & cheat sheet generator, with merge-ability for existing binding files

git-svn-id: svn://localhost/ardour2/branches/3.0@5447 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-07-31 20:26:15 +00:00
parent 908ad8c9a5
commit c601f87c12
1 changed files with 128 additions and 26 deletions

View File

@ -4,6 +4,7 @@
use Getopt::Long;
$semicolon = ";"; # help out stupid emacs
$title = "Ardour Shortcuts";
$in_group_def = 0;
$group_name;
$group_text;
@ -14,12 +15,22 @@ $group_number = 0;
%group_bindings;
%modifier_map;
%group_numbering;
%merge_bindings;
$platform = linux;
$winkey = 'Mod4><Super';
$make_cheatsheet = 1;
$make_accelmap = 0;
$merge_from = "";
GetOptions ("platform=s" => \$platform);
GetOptions ("platform=s" => \$platform,
"winkey=s" => \$winkey,
"cheatsheet" => \$make_cheatsheet,
"accelmap" => \$make_accelmap,
"merge=s" => \$merge_from);
if ($platform eq "osx") {
$gtk_modifier_map{'PRIMARY'} = 'meta';
$gtk_modifier_map{'SECONDARY'} = 'Mod1';
$gtk_modifier_map{'TERTIARY'} = 'Shift';
@ -27,24 +38,39 @@ if ($platform eq "osx") {
$gtk_modifier_map{'WINDOW'} = 'Mod1';
$cs_modifier_map{'PRIMARY'} = 'Command';
$cs_modifier_map{'SECONDARY'} = 'Alt';
$cs_modifier_map{'SECONDARY'} = 'Opt';
$cs_modifier_map{'TERTIARY'} = 'Shift';
$cs_modifier_map{'LEVEL4'} = 'Control';
$cs_modifier_map{'WINDOW'} = 'Alt';
$cs_modifier_map{'WINDOW'} = 'Opt';
$mouse_modifier_map{'PRIMARY'} = 'Cmd';
$mouse_modifier_map{'SECONDARY'} = 'Opt';
$mouse_modifier_map{'TERTIARY'} = 'Shift';
$mouse_modifier_map{'LEVEL4'} = 'Control';
$mouse_modifier_map{'WINDOW'} = 'Opt';
} else {
$gtk_modifier_map{'PRIMARY'} = 'Control';
$gtk_modifier_map{'SECONDARY'} = 'Alt';
$gtk_modifier_map{'TERTIARY'} = 'Shift';
$gtk_modifier_map{'LEVEL4'} = 'Mod4';
$gtk_modifier_map{'LEVEL4'} = $winkey;
$gtk_modifier_map{'WINDOW'} = 'Alt';
$gtk_modifier_map{$winkey} => 'Win';
$cs_modifier_map{'PRIMARY'} = 'Control';
$cs_modifier_map{'SECONDARY'} = 'Alt';
$cs_modifier_map{'TERTIARY'} = 'Shift';
$cs_modifier_map{'LEVEL4'} = 'Win';
$cs_modifier_map{'WINDOW'} = 'Alt';
$cs_modifier_map{$winkey} => 'Win';
$mouse_modifier_map{'PRIMARY'} = 'Ctl';
$mouse_modifier_map{'SECONDARY'} = 'Alt';
$mouse_modifier_map{'TERTIARY'} = 'Shift';
$mouse_modifier_map{'LEVEL4'} = 'Win';
$mouse_modifier_map{'WINDOW'} = 'Alt';
$mouse_modifier_map{$winkey} => 'Win';
}
%keycodes = (
@ -55,6 +81,7 @@ if ($platform eq "osx") {
'braceleft' => '\\{',
'braceright' => '\\}',
'backslash' => '$\\backslash$',
'slash' => '/',
'rightanglebracket' => '>',
'leftanglebracket' => '<',
'ampersand' => '\\&',
@ -73,12 +100,37 @@ if ($platform eq "osx") {
'Page_Down' => 'Page Down',
'Page_Up' => 'Page Up',
'space' => 'space',
'KP_' => 'KP$\_$'
'KP_' => 'KP$\_$',
);
if ($merge_from) {
open (BINDINGS, $merge_from) || die ("merge from bindings: file not readable");
while (<BINDINGS>) {
next if (/^$semicolon/);
if (/^\(gtk_accel/) {
chop; # newline
chop; # closing parenthesis
s/"//g;
($junk, $action, $binding) = split;
$merge_bindings{$action} = $binding;
}
}
close (BINDINGS);
}
if ($make_accelmap && !$merge_from) {
print ";; this accelmap was produced by tools/fmt-bindings\n";
}
while (<>) {
next if /^$semicolon/;
if (/^\$/) {
s/^\$//;
$title = $_;
next;
}
if (/^%/) {
if ($in_group_def) {
@ -125,9 +177,15 @@ while (<>) {
$gtk_binding = $binding;
foreach $k (keys %gtk_modifier_map) {
$gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
}
if ($merge_from) {
$lookup = "<Actions>/" . $action;
if ($merge_bindings{$lookup}) {
$binding = $merge_bindings{$lookup};
} else {
# this action is not defined in the merge from set, so forget it
next;
}
}
# print the accelmap output
@ -136,7 +194,12 @@ while (<>) {
$key =~ s/^\+//;
} else {
# include this in the accelmap
# print "(gtk_accel_map \"<Actions>/$action\" \"$gtk_binding\")\n";
if (!$merge_from && $make_accelmap) {
foreach $k (keys %gtk_modifier_map) {
$gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
}
print "(gtk_accel_map \"<Actions>/$action\" \"$gtk_binding\")\n";
}
}
if ($key =~ /^-/) {
@ -153,6 +216,10 @@ while (<>) {
next;
}
if ($make_accelmap || !$make_cheatsheet) {
exit 0;
}
# Now print the cheatsheet
$boilerplate_header = <<END_HEADER;
@ -161,14 +228,21 @@ $boilerplate_header = <<END_HEADER;
\\usepackage{calc}
\\usepackage{ifthen}
\\usepackage{palatino}
\\usepackage[landscape]{geometry}
\\usepackage{geometry}
\\setlength{\\parskip}{0pt}
\\setlength{\\parsep}{0pt}
\\setlength{\\headsep}{0pt}
\\setlength{\\topskip}{0pt}
\\setlength{\\topmargin}{0pt}
\\setlength{\\topsep}{0pt}
\\setlength{\\partopsep}{0pt}
% This sets page margins to .5 inch if using letter paper, and to 1cm
% if using A4 paper. (This probably isnott strictly necessary.)
% If using another size paper, use default 1cm margins.
\\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
{ \\geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
{ \\geometry{top=.5in,left=1in,right=0in,bottom=.5in} }
{\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
{\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
{\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
@ -181,7 +255,7 @@ $boilerplate_header = <<END_HEADER;
\\makeatletter
\\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%x
{0.5ex plus .2ex}%
{\\normalfont\\large\\bfseries}}
\\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
{-1explus -.5ex minus -.2ex}%
@ -193,11 +267,7 @@ $boilerplate_header = <<END_HEADER;
{\\normalfont\\small\\bfseries}}
\\makeatother
% Define BibTeX command
\\def\\BibTeX{{\\rm B\\kern-.05em{\\sc i\\kern-.025em b}\\kern-.08em
T\\kern-.1667em\\lower.7ex\\hbox{E}\\kern-.125emX}}
% Do not print section numbers
% Do not print section numbers% Do not print section numbers
\\setcounter{secnumdepth}{0}
\\setlength{\\parindent}{0pt}
@ -213,11 +283,24 @@ $boilerplate_header = <<END_HEADER;
END_HEADER
$boilerplate_footer = <<END_FOOTER;
\\rule{0.3\\linewidth}{0.25pt}
\\scriptsize
Copyright \\copyright\\ 2009 ardour.org
% Should change this to be date of file, not current date.
%\\verb!$Revision: 1.13 $, $Date: 2008/05/29 06:11:56 $.!
http://ardour.org/manual
\\end{multicols}
\\end{document}
END_FOOTER
print $boilerplate_header;
if ($make_cheatsheet) {
print $boilerplate_header;
print "\\begin{center}\\Large\\bf $title \\end{center}\n";
}
@groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
@ -226,7 +309,7 @@ foreach $gk (@groups_sorted_by_number) {
$bref = $group_bindings{$gk};
if (scalar @$bref > 1) {
print "\\section*{$group_names{$gk}}\n";
print "\\section{$group_names{$gk}}\n";
if (!($group_text{$gk} eq "")) {
print "$group_text{$gk}\n\\par\n";
@ -244,6 +327,12 @@ foreach $gk (@groups_sorted_by_number) {
for $bbref (@$bref) {
# $bbref is a reference to an array
$text = @$bbref[1];
#
# if there is a linebreak, just use everything up the linebreak
# to determine the width
#
if ($text =~ /\\linebreak/) {
$matchtext = s/\\linebreak.*//;
} else {
@ -255,7 +344,12 @@ foreach $gk (@groups_sorted_by_number) {
}
}
$maxtext .= "....";
if ($gk =~ /^m/) {
# mouse mode: don't extend max text at all - space it tight
$maxtext .= ".";
} else {
$maxtext .= "....";
}
# set up the table
@ -264,9 +358,10 @@ foreach $gk (@groups_sorted_by_number) {
\@{}p{\\linewidth-\\the\\MyLen}%
\@{}}\n";
# now print the bindings
# sort the array of arrays by the descriptive text for nicer appearance,
# and print them
for $bbref (@$bref) {
for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
# $bbref is a reference to an array
$binding = @$bbref[0];
@ -276,14 +371,21 @@ foreach $gk (@groups_sorted_by_number) {
($binding,$where) = split (/:/, $binding, 2);
}
if ($gk =~ /^m/) {
# mouse mode - use shorter abbrevs
foreach $k (keys %mouse_modifier_map) {
$binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
}
} else {
foreach $k (keys %cs_modifier_map) {
$binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
}
}
$binding =~ s/></\+/g;
$binding =~ s/^<//;
$binding =~ s/>/\+/;
foreach $k (keys %cs_modifier_map) {
$binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
}
# substitute keycode names for something printable
$re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;