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})) {
211 print "Try to open ", $group_file . ".bindings\n";
212 open $group_handles{$group_file}, ">", $group_file . ".bindings" or die "Cannot open bindings file " . $group_file . ".bindings: $!"
214 $group_files{$group_key} = $group_handles{$group_file}
225 $group_names{$group_key} = $group_name;
226 $group_text{$group_key} = $group_text;
229 next if (/^[ \t]+$/);
239 ($key,$action,$binding,$text) = split (/\|/, $_, 4);
244 # substitute bindings
246 $gtk_binding = $binding;
249 $lookup = "<Actions>/" . $action;
250 if ($merge_bindings{$lookup}) {
251 $binding = $merge_bindings{$lookup};
254 # forced inclusion of bindings from template
256 # this action is not defined in the merge from set, so forget it
262 # print the accelmap output
265 # remove + and don't print it in the accelmap
268 # include this in the accelmap
269 if (!$merge_from && $make_accelmap) {
270 if (!$ardour_bindings) {
271 foreach $k (keys %gtk_modifier_map) {
272 $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
274 print "(gtk_accel_path \"<Actions>/$action\" \"$gtk_binding\")\n";
279 $b =~ s/PRIMARY/Primary-/;
280 $b =~ s/SECONDARY/Secondary-/;
281 $b =~ s/TERTIARY/Tertiary-/;
282 $b =~ s/LEVEL4/Level4-/;
284 if (exists ($group_files{$gkey})) {
285 print { $group_files{$gkey} } "<Binding key=\"" . $b . "\" action=\"" . $action . "\"/>\n";
292 # do not include this binding in the cheat sheet
296 $bref = $group_bindings{$key};
297 push (@$bref, [$binding, $text]);
305 foreach my $key (keys %group_handles) {
306 close $group_handles{$key} or die "Group file $group_files{$key} not closed!"
309 if ($make_accelmap || !$make_cheatsheet) {
315 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
317 foreach $gk (@groups_sorted_by_number) {
320 # mouse stuff - ignore
324 # $bref is a reference to the array of arrays for this group
325 $bref = $group_bindings{$gk};
327 if (scalar @$bref > 1) {
329 $name = $group_names{$gk};
330 $name =~ s/\\linebreak.*//;
332 $name =~ s/\$\\_\$/-/g;
333 $name =~ s/\\[a-z]+ //g;
337 print "<h3>$name</h3>\n";
339 $gtext = $group_text{$gk};
340 $gtext =~ s/\\linebreak.*//;
342 $gtext =~ s/\$\\_\$/-/g;
343 $gtext =~ s/\\[a-z]+ //g;
345 $gtext =~ s/\\par//g;
347 if (!($gtext eq "")) {
351 # ignore the first entry, which was empty
357 print "<dl class=\"bindings\">\n";
359 # sort the array of arrays by the descriptive text for nicer appearance,
362 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
363 # $bbref is a reference to an array
365 $binding = @$bbref[0];
368 if ($binding =~ /:/) { # mouse binding with "where" clause
369 ($binding,$where) = split (/:/, $binding, 2);
372 foreach $k (keys %cs_modifier_map) {
373 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
376 # remove braces for HTML
378 $binding =~ s/></\+/g;
382 # substitute keycode names for something printable
384 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
385 $binding =~ s/($re)/$keycodes{$1}/g;
387 # tidy up description
390 $descr =~ s/\\linebreak.*//;
392 $descr =~ s/\$\\_\$/-/g;
393 $descr =~ s/\\[a-z]+ //g;
395 $descr =~ s/\\par//g;
397 print "<dt>$descr</dt><dd>$binding</dd>\n";
404 print " <!-- remove this if more text is added below -->\n";
409 # Now print the cheatsheet
411 $boilerplate_header = <<END_HEADER;
412 \\documentclass[10pt,landscape]{article}
413 %\\documentclass[10pt,landscape,a4paper]{article}
414 %\\documentclass[10pt,landscape,letterpaper]{article}
415 \\usepackage{multicol}
418 \\usepackage{palatino}
419 \\usepackage{geometry}
421 \\setlength{\\parskip}{0pt}
422 \\setlength{\\parsep}{0pt}
423 \\setlength{\\headsep}{0pt}
424 \\setlength{\\topskip}{0pt}
425 \\setlength{\\topmargin}{0pt}
426 \\setlength{\\topsep}{0pt}
427 \\setlength{\\partopsep}{0pt}
429 % This sets page margins to .5 inch if using letter paper, and to 1cm
430 % if using A4 paper. (This probably isnott strictly necessary.)
431 % If using another size paper, use default 1cm margins.
432 \\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
433 { \\geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
434 {\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
435 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
436 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
439 % Turn off header and footer
442 % Redefine section commands to use less space
444 \\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
445 {-1ex plus -.5ex minus -.2ex}%
447 {\\normalfont\\large\\bfseries}}
448 \\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
449 {-1explus -.5ex minus -.2ex}%
451 {\\normalfont\\normalsize\\bfseries}}
452 \\renewcommand{\\subsubsection}{\\\@startsection{subsubsection}{3}{0mm}%
453 {-1ex plus -.5ex minus -.2ex}%
455 {\\normalfont\\small\\bfseries}}
458 % Do not print section numbers% Do not print section numbers
459 \\setcounter{secnumdepth}{0}
461 \\setlength{\\parindent}{0pt}
462 \\setlength{\\parskip}{0pt plus 0.5ex}
464 %-------------------------------------------
470 \\begin{multicols}{3}
473 $boilerplate_footer = <<END_FOOTER;
474 \\rule{0.3\\linewidth}{0.25pt}
477 Copyright \\copyright\\ 2013 ardour.org
479 % Should change this to be date of file, not current date.
481 http://manual.ardour.org
487 if ($make_cheatsheet) {
488 print $boilerplate_header;
489 print "\\begin{center}\\Large\\bf $title \\end{center}\n";
492 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
494 foreach $gk (@groups_sorted_by_number) {
495 # $bref is a reference to the array of arrays for this group
496 $bref = $group_bindings{$gk};
498 if (scalar @$bref > 1) {
499 print "\\section{$group_names{$gk}}\n";
501 if (!($group_text{$gk} eq "")) {
502 print "$group_text{$gk}\n\\par\n";
505 # ignore the first entry, which was empty
509 # find the longest descriptive text (this is not 100% accuracy due to typography)
514 for $bbref (@$bref) {
515 # $bbref is a reference to an array
519 # if there is a linebreak, just use everything up the linebreak
520 # to determine the width
523 if ($text =~ /\\linebreak/) {
524 $matchtext = s/\\linebreak.*//;
528 if (length ($matchtext) > $maxtextlen) {
529 $maxtextlen = length ($matchtext);
530 $maxtext = $matchtext;
535 # mouse mode: don't extend max text at all - space it tight
543 print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n";
544 print "\\begin{tabular}{\@{}p{\\the\\MyLen}%
545 \@{}p{\\linewidth-\\the\\MyLen}%
548 # sort the array of arrays by the descriptive text for nicer appearance,
551 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
552 # $bbref is a reference to an array
554 $binding = @$bbref[0];
557 if ($binding =~ /:/) { # mouse binding with "where" clause
558 ($binding,$where) = split (/:/, $binding, 2);
562 # mouse mode - use shorter abbrevs
563 foreach $k (keys %mouse_modifier_map) {
564 $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
567 foreach $k (keys %cs_modifier_map) {
568 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
572 $binding =~ s/></\+/g;
576 # substitute keycode names for something printable
578 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
579 $binding =~ s/($re)/$keycodes{$1}/g;
581 # split up mouse bindings to "click" and "where" parts
583 if ($gk eq "mobject") {
584 print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n";
586 print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n";
590 print "\\end{tabular}\n";
595 print $boilerplate_footer;