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 open $group_handles{$group_file}, ">", "gtk2_ardour/" . $group_file . ".bindings" or die "Cannot open bindings file " . $group_file . ".bindings: $!"
213 $group_files{$group_key} = $group_handles{$group_file}
224 $group_names{$group_key} = $group_name;
225 $group_text{$group_key} = $group_text;
228 next if (/^[ \t]+$/);
238 ($key,$action,$binding,$text) = split (/\|/, $_, 4);
243 # substitute bindings
245 $gtk_binding = $binding;
248 $lookup = "<Actions>/" . $action;
249 if ($merge_bindings{$lookup}) {
250 $binding = $merge_bindings{$lookup};
253 # forced inclusion of bindings from template
255 # this action is not defined in the merge from set, so forget it
261 # print the accelmap output
264 # remove + and don't print it in the accelmap
267 # include this in the accelmap
268 if (!$merge_from && $make_accelmap) {
269 if (!$ardour_bindings) {
270 foreach $k (keys %gtk_modifier_map) {
271 $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/;
273 print "(gtk_accel_path \"<Actions>/$action\" \"$gtk_binding\")\n";
278 $b =~ s/PRIMARY/Primary-/;
279 $b =~ s/SECONDARY/Secondary-/;
280 $b =~ s/TERTIARY/Tertiary-/;
281 $b =~ s/LEVEL4/Level4-/;
283 if (exists ($group_files{$gkey})) {
284 print { $group_files{$gkey} } "<Binding key=\"" . $b . "\" action=\"" . $action . "\"/>\n";
291 # do not include this binding in the cheat sheet
295 $bref = $group_bindings{$key};
296 push (@$bref, [$binding, $text]);
304 foreach my $key (keys %group_handles) {
305 close $group_handles{$key} or die "Group file $group_files{$key} not closed!"
308 if ($make_accelmap || !$make_cheatsheet) {
314 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
316 foreach $gk (@groups_sorted_by_number) {
319 # mouse stuff - ignore
323 # $bref is a reference to the array of arrays for this group
324 $bref = $group_bindings{$gk};
326 if (scalar @$bref > 1) {
328 $name = $group_names{$gk};
329 $name =~ s/\\linebreak.*//;
331 $name =~ s/\$\\_\$/-/g;
332 $name =~ s/\\[a-z]+ //g;
336 print "<h3>$name</h3>\n";
338 $gtext = $group_text{$gk};
339 $gtext =~ s/\\linebreak.*//;
341 $gtext =~ s/\$\\_\$/-/g;
342 $gtext =~ s/\\[a-z]+ //g;
344 $gtext =~ s/\\par//g;
346 if (!($gtext eq "")) {
350 # ignore the first entry, which was empty
356 print "<dl class=\"bindings\">\n";
358 # sort the array of arrays by the descriptive text for nicer appearance,
361 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
362 # $bbref is a reference to an array
364 $binding = @$bbref[0];
367 if ($binding =~ /:/) { # mouse binding with "where" clause
368 ($binding,$where) = split (/:/, $binding, 2);
371 foreach $k (keys %cs_modifier_map) {
372 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
375 # remove braces for HTML
377 $binding =~ s/></\+/g;
381 # substitute keycode names for something printable
383 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
384 $binding =~ s/($re)/$keycodes{$1}/g;
386 # tidy up description
389 $descr =~ s/\\linebreak.*//;
391 $descr =~ s/\$\\_\$/-/g;
392 $descr =~ s/\\[a-z]+ //g;
394 $descr =~ s/\\par//g;
396 print "<dt>$descr</dt><dd>$binding</dd>\n";
403 print " <!-- remove this if more text is added below -->\n";
408 # Now print the cheatsheet
410 $boilerplate_header = <<END_HEADER;
411 \\documentclass[10pt,landscape]{article}
412 %\\documentclass[10pt,landscape,a4paper]{article}
413 %\\documentclass[10pt,landscape,letterpaper]{article}
414 \\usepackage{multicol}
417 \\usepackage{palatino}
418 \\usepackage{geometry}
420 \\setlength{\\parskip}{0pt}
421 \\setlength{\\parsep}{0pt}
422 \\setlength{\\headsep}{0pt}
423 \\setlength{\\topskip}{0pt}
424 \\setlength{\\topmargin}{0pt}
425 \\setlength{\\topsep}{0pt}
426 \\setlength{\\partopsep}{0pt}
428 % This sets page margins to .5 inch if using letter paper, and to 1cm
429 % if using A4 paper. (This probably isnott strictly necessary.)
430 % If using another size paper, use default 1cm margins.
431 \\ifthenelse{\\lengthtest { \\paperwidth = 11in}}
432 { \\geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
433 {\\ifthenelse{ \\lengthtest{ \\paperwidth = 297mm}}
434 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
435 {\\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
438 % Turn off header and footer
441 % Redefine section commands to use less space
443 \\renewcommand{\\section}{\\\@startsection{section}{1}{0mm}%
444 {-1ex plus -.5ex minus -.2ex}%
446 {\\normalfont\\large\\bfseries}}
447 \\renewcommand{\\subsection}{\\\@startsection{subsection}{2}{0mm}%
448 {-1explus -.5ex minus -.2ex}%
450 {\\normalfont\\normalsize\\bfseries}}
451 \\renewcommand{\\subsubsection}{\\\@startsection{subsubsection}{3}{0mm}%
452 {-1ex plus -.5ex minus -.2ex}%
454 {\\normalfont\\small\\bfseries}}
457 % Do not print section numbers% Do not print section numbers
458 \\setcounter{secnumdepth}{0}
460 \\setlength{\\parindent}{0pt}
461 \\setlength{\\parskip}{0pt plus 0.5ex}
463 %-------------------------------------------
469 \\begin{multicols}{3}
472 $boilerplate_footer = <<END_FOOTER;
473 \\rule{0.3\\linewidth}{0.25pt}
476 Copyright \\copyright\\ 2013 ardour.org
478 % Should change this to be date of file, not current date.
480 http://manual.ardour.org
486 if ($make_cheatsheet) {
487 print $boilerplate_header;
488 print "\\begin{center}\\Large\\bf $title \\end{center}\n";
491 @groups_sorted_by_number = sort { $group_numbering{$a} <=> $group_numbering{$b} } keys %group_numbering;
493 foreach $gk (@groups_sorted_by_number) {
494 # $bref is a reference to the array of arrays for this group
495 $bref = $group_bindings{$gk};
497 if (scalar @$bref > 1) {
498 print "\\section{$group_names{$gk}}\n";
500 if (!($group_text{$gk} eq "")) {
501 print "$group_text{$gk}\n\\par\n";
504 # ignore the first entry, which was empty
508 # find the longest descriptive text (this is not 100% accuracy due to typography)
513 for $bbref (@$bref) {
514 # $bbref is a reference to an array
518 # if there is a linebreak, just use everything up the linebreak
519 # to determine the width
522 if ($text =~ /\\linebreak/) {
523 $matchtext = s/\\linebreak.*//;
527 if (length ($matchtext) > $maxtextlen) {
528 $maxtextlen = length ($matchtext);
529 $maxtext = $matchtext;
534 # mouse mode: don't extend max text at all - space it tight
542 print "\\settowidth{\\MyLen}{\\texttt{$maxtext}}\n";
543 print "\\begin{tabular}{\@{}p{\\the\\MyLen}%
544 \@{}p{\\linewidth-\\the\\MyLen}%
547 # sort the array of arrays by the descriptive text for nicer appearance,
550 for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) {
551 # $bbref is a reference to an array
553 $binding = @$bbref[0];
556 if ($binding =~ /:/) { # mouse binding with "where" clause
557 ($binding,$where) = split (/:/, $binding, 2);
561 # mouse mode - use shorter abbrevs
562 foreach $k (keys %mouse_modifier_map) {
563 $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/;
566 foreach $k (keys %cs_modifier_map) {
567 $binding =~ s/\@$k\@/$cs_modifier_map{$k}/;
571 $binding =~ s/></\+/g;
575 # substitute keycode names for something printable
577 $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;
578 $binding =~ s/($re)/$keycodes{$1}/g;
580 # split up mouse bindings to "click" and "where" parts
582 if ($gk eq "mobject") {
583 print "{\\tt @$bbref[1] } & {\\tt $binding} {\\it $where}\\\\\n";
585 print "{\\tt @$bbref[1] } & {\\tt $binding} \\\\\n";
589 print "\\end{tabular}\n";
594 print $boilerplate_footer;