6 $semicolon = ";"; # help out stupid emacs
7 $title = "Ardour Shortcuts";
21 $winkey = 'Mod4\>\<Super';
27 GetOptions ("platform=s" => \$platform,
28 "winkey=s" => \$winkey,
29 "cheatsheet" => \$make_cheatsheet,
30 "accelmap" => \$make_accelmap,
31 "merge=s" => \$merge_from,
34 if ($platform eq "darwin") {
36 $gtk_modifier_map{'PRIMARY'} = 'Primary';
37 $gtk_modifier_map{'SECONDARY'} = 'Control';
38 $gtk_modifier_map{'TERTIARY'} = 'Shift';
39 $gtk_modifier_map{'LEVEL4'} = 'Mod1';
40 $gtk_modifier_map{'WINDOW'} = 'Control';
42 $cs_modifier_map{'PRIMARY'} = 'Cmd';
43 $cs_modifier_map{'SECONDARY'} = 'Control';
44 $cs_modifier_map{'TERTIARY'} = 'Shift';
45 $cs_modifier_map{'LEVEL4'} = 'Mod1';
46 $cs_modifier_map{'WINDOW'} = 'Control';
48 $mouse_modifier_map{'PRIMARY'} = 'Cmd';
49 $mouse_modifier_map{'SECONDARY'} = 'Ctrl';
50 $mouse_modifier_map{'TERTIARY'} = 'Shift';
51 $mouse_modifier_map{'LEVEL4'} = 'Opt';
52 $mouse_modifier_map{'WINDOW'} = 'Ctrl';
56 $gtk_modifier_map{'PRIMARY'} = 'Control';
57 $gtk_modifier_map{'SECONDARY'} = 'Alt';
58 $gtk_modifier_map{'TERTIARY'} = 'Shift';
59 $gtk_modifier_map{'LEVEL4'} = $winkey;
60 $gtk_modifier_map{'WINDOW'} = 'Alt';
61 $gtk_modifier_map{$winkey} => 'Win';
63 $cs_modifier_map{'PRIMARY'} = 'Control';
64 $cs_modifier_map{'SECONDARY'} = 'Alt';
65 $cs_modifier_map{'TERTIARY'} = 'Shift';
66 $cs_modifier_map{'LEVEL4'} = 'Win';
67 $cs_modifier_map{'WINDOW'} = 'Alt';
68 $cs_modifier_map{$winkey} => 'Win';
70 $mouse_modifier_map{'PRIMARY'} = 'Ctl';
71 $mouse_modifier_map{'SECONDARY'} = 'Alt';
72 $mouse_modifier_map{'TERTIARY'} = 'Shift';
73 $mouse_modifier_map{'LEVEL4'} = 'Win';
74 $mouse_modifier_map{'WINDOW'} = 'Alt';
75 $mouse_modifier_map{$winkey} => 'Win';
85 'bracketright' => ']',
90 'rightanglebracket' => '>',
91 'leftanglebracket' => '<',
101 'rightarrow' => '→',
102 'leftarrow' => '←',
103 'uparrow' => '↑',
104 'downarrow' => '↓',
105 'Page_Down' => 'PageDown',
106 'Page_Up' => 'PageUp',
108 'KP_Right' => 'KP-→',
109 'KP_Left' => 'KP-←',
110 'KP_Up' => 'KP-↑',
111 'KP_Down' => 'KP-↓',
119 'asciicircum' => '\\verb=^=',
120 'apostrophe' => '\'',
121 'bracketleft' => '[',
122 'bracketright' => ']',
123 'braceleft' => '\\{',
124 'braceright' => '\\}',
125 'backslash' => '$\\backslash$',
127 'rightanglebracket' => '>',
128 'leftanglebracket' => '<',
129 'ampersand' => '\\&',
138 'rightarrow' => '$\rightarrow$',
139 'leftarrow' => '$\\leftarrow$',
140 'uparrow' => '$\\uparrow$',
141 'downarrow' => '$\\downarrow$',
142 'Page_Down' => 'Page Down',
143 'Page_Up' => 'Page Up',
152 open (BINDINGS, $merge_from) || die ("merge from bindings: file not readable");
154 next if (/^$semicolon/);
155 if (/^\(gtk_accel/) {
157 chop; # closing parenthesis
159 ($junk, $action, $binding) = split;
160 $merge_bindings{$action} = $binding;
166 if ($make_accelmap && !$merge_from) {
167 print ";; this accelmap was produced by tools/fmt-bindings\n";
171 next if /^$semicolon/;
183 $group_names{$group_key} = $group_name;
184 $group_text{$group_key} = $group_text;
185 $group_numbering{$group_key} = $group_number;
186 # each binding entry is 2 element array. bindings
187 # are all collected into a container array. create
188 # the first dummy entry so that perl knows what we
190 $group_bindings{$group_key} = [ [] ];
195 ($group_key,$group_name) = split (/\s+/, $_, 2);
205 $group_names{$group_key} = $group_name;
206 $group_text{$group_key} = $group_text;
209 next if (/^[ \t]+$/);
219 ($key,$action,$binding,$text) = split (/\|/, $_, 4);
221 # substitute bindings
223 $gtk_binding = $binding;
226 $lookup = "<Actions>/" . $action;
227 if ($merge_bindings{$lookup}) {
228 $binding = $merge_bindings{$lookup};
231 # forced inclusion of bindings from template
233 # this action is not defined in the merge from set, so forget it
239 # print the accelmap output
242 # remove + and don't print it in the accelmap
245 # include this in the accelmap
246 if (!$merge_from && $make_accelmap) {
247 foreach $k (keys %gtk_modifier_map) {
248 $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
250 print "(gtk_accel_path \"<Actions>/$action\" \"$gtk_binding\")\n";
255 # do not include this binding in the cheat sheet
259 $bref = $group_bindings{$key};
260 push (@$bref, [$binding, $text]);
268 if ($make_accelmap || !$make_cheatsheet) {
274 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
276 foreach $gk (@groups_sorted_by_number) {
279 # mouse stuff - ignore
283 # $bref is a reference to the array of arrays for this group
284 $bref = $group_bindings{$gk};
286 if (scalar @$bref > 1) {
288 $name = $group_names{$gk};
289 $name =~ s/\\linebreak.*//;
291 $name =~ s/\$\\_\$/-/g;
292 $name =~ s/\\[a-z]+ //g;
296 print "<h3>$name</h3>\n";
298 $gtext = $group_text{$gk};
299 $gtext =~ s/\\linebreak.*//;
301 $gtext =~ s/\$\\_\$/-/g;
302 $gtext =~ s/\\[a-z]+ //g;
304 $gtext =~ s/\\par//g;
306 if (!($gtext eq "")) {
310 # ignore the first entry, which was empty
316 print "<dl class=\"bindings\">\n";
318 # sort the array of arrays by the descriptive text for nicer appearance,
321 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
322 # $bbref is a reference to an array
324 $binding = @$bbref[0];
327 if ($binding =~ /:/) { # mouse binding with "where" clause
328 ($binding,$where) = split (/:/, $binding, 2);
331 foreach $k (keys %cs_modifier_map) {
332 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
335 # remove braces for HTML
337 $binding =~ s/></\+/g;
341 # substitute keycode names for something printable
343 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
344 $binding =~ s/($re)/$keycodes{$1}/g;
346 # tidy up description
349 $descr =~ s/\\linebreak.*//;
351 $descr =~ s/\$\\_\$/-/g;
352 $descr =~ s/\\[a-z]+ //g;
354 $descr =~ s/\\par//g;
356 print "<dt>$descr</dt><dd>$binding</dd>\n";
363 print " <!-- remove this if more text is added below -->\n";
368 # Now print the cheatsheet
370 $boilerplate_header = <<END_HEADER;
371 \\documentclass[10pt,landscape]{article}
372 \\usepackage{multicol}
375 \\usepackage{palatino}
376 \\usepackage{geometry}
378 \\setlength{\\parskip}{0pt}
379 \\setlength{\\parsep}{0pt}
380 \\setlength{\\headsep}{0pt}
381 \\setlength{\\topskip}{0pt}
382 \\setlength{\\topmargin}{0pt}
383 \\setlength{\\topsep}{0pt}
384 \\setlength{\\partopsep}{0pt}
386 % This sets page margins to .5 inch if using letter paper, and to 1cm
387 % if using A4 paper. (This probably isnott strictly necessary.)
388 % If using another size paper, use default 1cm margins.
389 \\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
390 { \\geometry{top=.5in,left=1in,right=0in,bottom=.5in} }
391 {\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
392 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
393 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
396 % Turn off header and footer
399 % Redefine section commands to use less space
401 \\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
402 {-1ex plus -.5ex minus -.2ex}%
404 {\\normalfont\\large\\bfseries}}
405 \\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
406 {-1explus -.5ex minus -.2ex}%
408 {\\normalfont\\normalsize\\bfseries}}
409 \\renewcommand{\\subsubsection}{\\\@startsection{subsubsection}{3}{0mm}%
410 {-1ex plus -.5ex minus -.2ex}%
412 {\\normalfont\\small\\bfseries}}
415 % Do not print section numbers% Do not print section numbers
416 \\setcounter{secnumdepth}{0}
418 \\setlength{\\parindent}{0pt}
419 \\setlength{\\parskip}{0pt plus 0.5ex}
421 %-------------------------------------------
427 \\begin{multicols}{3}
430 $boilerplate_footer = <<END_FOOTER;
431 \\rule{0.3\\linewidth}{0.25pt}
434 Copyright \\copyright\\ 2009 ardour.org
436 % Should change this to be date of file, not current date.
437 %\\verb!$Revision: 1.13 $, $Date: 2008/05/29 06:11:56 $.!
439 http://ardour.org/manual
445 if ($make_cheatsheet) {
446 print $boilerplate_header;
447 print "\\begin{center}\\Large\\bf $title \\end{center}\n";
450 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
452 foreach $gk (@groups_sorted_by_number) {
453 # $bref is a reference to the array of arrays for this group
454 $bref = $group_bindings{$gk};
456 if (scalar @$bref > 1) {
457 print "\\section{$group_names{$gk}}\n";
459 if (!($group_text{$gk} eq "")) {
460 print "$group_text{$gk}\n\\par\n";
463 # ignore the first entry, which was empty
467 # find the longest descriptive text (this is not 100% accuracy due to typography)
472 for $bbref (@$bref) {
473 # $bbref is a reference to an array
477 # if there is a linebreak, just use everything up the linebreak
478 # to determine the width
481 if ($text =~ /\\linebreak/) {
482 $matchtext = s/\\linebreak.*//;
486 if (length ($matchtext) > $maxtextlen) {
487 $maxtextlen = length ($matchtext);
488 $maxtext = $matchtext;
493 # mouse mode: don't extend max text at all - space it tight
501 print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n";
502 print "\\begin{tabular}{\@{}p{\\the\\MyLen}%
503 \@{}p{\\linewidth-\\the\\MyLen}%
506 # sort the array of arrays by the descriptive text for nicer appearance,
509 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
510 # $bbref is a reference to an array
512 $binding = @$bbref[0];
515 if ($binding =~ /:/) { # mouse binding with "where" clause
516 ($binding,$where) = split (/:/, $binding, 2);
520 # mouse mode - use shorter abbrevs
521 foreach $k (keys %mouse_modifier_map) {
522 $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
525 foreach $k (keys %cs_modifier_map) {
526 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
530 $binding =~ s/></\+/g;
534 # substitute keycode names for something printable
536 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
537 $binding =~ s/($re)/$keycodes{$1}/g;
539 # split up mouse bindings to "click" and "where" parts
541 if ($gk eq "mobject") {
542 print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n";
544 print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n";
548 print "\\end{tabular}\n";
553 print $boilerplate_footer;