8 $semicolon = ";"; # help out stupid emacs
9 $title = "Ardour Shortcuts";
31 GetOptions ("platform=s" => \$platform,
32 "winkey=s" => \$winkey,
33 "cheatsheet" => \$make_cheatsheet,
34 "accelmap" => \$make_accelmap,
35 "merge=s" => \$merge_from,
38 if ($platform eq "darwin") {
40 $gtk_modifier_map{'PRIMARY'} = 'Primary'; # GTK supports Primary to allow platform-independent binding to the "primary" modifier, which on OS X is Command
41 $gtk_modifier_map{'SECONDARY'} = 'Control';
42 $gtk_modifier_map{'TERTIARY'} = 'Shift';
43 $gtk_modifier_map{'LEVEL4'} = 'Mod1';
45 # cs_modifier_map == "Cheat Sheet Modifier Map"
46 # Used to control what gets shown in the
47 # cheat sheet for a given (meta)-modifier
49 $cs_modifier_map{'PRIMARY'} = 'Cmd';
50 $cs_modifier_map{'SECONDARY'} = 'Control';
51 $cs_modifier_map{'TERTIARY'} = 'Shift';
52 $cs_modifier_map{'LEVEL4'} = 'Opt';
54 # used to display what gets shown in the
55 # cheat sheet for mouse bindings. Differs
56 # from cs_modifier map in using shorter
59 $mouse_modifier_map{'PRIMARY'} = 'Cmd';
60 $mouse_modifier_map{'SECONDARY'} = 'Ctrl';
61 $mouse_modifier_map{'TERTIARY'} = 'Shift';
62 $mouse_modifier_map{'LEVEL4'} = 'Opt';
66 $gtk_modifier_map{'PRIMARY'} = 'Control';
67 $gtk_modifier_map{'SECONDARY'} = 'Alt';
68 $gtk_modifier_map{'TERTIARY'} = 'Shift';
69 $gtk_modifier_map{'LEVEL4'} = $winkey; # something like "Mod4><Super"
71 # cs_modifier_map == "Cheat Sheet Modifier Map"
72 # Used to control what gets shown in the
73 # cheat sheet for a given (meta)-modifier
75 $cs_modifier_map{'PRIMARY'} = 'Control';
76 $cs_modifier_map{'SECONDARY'} = 'Alt';
77 $cs_modifier_map{'TERTIARY'} = 'Shift';
78 $cs_modifier_map{'LEVEL4'} = 'Win';
80 # used to display what gets shown in the
81 # cheat sheet for mouse bindings. Differs
82 # from cs_modifier map in using shorter
85 $mouse_modifier_map{'PRIMARY'} = 'Ctl';
86 $mouse_modifier_map{'SECONDARY'} = 'Alt';
87 $mouse_modifier_map{'TERTIARY'} = 'Shift';
88 $mouse_modifier_map{'LEVEL4'} = 'Win';
98 'bracketright' => ']',
103 'rightanglebracket' => '>',
104 'leftanglebracket' => '<',
114 'rightarrow' => '→',
115 'leftarrow' => '←',
116 'uparrow' => '↑',
117 'downarrow' => '↓',
118 'Page_Down' => 'PageDown',
119 'Page_Up' => 'PageUp',
121 'KP_Right' => 'KP-→',
122 'KP_Left' => 'KP-←',
123 'KP_Up' => 'KP-↑',
124 'KP_Down' => 'KP-↓',
132 'asciicircum' => '\\verb=^=',
133 'apostrophe' => '\'',
134 'bracketleft' => '[',
135 'bracketright' => ']',
136 'braceleft' => '\\{',
137 'braceright' => '\\}',
138 'backslash' => '$\\backslash$',
140 'rightanglebracket' => '>',
141 'leftanglebracket' => '<',
142 'ampersand' => '\\&',
151 'rightarrow' => '$\rightarrow$',
152 'leftarrow' => '$\\leftarrow$',
153 'uparrow' => '$\\uparrow$',
154 'downarrow' => '$\\downarrow$',
155 'Page_Down' => 'Page Down',
156 'Page_Up' => 'Page Up',
165 open (BINDINGS, $merge_from) || die ("merge from bindings: file not readable");
167 next if (/^$semicolon/);
168 if (/^\(gtk_accel/) {
170 chop; # closing parenthesis
172 ($junk, $action, $binding) = split;
173 $merge_bindings{$action} = $binding;
179 if ($make_accelmap && !$merge_from) {
180 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
183 $bindings_name = basename ($ARGV[0]);
184 $bindings_name =~ s/.bindings\.in$//;
186 open SOURCE, "<", $ARGV[0] or die $!;
189 next if /^$semicolon/;
201 $group_names{$group_key} = $group_name;
202 $group_text{$group_key} = $group_text;
203 $group_numbering{$group_key} = $group_number;
204 # each binding entry is 2 element array. bindings
205 # are all collected into a container array. create
206 # the first dummy entry so that perl knows what we
208 $group_bindings{$group_key} = [ [] ];
213 ($group_key,$owner,$group_name) = split (/\s+/, $_, 3);
214 if ($make_accelmap) {
215 if (!exists ($owner_bindings{$owner})) {
216 $owner_bindings{$owner} = [ [] ];
218 $group_owners{$group_key} = $owner;
229 $group_names{$group_key} = $group_name;
230 $group_text{$group_key} = $group_text;
233 next if (/^[ \t]+$/);
243 ($key,$action,$binding,$text) = split (/\|/, $_, 4);
247 $owner = $group_owners{$gkey};
249 # substitute bindings
251 $gtk_binding = $binding;
254 $lookup = "<Actions>/" . $action;
255 if ($merge_bindings{$lookup}) {
256 $binding = $merge_bindings{$lookup};
259 # forced inclusion of bindings from template
261 # this action is not defined in the merge from set, so forget it
267 # print the accelmap output
270 # remove + and don't print it in the accelmap
273 # include this in the accelmap if it is part of a group that has an "owner"
274 if (!$merge_from && $make_accelmap && exists ($owner_bindings{$owner})) {
279 $b =~ s/PRIMARY/Primary-/;
280 $b =~ s/SECONDARY/Secondary-/;
281 $b =~ s/TERTIARY/Tertiary-/;
282 $b =~ s/LEVEL4/Level4-/;
284 $bref = $owner_bindings{$owner};
285 push (@$bref, [ $action, $b ]);
290 # do not include this binding in the cheat sheet
294 $bref = $group_bindings{$key};
295 push (@$bref, [$binding, $text]);
303 if ($make_accelmap) {
304 print "<BindingSet name=\"" . $bindings_name . "\">\n";
306 foreach $owner (keys %owner_bindings) {
307 print " <Bindings name=\"$owner\">\n <Press>\n";
308 $bindings = $owner_bindings{$owner};
309 shift (@$bindings); # remove initial empty element
310 for my $binding (@$bindings) {
311 print ' <Binding key="' . @$binding[1] . '" action="' . @$binding[0] . "\"/>\n";
313 print " </Press>\n </Bindings>\n";
316 # merge in the "fixed" bindings that are not defined by the argument given to this program
317 # namely, the step editor and the mixer windows
319 foreach $hardcoded_bindings ("mixer.bindings", "step_editing.bindings", "monitor.bindings", "processor_box.bindings") {
320 $path = File::Spec->catfile (dirname ($ARGV[0]), $hardcoded_bindings);
321 open HARDCODED, "<", $path or die $!;
322 while (<HARDCODED>) {
328 print "</BindingSet>\n";
331 if ($make_accelmap || !$make_cheatsheet) {
337 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
339 foreach $gk (@groups_sorted_by_number) {
342 # mouse stuff - ignore
346 # $bref is a reference to the array of arrays for this group
347 $bref = $group_bindings{$gk};
349 if (scalar @$bref > 1) {
351 $name = $group_names{$gk};
352 $name =~ s/\\linebreak.*//;
354 $name =~ s/\$\\_\$/-/g;
355 $name =~ s/\\[a-z]+ //g;
359 print "<h3>$name</h3>\n";
361 $gtext = $group_text{$gk};
362 $gtext =~ s/\\linebreak.*//;
364 $gtext =~ s/\$\\_\$/-/g;
365 $gtext =~ s/\\[a-z]+ //g;
367 $gtext =~ s/\\par//g;
369 if (!($gtext eq "")) {
373 # ignore the first entry, which was empty
379 print "<dl class=\"bindings\">\n";
381 # sort the array of arrays by the descriptive text for nicer appearance,
384 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
385 # $bbref is a reference to an array
387 $binding = @$bbref[0];
390 if ($binding =~ /:/) { # mouse binding with "where" clause
391 ($binding,$where) = split (/:/, $binding, 2);
394 foreach $k (keys %cs_modifier_map) {
395 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
398 # remove braces for HTML
400 $binding =~ s/></\+/g;
404 # substitute keycode names for something printable
406 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
407 $binding =~ s/($re)/$keycodes{$1}/g;
409 # tidy up description
412 $descr =~ s/\\linebreak.*//;
414 $descr =~ s/\$\\_\$/-/g;
415 $descr =~ s/\\[a-z]+ //g;
417 $descr =~ s/\\par//g;
419 print "<dt>$descr</dt><dd>$binding</dd>\n";
426 print " <!-- remove this if more text is added below -->\n";
431 # Now print the cheatsheet
433 $boilerplate_header = <<END_HEADER;
434 \\documentclass[10pt,landscape]{article}
435 %\\documentclass[10pt,landscape,a4paper]{article}
436 %\\documentclass[10pt,landscape,letterpaper]{article}
437 \\usepackage{multicol}
440 \\usepackage{palatino}
441 \\usepackage{geometry}
443 \\setlength{\\parskip}{0pt}
444 \\setlength{\\parsep}{0pt}
445 \\setlength{\\headsep}{0pt}
446 \\setlength{\\topskip}{0pt}
447 \\setlength{\\topmargin}{0pt}
448 \\setlength{\\topsep}{0pt}
449 \\setlength{\\partopsep}{0pt}
451 % This sets page margins to .5 inch if using letter paper, and to 1cm
452 % if using A4 paper. (This probably isnott strictly necessary.)
453 % If using another size paper, use default 1cm margins.
454 \\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
455 { \\geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
456 {\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
457 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
458 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
461 % Turn off header and footer
464 % Redefine section commands to use less space
466 \\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
467 {-1ex plus -.5ex minus -.2ex}%
469 {\\normalfont\\large\\bfseries}}
470 \\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
471 {-1explus -.5ex minus -.2ex}%
473 {\\normalfont\\normalsize\\bfseries}}
474 \\renewcommand{\\subsubsection}{\\\@startsection{subsubsection}{3}{0mm}%
475 {-1ex plus -.5ex minus -.2ex}%
477 {\\normalfont\\small\\bfseries}}
480 % Do not print section numbers% Do not print section numbers
481 \\setcounter{secnumdepth}{0}
483 \\setlength{\\parindent}{0pt}
484 \\setlength{\\parskip}{0pt plus 0.5ex}
486 %-------------------------------------------
492 \\begin{multicols}{3}
495 $boilerplate_footer = <<END_FOOTER;
496 \\rule{0.3\\linewidth}{0.25pt}
499 Copyright \\copyright\\ 2013 ardour.org
501 % Should change this to be date of file, not current date.
503 http://manual.ardour.org
509 if ($make_cheatsheet) {
510 print $boilerplate_header;
511 print "\\begin{center}\\Large\\bf $title \\end{center}\n";
514 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
516 foreach $gk (@groups_sorted_by_number) {
517 # $bref is a reference to the array of arrays for this group
518 $bref = $group_bindings{$gk};
520 if (scalar @$bref > 1) {
521 print "\\section{$group_names{$gk}}\n";
523 if (!($group_text{$gk} eq "")) {
524 print "$group_text{$gk}\n\\par\n";
527 # ignore the first entry, which was empty
531 # find the longest descriptive text (this is not 100% accuracy due to typography)
536 for $bbref (@$bref) {
537 # $bbref is a reference to an array
541 # if there is a linebreak, just use everything up the linebreak
542 # to determine the width
545 if ($text =~ /\\linebreak/) {
546 $matchtext = s/\\linebreak.*//;
550 if (length ($matchtext) > $maxtextlen) {
551 $maxtextlen = length ($matchtext);
552 $maxtext = $matchtext;
557 # mouse mode: don't extend max text at all - space it tight
565 print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n";
566 print "\\begin{tabular}{\@{}p{\\the\\MyLen}%
567 \@{}p{\\linewidth-\\the\\MyLen}%
570 # sort the array of arrays by the descriptive text for nicer appearance,
573 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
574 # $bbref is a reference to an array
576 $binding = @$bbref[0];
579 if ($binding =~ /:/) { # mouse binding with "where" clause
580 ($binding,$where) = split (/:/, $binding, 2);
584 # mouse mode - use shorter abbrevs
585 foreach $k (keys %mouse_modifier_map) {
586 $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
589 foreach $k (keys %cs_modifier_map) {
590 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
594 $binding =~ s/></\+/g;
598 # substitute keycode names for something printable
600 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
601 $binding =~ s/($re)/$keycodes{$1}/g;
603 # split up mouse bindings to "click" and "where" parts
605 if ($gk eq "mobject") {
606 print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n";
608 print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n";
612 print "\\end{tabular}\n";
617 print $boilerplate_footer;