package ONO::Lib::PDF::Elements::Music;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
use ONO::Lib::PDF::Draw;
use ONO::Lib::Image::Canvas::Draw;
use ONO::Lib::Image::Music::Guitar;
#: This module generates specific PDF content.
sub lines_notes {
my (
$self,
$canvas,
$x1,
$y1,
$x2,
$height,
$weight,
$color,
$cols,
$switches,
$offset_y_fix,
) = @_;
#: This generates a notes line.
#:
#: Switches:
#:
#: -k display key (treble)
#: -K display key (bass)
#: -s display separator (4 columns)
#: -S display double separator (left - note that this is NON-STANDARD)
#: -t display time signature (4/4)
#: -T display time signature (3/4)
my $DEBUG;
eval "use PDF::Reuse";
if (!$@) {
if (!$height) {
$height = 10;
}
if (!$weight) {
$weight = 0.2;
}
if (!$color) {
$color = "0:150:150:150";
}
if (!$cols) {
$cols = 1;
}
ONO::Lib::PDF::Draw->rect($canvas,$x1,$y1, $x2,$y1+$height, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/4, $x2,$y1+$height/4, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/4*2, $x2,$y1+$height/4*2, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/4*3, $x2,$y1+$height/4*3, $weight, $color);
if ($switches =~ /(s|S)/) {
my $length = $x2-$x1;
for (my $i = 1; $i < 4; $i++) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$length/4*$i,$y1,$x1+$length/4*$i, $y1+$height, $weight, $color);
}
if ($switches =~ /S/) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$height/10,$y1,$x1+$height/10, $y1+$height, $weight, $color);
}
}
my $x1_time_offset;
if ($switches =~ /(k|K)/) {
$x1_time_offset = $height/1.1;
my $key_size = $height*0.009;
my $key_x = $x1-$height/2.5;
my $key_y = $y1-$height;
if ($switches =~ /k/) {
if (ONO::IO->devstation) {
ONO::Lib::PDF::Draw->place_pdf_abs($canvas,$key_x,$key_y,$height*3,$height*3,"ono/osr/images/music/clefs/clef_test.pdf",$offset_y_fix);
} else {
ONO::Lib::PDF::Draw->place_pdf_abs($canvas,$key_x,$key_y,$height*3,$height*3,"ono/osr/images/music/clefs/clef_treble.pdf",$offset_y_fix);
}
} else {
ONO::Lib::PDF::Draw->place_pdf_abs($canvas,$key_x,$key_y,$height*3,$height*3,"ono/osr/images/music/clefs/clef_bass.pdf",$offset_y_fix);
}
}
if ($switches =~ /(t|T)/) {
my $time = 4;
if ($switches =~ /T/) {
$time = 3;
}
ONO::Lib::PDF::Draw->font("HB",$height*1.8);
ONO::Lib::PDF::Draw->text($canvas,$x1+3+$x1_time_offset,$y1+$height/2,$time,"c");
ONO::Lib::PDF::Draw->text($canvas,$x1+3+$x1_time_offset,$y1+$height,4,"c");
ONO::Lib::PDF::Draw->font("H",12);
}
}
return $DEBUG;
}
sub lines_tabs {
my (
$self,
$canvas,
$x1,
$y1,
$x2,
$height,
$weight,
$color,
$cols,
$switches,
) = @_;
#: This generates a guitar tabs line.
#:
#: Switches:
#:
#: -N display notes
#: -s display separator (4 columns)
#: -S display double separator (left)
#: -T display "TAB"
eval "use PDF::Reuse";
if (!$@) {
if (!$height) {
$height = 10;
}
if (!$weight) {
$weight = 0.2;
}
if (!$color) {
$color = "0:150:150:150";
}
if (!$cols) {
$cols = 1;
}
if ($switches =~ /N/) {
$x1 = $x1+$height/4;
}
ONO::Lib::PDF::Draw->rect($canvas,$x1,$y1, $x2,$y1+$height, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/5, $x2,$y1+$height/5, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/5*2, $x2,$y1+$height/5*2, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/5*3, $x2,$y1+$height/5*3, $weight, $color);
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1+$height/5*4, $x2,$y1+$height/5*4, $weight, $color);
if ($switches =~ /(s|S)/) {
my $length = $x2-$x1;
for (my $i = 1; $i < 4; $i++) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$length/4*$i,$y1,$x1+$length/4*$i, $y1+$height, $weight, $color);
}
if ($switches =~ /S/) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$height/10,$y1,$x1+$height/10, $y1+$height, $weight, $color);
}
}
if ($switches =~ /N/) {
ONO::Lib::PDF::Draw->font("H",$height*0.4);
my $count;
foreach my $opt ('e','B','G','D','A','E') {
$count++;
ONO::Lib::PDF::Draw->text($canvas,$x1-$height/6,$y1+$height/5*($count-1)+$height/30,$opt,"c");
}
ONO::Lib::PDF::Draw->font("H",12);
}
if ($switches =~ /T/) {
ONO::Lib::PDF::Draw->font("HB",$height*0.66);
my $count;
foreach my $opt ('T','A','B') {
$count++;
ONO::Lib::PDF::Draw->text($canvas,$x1+3,$y1+$height/3.6*$count+$height/32,$opt,"c");
}
ONO::Lib::PDF::Draw->font("H",12);
}
}
}
sub guitar_chord {
my (
$self,
$canvas,
$x1,
$y1,
$width,
$height,
$strings,
$frets,
$top_fret,
$tuning,
$fingering,
$rotate,
$weight,
$color,
$color_dots,
$start_fret,
$switches,
$display,
) = @_;
#: This generates a guitar chord grid.
my $auto_frets;
if (!$frets && !$top_fret && $fingering) {
$auto_frets = 1;
}
if (!$width) {
$width = 80;
}
if (!$height) {
$height = 160;
}
if (!$strings) {
$strings = 6;
}
if (!$frets) {
$frets = 3;
}
if (!$top_fret) {
$top_fret = 1;
}
if (!$tuning) {
$tuning = "EADGBE";
}
if (!$rotate) {
$rotate = 0;
}
my $w = $rotate ? $height : $width;
my $h = $rotate ? $width : $height;
if (ONO::IO->devstation) {
# ONO::Lib::PDF::Draw->rect($canvas,$x1,$y1,$x1+$width,$y1+$height,1,"0:0:0:0");
}
$x1 = $x1 + 0.5;
$y1 = $y1 - 3;
my (
$fingering_main,
$barre_fret,
$barre_start,
$barre_end,
$top_fret,
$frets,
) = ONO::Lib::Image::Music::Guitar->chord_prepare($fingering,$auto_frets,$top_fret,$frets);
my $orig_w = $width;
my $orig_h = $height;
my $num_strings = $strings;
my $num_frets = $frets;
my $top_fret_num = $top_fret;
my $fingering_str = $fingering_main;
my @fingering = map { my $s = $_; $s =~ s/^\s+|\s+$//g; $s + 0 } split /,/, $fingering_str;
my $barre_fret_num = $barre_fret;
my $barre_start_str = $barre_start;
my $barre_end_str = $barre_end;
# Layout - always in original orientation
my $space_top = $orig_h/4.5;
my $space_bottom = -2;
my $diagram_h = $orig_h - $space_top - $space_bottom;
my $show_nut = ($top_fret_num == 1);
my $num_h_lines = $num_frets + 1;
my $fret_spacing = $diagram_h / $num_frets;
my $left_margin = 10;
my $string_spacing = ($orig_w - 20) / ($num_strings - 1);
my $right_margin = $orig_w - $left_margin;
my $font_size = $orig_w/8;
if ($orig_h < $orig_w) {
$font_size = $orig_h/8;
}
ONO::Lib::PDF::Draw->font("H",$font_size);
# Positions - in original orientation
my @strings_x;
for my $i (0 .. $num_strings - 1) {
$strings_x[$i] = $left_margin + $i * $string_spacing;
}
my @frets_y;
for my $i (0 .. $num_h_lines - 1) {
$frets_y[$i] = $space_top + $i * $fret_spacing;
}
# Draw vertical strings
for my $i (0 .. $num_strings - 1) {
my $orig_x = $strings_x[$i];
my $p1 = &guitar_chord_rotate("",$rotate,$orig_x, $space_top, $orig_w);
my $p2 = &guitar_chord_rotate("",$rotate,$orig_x, $space_top + $diagram_h, $orig_w);
if ($rotate) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$p1->{x}-$string_spacing/2,$y1+$p1->{y},$x1+$p2->{x}-$string_spacing/2,$y1+$p2->{y});
} else {
ONO::Lib::PDF::Draw->line($canvas,$x1+$p1->{x},$y1+$p1->{y},$x1+$p2->{x},$y1+$p2->{y});
}
}
# Draw horizontal frets
for my $i (0 .. $num_h_lines - 1) {
my $orig_y = $frets_y[$i];
my $p1 = &guitar_chord_rotate("",$rotate,$left_margin, $orig_y, $orig_w);
my $p2 = &guitar_chord_rotate("",$rotate,$right_margin, $orig_y, $orig_w);
if ($rotate) {
ONO::Lib::PDF::Draw->line($canvas,$x1+$p1->{x}-$string_spacing/2,$y1+$p1->{y},$x1+$p2->{x}-$string_spacing/2,$y1+$p2->{y});
} else {
ONO::Lib::PDF::Draw->line($canvas,$x1+$p1->{x},$y1+$p1->{y},$x1+$p2->{x},$y1+$p2->{y});
}
if ($i == 0 && $show_nut) {
if ($rotate) {
ONO::Lib::PDF::Draw->rect($canvas,$x1+$p1->{x}-$string_spacing/2,$y1+$p1->{y},$x1+$p2->{x}-$string_spacing/3,$y1+$p2->{y},0,"","0:0:0:0");
} else {
ONO::Lib::PDF::Draw->rect($canvas,$x1+$p1->{x},$y1+$p1->{y},$x1+$p2->{x},$y1+$p2->{y}+$string_spacing/6,0,"","0:0:0:0");
}
}
}
# Fret numbers on left, centered in each space
my $label_x = $left_margin - 5;
my @special_frets = (1,3,5,7,9,12,15,17,19,21);
my $current_fret = $top_fret_num;
for my $j (0 .. $num_frets - 1) {
my $label_y = $space_top + ($j + 0.5) * $fret_spacing;
if (grep { $_ == $current_fret } @special_frets) {
if ($rotate) {
my $p = &guitar_chord_rotate("",$rotate,$label_x, $label_y-$string_spacing/2, $orig_w);
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x},$y1+$p->{y},$current_fret,"c");
} else {
my $p = &guitar_chord_rotate("",$rotate,$label_x, $label_y, $orig_w);
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x}+$string_spacing/3,$y1+$p->{y},$current_fret,"c");
}
}
$current_fret++;
}
# Tuning labels at top
my $tuning_y = 6.5;
for my $i (0 .. $num_strings - 1) {
my $orig_x = $strings_x[$i];
if ($rotate) {
my $p = &guitar_chord_rotate("",$rotate,$orig_x-1, $tuning_y-$string_spacing, $orig_w);
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x},$y1+$p->{y},substr($tuning,$i,1),"c");
} else {
my $p = &guitar_chord_rotate("",$rotate,$orig_x-1, $tuning_y, $orig_w);
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x}+$string_spacing/4,$y1+$p->{y},substr($tuning,$i,1),"c");
}
}
if ($fingering_str) {
# Top indicators (o for open, x for muted)
my $top_y = $space_top - 1;
for my $i (0 .. $num_strings - 1) {
my $pos = $fingering[$i];
my $orig_x = $strings_x[$i];
my $p = &guitar_chord_rotate("",$rotate,$orig_x-1, $top_y, $orig_w);
my $text;
if ($pos == -1) {
$text = 'x';
} elsif ($pos == 0) {
$text = 'o';
}
if ($text) {
if ($rotate) {
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x}-$string_spacing/1.25,$y1+$p->{y},$text,"c");
} else {
ONO::Lib::PDF::Draw->text($canvas,$x1+$p->{x}+$string_spacing/4,$y1+$p->{y},$text,"c");
}
}
}
}
if ($fingering_str) {
# Draw finger dots for fretted notes
for my $str (0 .. $num_strings - 1) {
my $pos = $fingering[$str];
if ($pos > 0) {
my $dot_y = $space_top + ($pos - $top_fret_num + 0.5) * $fret_spacing;
my $orig_x = $strings_x[$str];
my $p = &guitar_chord_rotate("",$rotate,$orig_x, $dot_y, $orig_w);
if ($rotate) {
ONO::Lib::PDF::Draw->circle($canvas,$x1+$p->{x}-$string_spacing/2,$y1+$p->{y},1,0,"0:0:0:0","0:0:0:0");
} else {
ONO::Lib::PDF::Draw->circle($canvas,$x1+$p->{x},$y1+$p->{y},1,0,"0:0:0:0","0:0:0:0");
}
}
}
}
# Draw barre
if ($barre_fret_num > 0) {
my $relative_fret = $barre_fret_num - $top_fret_num;
if ($relative_fret >= 0 && $relative_fret < $num_frets) {
my $barre_y = $space_top + $relative_fret + $fret_spacing*0.5;
my $x1b = $strings_x[$barre_start_str - 1];
my $x2b = $strings_x[$barre_end_str - 1];
if (!$rotate) {
ONO::Lib::PDF::Draw->rect($canvas,$x1+$x1b,$y1+$barre_y-1,$x1+$x2b,$y1+$barre_y+1,0,"0:0:0:0","0:0:0:0");
} else {
ONO::Lib::PDF::Draw->rect($canvas,$x1+$barre_y-1-$string_spacing/2,$y1-$x1b+$string_spacing*10,$x1+$barre_y+1-$string_spacing/2,$y1-$x2b+$string_spacing*10,0,"0:0:0:0","0:0:0:0");
}
}
}
ONO::Lib::PDF::Draw->font("H",12);
}
sub guitar_chord_rotate {
#: This generates a rotated guitar chord grid.
my ($self,$rotate,$orig_x, $orig_y,$orig_w) = @_;
if (!$rotate) {
return { x => $orig_x, y => $orig_y };
} else {
return { x => $orig_y, y => $orig_w - $orig_x };
}
}
sub guitar_fretboard {
#: This generates a guitar fretboard.
#:
#: Not implemented yet
}
sub keyboard {
my (
$self,
$canvas,
$x1,
$y1,
$width,
$height,
$keys,
$first_key,
$fingering,
$display_notes,
) = @_;
#: This generates a music keyboard.
if (!$width) {
$width = 80;
}
if (!$height) {
$height = 160;
}
if (!$keys) {
$keys = 36;
}
if (!$first_key) {
$first_key = 'C';
}
if (!$fingering) {
$fingering = '';
}
if (!$display_notes) {
$display_notes = 0;
}
my %note_to_num = (
'C' => 0, 'C#' => 1, 'D' => 2, 'D#' => 3, 'E' => 4,
'F' => 5, 'F#' => 6, 'G' => 7, 'G#' => 8, 'A' => 9,
'A#' => 10, 'B' => 11,
);
my $start_note = $note_to_num{$first_key} // 0;
my %highlight_set;
if ($fingering) {
my @highlights = split /,/, $fingering;
@highlights = map { my $n = int($_); $n - 1 } @highlights;
@highlights = grep { $_ >= 0 && $_ < $keys } @highlights;
@highlight_set{@highlights} = (1) x @highlights;
}
sub isBlack {
my ($note) = @_;
return $note == 1 || $note == 3 || $note == 6 || $note == 8 || $note == 10;
}
my @note_names = ('C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B');
sub getNoteName {
my ($idx) = @_;
return $note_names[$idx % 12];
}
my $num_whites = 0;
for my $i (0 .. $keys - 1) {
my $note = ($start_note + $i) % 12;
$num_whites++ unless isBlack($note);
}
my $white_width = $width / $num_whites;
# Compute white keys
my @white_keys;
my $current_white_pos = 0;
for my $i (0 .. $keys - 1) {
my $note = ($start_note + $i) % 12;
unless (isBlack($note)) {
my $x = $current_white_pos * $white_width;
my $is_high = $highlight_set{$i} ? 1 : 0;
my $note_name = getNoteName($note);
push @white_keys, {
x => $x,
width => $white_width,
height => $height,
is_high => $is_high,
note_name => $note_name
};
$current_white_pos++;
}
}
# Compute black keys
my $black_width = $white_width * 0.6;
my $black_height = $height * 0.75;
my @black_keys;
for my $i (0 .. $keys - 1) {
my $note = ($start_note + $i) % 12;
if (isBlack($note)) {
my $prev_whites_count = 0;
for my $k (0 .. $i - 1) {
my $prev_note = ($start_note + $k) % 12;
$prev_whites_count++ unless isBlack($prev_note);
}
my $center = $prev_whites_count == 0 ? 0.5 * $white_width : ($prev_whites_count - 1 + 0.5) * $white_width;
my $black_x = $center - $black_width / 2;
my $is_high = $highlight_set{$i} ? 1 : 0;
push @black_keys, {
x => $black_x,
width => $black_width,
height => $black_height,
is_high => $is_high
};
}
}
ONO::Lib::PDF::Draw->font("HB",$white_width*2);
foreach my $key_data (@white_keys) {
my $color = "0:244:244:244";
if ($key_data->{is_high}) {
$color = "0:244:244:0";
}
ONO::Lib::PDF::Draw->rect($canvas,$x1+$key_data->{x},$y1,$x1+$key_data->{x}+$key_data->{width},$y1+$height,0.5,"0:0:0:0",$color);
if ($display_notes) {
ONO::Lib::PDF::Draw->text($canvas,$x1+$key_data->{x}+($key_data->{width})/2,$y1+$height-1,$key_data->{note_name},"c");
}
}
foreach my $key_data (@black_keys) {
my $color = "0:22:22:22";
if ($key_data->{is_high}) {
$color = "0:244:244:0";
}
ONO::Lib::PDF::Draw->rect($canvas,$x1+$key_data->{x}+$white_width/2,$y1,$x1+$key_data->{x}+$key_data->{width}+$white_width/2,$y1+$height/2,0.5,"0:0:0:0",$color);
}
ONO::Lib::PDF::Draw->font("H",12);
return "";
}
sub hardware_test {
#: This is a test for the music hardware display features.
my (
$self,
$canvas,
$x1,
$y1,
) = @_;
ONO::Lib::PDF::Draw->text($canvas,$x1,$y1,"TEST");
ONO::Lib::PDF::Draw->line($canvas,$x1,$y1,$x1+170,$y1);
&hardware_knob("",$canvas,$x1+25,$y1);
&hardware_fader("",$canvas,$x1+50,$y1);
&hardware_button("",$canvas,$x1+75,$y1);
&hardware_switch("",$canvas,$x1+100,$y1,"",10,"",1);
&hardware_led("",$canvas,$x1+125,$y1);
}
sub hardware_section {
my (
$self,
$canvas,
$x1,
$y1,
$width,
$height,
) = @_;
#: This generates a music hardware box.
ONO::Lib::PDF::Draw->rect($canvas,$x1,$y1,$x1+$width,$y1+$height,0.5,"","",$height/10);
}
sub hardware_knob {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$size,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware knob.
if (!$size) {
$size = 10;
}
my $pos = -135+$status*2.7;
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2,0.5);
if ($status >= 0) {
ONO::Lib::PDF::Draw->linerot($canvas,$x1,$y1+$size/2,$size/2,$pos,0.5);
}
}
sub hardware_fader {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$width,
$height,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware fader.
#:
#: Switches:
#:
#: -h fader cap height = half of width
#:
#: status goes from 0 (bottom) to 100 (top), negative = no status
if (!$width) {
$width = 2;
}
if (!$height) {
$height = 25;
}
my $width_adj = $width;
if ($width_adj < 2) {
$width_adj = 2;
}
my $cap_adj = $width;
if ($switches =~ /h/) {
$cap_adj = $width/2;
}
if ($switches =~ /H/) {
$cap_adj = $width/3;
}
my $pos = $height/100*$status;
ONO::Lib::PDF::Draw->rect($canvas,$x1-$width_adj/2,$y1,$x1+$width_adj/2,$y1+$height,0.5,"","",1);
if ($status >= 0) {
ONO::Lib::PDF::Draw->rect($canvas,$x1-$width*2,$y1+$height-$pos-$cap_adj,$x1+$width*2,$y1+$height-$pos+$cap_adj,0.5,"0:0:0:0","0:244:244:244",$width/2);
}
}
sub hardware_geq {
my (
$self,
$canvas,
$x1,
$y1,
$bands,
$width,
$height,
$label,
$status_ref,
$switches,
) = @_;
#: This generates a music hardware graphics equalizer.
#:
#: Switches:
#:
#: -e empty (no fader knobs)
#: -h fader cap height = half of width
#: -v v-shape light (5-band only, can be combined with -V)
#: -V v-shape harder (5-band only, can be combined with -v)
if (!$width) {
$width = 50;
}
if (!$height) {
$height = 30;
}
if (!$bands) {
$bands = 5;
}
my @status;
if ($status_ref) {
@status = @$status_ref;
}
if ($switches =~ /v/) {
@status = (65,55,40,55,65);
}
if ($switches =~ /V/) {
@status = (80,50,20,50,80);
if ($switches =~ /v/) {
@status = (100,50,0,50,100);
}
}
&hardware_section("",$canvas,$x1,$y1,$width,$height);
for (my $b = 0; $b < $bands; $b++) {
if ($switches =~ /e/) {
$status[$b] = -1;
}
&hardware_fader("",$canvas,$x1+($b+1)*$width/($bands+1),$y1+$height*0.15,"",$width/30,$height*0.7,"",$status[$b],$switches);
}
}
sub hardware_button {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$size,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware button.
if (!$size) {
$size = 10;
}
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2,0.5);
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2.75,0.5);
}
sub hardware_switch {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$size,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware switch:
#:
#: status:
#:
#: -1 = none at all
#: 0 = down, 1 = mid, 2 = up
if (!$size) {
$size = 10;
}
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2,0.5);
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2.75,0.5);
if ($status == 2) {
my $pos = $size/1.7/2;
ONO::Lib::PDF::Draw->rect($canvas,$x1-$size*0.15,$y1-$size/2.75+$pos,$x1+$size*0.15,$y1+$size/2.75+$pos,0.5,"0:0:0:0","0:244:244:244",$size*0.15);
}
if ($status == 1) {
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size*0.15,0.5,"0:244:244:244");
}
if ($status == 0) {
my $pos = $size*1.45/2;
ONO::Lib::PDF::Draw->rect($canvas,$x1-$size*0.15,$y1-$size/2.75+$pos,$x1+$size*0.15,$y1+$size/2.75+$pos,0.5,"0:0:0:0","0:244:244:244",$size*0.15);
}
}
sub hardware_led {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$size,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware LED.
if (!$size) {
$size = 5;
}
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2,0.5);
}
sub hardware_input {
my (
$self,
$canvas,
$x1,
$y1,
$type,
$size,
$label,
$status,
$switches,
) = @_;
#: This generates a music hardware input connector.
if (!$size) {
$size = 10;
}
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2,0.5);
ONO::Lib::PDF::Draw->circle($canvas,$x1,$y1+$size/2,$size/2.75,0.5);
}
###############################################################################
# end of script
###############################################################################
1;
__END__