6 $semicolon = ";"; # help out stupid emacs
7 $title = "Ardour Shortcuts";
30 GetOptions ("platform=s" => \$platform,
31 "winkey=s" => \$winkey,
32 "cheatsheet" => \$make_cheatsheet,
33 "accelmap" => \$make_accelmap,
34 "ardourbindings" => \$ardour_bindings,
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 && !$ardour_bindings) {
180 print ";; this accelmap was produced by tools/fmt-bindings\n";
184 next if /^$semicolon/;
196 $group_names{$group_key} = $group_name;
197 $group_text{$group_key} = $group_text;
198 $group_numbering{$group_key} = $group_number;
199 # each binding entry is 2 element array. bindings
200 # are all collected into a container array. create
201 # the first dummy entry so that perl knows what we
203 $group_bindings{$group_key} = [ [] ];
208 ($group_key,$group_file,$group_name) = split (/\s+/, $_, 3);
209 if ($make_accelmap && $ardour_bindings) {
210 if (!exists ($group_handles{$group_file})) {
212 open $group_handles{$group_file}, ">", "gtk2_ardour/" . $group_file . ".bindings" or die "Cannot open bindings file " . $group_file . ".bindings: $!";
213 print { $group_handles{$group_file} } "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <Bindings name=\"ardour-", $group_file , "\">\n <Press>\n";
215 $group_files{$group_key} = $group_handles{$group_file}
226 $group_names{$group_key} = $group_name;
227 $group_text{$group_key} = $group_text;
230 next if (/^[ \t]+$/);
240 ($key,$action,$binding,$text) = split (/\|/, $_, 4);
245 # substitute bindings
247 $gtk_binding = $binding;
250 $lookup = "<Actions>/" . $action;
251 if ($merge_bindings{$lookup}) {
252 $binding = $merge_bindings{$lookup};
255 # forced inclusion of bindings from template
257 # this action is not defined in the merge from set, so forget it
263 # print the accelmap output
266 # remove + and don't print it in the accelmap
269 # include this in the accelmap
270 if (!$merge_from && $make_accelmap) {
271 if (!$ardour_bindings) {
272 foreach $k (keys %gtk_modifier_map) {
273 $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
275 print "(gtk_accel_path \"<Actions>/$action\" \"$gtk_binding\")\n";
280 $b =~ s/PRIMARY/Primary-/;
281 $b =~ s/SECONDARY/Secondary-/;
282 $b =~ s/TERTIARY/Tertiary-/;
283 $b =~ s/LEVEL4/Level4-/;
285 if (exists ($group_files{$gkey})) {
286 print { $group_files{$gkey} } " <Binding key=\"" . $b . "\" action=\"" . $action . "\"/>\n";
293 # do not include this binding in the cheat sheet
297 $bref = $group_bindings{$key};
298 push (@$bref, [$binding, $text]);
306 foreach my $key (keys %group_handles) {
307 print { $group_handles{$key} } " </Press>\n <Release>\n </Release>\n</Bindings>\n";
308 close $group_handles{$key} or die "Group file $group_files{$key} not closed!"
311 if ($make_accelmap || !$make_cheatsheet) {
317 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
319 foreach $gk (@groups_sorted_by_number) {
322 # mouse stuff - ignore
326 # $bref is a reference to the array of arrays for this group
327 $bref = $group_bindings{$gk};
329 if (scalar @$bref > 1) {
331 $name = $group_names{$gk};
332 $name =~ s/\\linebreak.*//;
334 $name =~ s/\$\\_\$/-/g;
335 $name =~ s/\\[a-z]+ //g;
339 print "<h3>$name</h3>\n";
341 $gtext = $group_text{$gk};
342 $gtext =~ s/\\linebreak.*//;
344 $gtext =~ s/\$\\_\$/-/g;
345 $gtext =~ s/\\[a-z]+ //g;
347 $gtext =~ s/\\par//g;
349 if (!($gtext eq "")) {
353 # ignore the first entry, which was empty
359 print "<dl class=\"bindings\">\n";
361 # sort the array of arrays by the descriptive text for nicer appearance,
364 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
365 # $bbref is a reference to an array
367 $binding = @$bbref[0];
370 if ($binding =~ /:/) { # mouse binding with "where" clause
371 ($binding,$where) = split (/:/, $binding, 2);
374 foreach $k (keys %cs_modifier_map) {
375 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
378 # remove braces for HTML
380 $binding =~ s/></\+/g;
384 # substitute keycode names for something printable
386 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
387 $binding =~ s/($re)/$keycodes{$1}/g;
389 # tidy up description
392 $descr =~ s/\\linebreak.*//;
394 $descr =~ s/\$\\_\$/-/g;
395 $descr =~ s/\\[a-z]+ //g;
397 $descr =~ s/\\par//g;
399 print "<dt>$descr</dt><dd>$binding</dd>\n";
406 print " <!-- remove this if more text is added below -->\n";
411 # Now print the cheatsheet
413 $boilerplate_header = <<END_HEADER;
414 \\documentclass[10pt,landscape]{article}
415 %\\documentclass[10pt,landscape,a4paper]{article}
416 %\\documentclass[10pt,landscape,letterpaper]{article}
417 \\usepackage{multicol}
420 \\usepackage{palatino}
421 \\usepackage{geometry}
423 \\setlength{\\parskip}{0pt}
424 \\setlength{\\parsep}{0pt}
425 \\setlength{\\headsep}{0pt}
426 \\setlength{\\topskip}{0pt}
427 \\setlength{\\topmargin}{0pt}
428 \\setlength{\\topsep}{0pt}
429 \\setlength{\\partopsep}{0pt}
431 % This sets page margins to .5 inch if using letter paper, and to 1cm
432 % if using A4 paper. (This probably isnott strictly necessary.)
433 % If using another size paper, use default 1cm margins.
434 \\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
435 { \\geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
436 {\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
437 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
438 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
441 % Turn off header and footer
444 % Redefine section commands to use less space
446 \\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
447 {-1ex plus -.5ex minus -.2ex}%
449 {\\normalfont\\large\\bfseries}}
450 \\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
451 {-1explus -.5ex minus -.2ex}%
453 {\\normalfont\\normalsize\\bfseries}}
454 \\renewcommand{\\subsubsection}{\\\@startsection{subsubsection}{3}{0mm}%
455 {-1ex plus -.5ex minus -.2ex}%
457 {\\normalfont\\small\\bfseries}}
460 % Do not print section numbers% Do not print section numbers
461 \\setcounter{secnumdepth}{0}
463 \\setlength{\\parindent}{0pt}
464 \\setlength{\\parskip}{0pt plus 0.5ex}
466 %-------------------------------------------
472 \\begin{multicols}{3}
475 $boilerplate_footer = <<END_FOOTER;
476 \\rule{0.3\\linewidth}{0.25pt}
479 Copyright \\copyright\\ 2013 ardour.org
481 % Should change this to be date of file, not current date.
483 http://manual.ardour.org
489 if ($make_cheatsheet) {
490 print $boilerplate_header;
491 print "\\begin{center}\\Large\\bf $title \\end{center}\n";
494 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
496 foreach $gk (@groups_sorted_by_number) {
497 # $bref is a reference to the array of arrays for this group
498 $bref = $group_bindings{$gk};
500 if (scalar @$bref > 1) {
501 print "\\section{$group_names{$gk}}\n";
503 if (!($group_text{$gk} eq "")) {
504 print "$group_text{$gk}\n\\par\n";
507 # ignore the first entry, which was empty
511 # find the longest descriptive text (this is not 100% accuracy due to typography)
516 for $bbref (@$bref) {
517 # $bbref is a reference to an array
521 # if there is a linebreak, just use everything up the linebreak
522 # to determine the width
525 if ($text =~ /\\linebreak/) {
526 $matchtext = s/\\linebreak.*//;
530 if (length ($matchtext) > $maxtextlen) {
531 $maxtextlen = length ($matchtext);
532 $maxtext = $matchtext;
537 # mouse mode: don't extend max text at all - space it tight
545 print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n";
546 print "\\begin{tabular}{\@{}p{\\the\\MyLen}%
547 \@{}p{\\linewidth-\\the\\MyLen}%
550 # sort the array of arrays by the descriptive text for nicer appearance,
553 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
554 # $bbref is a reference to an array
556 $binding = @$bbref[0];
559 if ($binding =~ /:/) { # mouse binding with "where" clause
560 ($binding,$where) = split (/:/, $binding, 2);
564 # mouse mode - use shorter abbrevs
565 foreach $k (keys %mouse_modifier_map) {
566 $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
569 foreach $k (keys %cs_modifier_map) {
570 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
574 $binding =~ s/></\+/g;
578 # substitute keycode names for something printable
580 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
581 $binding =~ s/($re)/$keycodes{$1}/g;
583 # split up mouse bindings to "click" and "where" parts
585 if ($gk eq "mobject") {
586 print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n";
588 print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n";
592 print "\\end{tabular}\n";
597 print $boilerplate_footer;