ONO::FW::Apps::Modules::MusicSheet

package ONO::FW::Apps::Modules::MusicSheet;
################################################################################
# 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::PDF::Elements::Grid;
use ONO::Lib::PDF::Elements::Music;
use ONO::Lib::Audio::Pro::Guitar::Amplifier::PDF;

use ONO::FW::Apps::ToolBox;

###############################################################################
#
###############################################################################

sub conf {

#: Music sheet app configurator.

my (
$self,
$vars_ref,
$BLK_ref,
) = @_;

my %vars = %$vars_ref;
my %BLK = %$BLK_ref;

my @color = ('fabric','fabric','fabric','fabric','fabric','fabric','fabric');
my @hide = (' hide',' hide',' hide',' hide',' hide',' hide',' hide');

if (!$vars{'app_input_type'}) {
$vars{'app_input_type'} = 0;
}
$color[$vars{'app_input_type'}] = "green";
$hide[$vars{'app_input_type'}] = "";

my $box_number = 7;

if (ONO::IO->community eq "school") {
$color[6] = "fabric hide";
$box_number = 6;
}

my $SEL = qq~<input type="hidden" id="app_input_type_id" name="app_input_type" value="$vars{'app_input_type'}">
<div id="app_input_type_0" class="box_$color[0] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('0');">
<div class="block48 bo rel bg_paper" style="width:72px">
<div class="abs bg_black" style="bottom:0px;left:0px;width:100%;height:2px"></div>
<div id="app_input_type_0_check" class="abs$hide[0]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_1" class="box_$color[1] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('1');">
<div class="block48 bo rel bg_paper" style="width:72px">
<div class="abs bg_black trans50" style="top:24px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:0px;left:24px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:48px;width:1px;height:48px"></div>
<div id="app_input_type_1_check" class="abs$hide[1]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_2" class="box_$color[2] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('2');">
<div class="block48 bo rel bg_paper" style="width:72px">
<div class="abs bg_black trans50" style="top:12px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:24px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:36px;left:0px;width:100%;height:1px"></div>
<div class="abs" style="top:12px;left:20px;font-size:48px">♫</div>
<div id="app_input_type_2_check" class="abs$hide[2]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_3" class="box_$color[3] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('3');">
<div class="block48 bo rel bg_paper" style="width:72px">
<div class="abs bg_black trans50" style="top:9px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:19px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:29px;left:0px;width:100%;height:1px"></div>
<div class="abs bg_black trans50" style="top:39px;left:0px;width:100%;height:1px"></div>
<div class="abs lh100 bold" style="top:2px;left:5px">T<br>A<br>B</div>
<div id="app_input_type_3_check" class="abs$hide[3]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_4" class="box_$color[4] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('4');">
<div class="block48 bo rel bg_paper" style="width:70px">
<div class="abs bg_black trans50" style="top:0px;left:10px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:20px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:30px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:40px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:50px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:60px;width:1px;height:48px"></div>
<div class="abs bg_black trans80" style="top:0px;left:6px;width:8px;height:28px"></div>
<div class="abs bg_black trans80" style="top:0px;left:16px;width:8px;height:28px"></div>
<div class="abs bg_black trans80" style="top:0px;left:36px;width:8px;height:28px"></div>
<div class="abs bg_black trans80" style="top:0px;left:46px;width:8px;height:28px"></div>
<div class="abs bg_black trans80" style="top:0px;left:56px;width:8px;height:28px"></div>
<div id="app_input_type_4_check" class="abs$hide[4]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_5" class="box_$color[5] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('5');">
<div class="block48 bo rel bg_paper" style="width:29px">
<div class="abs bg_black trans50" style="top:0px;left:5px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:11px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:17px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:23px;width:1px;height:48px"></div>
<div class="abs bg_black trans50" style="top:0px;left:0px;width:29px;height:1px"></div>
<div class="abs bg_black trans50" style="top:16px;left:0px;width:29px;height:1px"></div>
<div class="abs bg_black trans50" style="top:32px;left:0px;width:29px;height:1px"></div>
<div class="abs bg_black trans80 block5 radius5" style="top:6px;left:21px"></div>
<div class="abs bg_black trans80 block5 radius5" style="top:22px;left:9px"></div>
<div class="abs bg_black trans80 block5 radius5" style="top:38px;left:3px"></div>
<div id="app_input_type_5_check" class="abs$hide[5]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<div id="app_input_type_6" class="box_$color[6] fl mr10 mb10 cursorlink noselect" onclick="app_input_type_select('6');">
<div class="block48 bo rel bg_paper" style="width:72px">
<div class="abs trans50 block10 radius10" style="top:8px;left:8px;border:1px solid #000000"></div>
<div class="abs bg_black trans50" style="top:8px;left:13.5px;width:1px;height:5px"></div>
<div class="abs trans50 block10 radius10" style="top:19px;left:24px;border:1px solid #000000"></div>
<div class="abs bg_black trans50" style="top:19px;left:29.5px;width:1px;height:5px"></div>
<div class="abs trans50 block10 radius10" style="top:30px;left:8px;border:1px solid #000000"></div>
<div class="abs bg_black trans50" style="top:30px;left:13.5px;width:1px;height:5px"></div>
<div class="abs bg_black trans50" style="top:8px;left:50px;width:1px;height:32px"></div>
<div class="abs bg_black trans80" style="top:24px;left:47px;width:7px;height:3px"></div>
<div class="abs bg_black trans50" style="top:8px;left:62px;width:1px;height:32px"></div>
<div class="abs bg_black trans80" style="top:16px;left:59px;width:7px;height:3px"></div>
<div id="app_input_type_6_check" class="abs$hide[6]" style="top:24px;right:4px"><img class="block32" src="/ono/osr/images/icons/crystal/32x32/ono/ok.png" alt=""></div>
</div>
</div>
<script>
function app_input_type_select(id) {
for (let i = 0; i < $box_number; i++) {
onojs_class('app_input_type_'+i,'box_fabric fl mr10 mb10 cursorlink noselect');
onojs_hide('app_input_type_'+i+'_check');
}
onojs_setvalue('app_input_type_id',id);
onojs_class('app_input_type_'+id,'box_green fl mr10 mb10 cursorlink noselect');
onojs_block('app_input_type_'+id+'_check');
}
</script>
~;

my $CONF;

$CONF .= ONO::FW::Apps::ToolBox->conf_input("custom", $BLK_ref,\%vars,"","",$SEL);
$CONF .= ONO::FW::Apps::ToolBox->conf_input("selnum", $BLK_ref,\%vars,"",0,4,"NoqzZ",$vars{'app_input_number'},$BLK{'no3'});
$CONF .= ONO::FW::Apps::ToolBox->conf_input("spacer", $BLK_ref,\%vars);

return $CONF;

}

sub exec {

my (
$self,
$canvas,
$vars_ref,
) = @_;

#: Music sheet app execution.

my %vars = %$vars_ref;

my $paras = 1;
if ($vars{'app_input_number'} > 1) {
$paras = $vars{'app_input_number'};
}

my $line_y = 0;
my $line_y_max = 180;

if ($paras == 2) {
$line_y_max = 80;
}
if ($paras == 3) {
$line_y_max = 40;
}
if ($paras == 4) {
$line_y_max = 30;
}

my $para_y;

for (my $p = 0; $p < $paras; $p++) {

if ($vars{'app_input_type'} =~ /^(0|2|3|4|5|6)$/) {

my $whilecounter;
while ($whilecounter < 256 && $line_y < $line_y_max) {
$whilecounter++;

if ($vars{'app_input_type'} =~ /^(0)$/) {

$line_y = $line_y + 12;
ONO::Lib::PDF::Draw->line($canvas,0,$line_y+$para_y,170,$line_y+$para_y);

}

if ($vars{'app_input_type'} =~ /^(2)$/) {

my @offset = (0,0,5,10,0);
$line_y = $line_y + 10;
my $size = 10;
my $offset_y_fix = 7;

ONO::Lib::PDF::Elements::Music->lines_notes($canvas,0,$line_y+$para_y+$offset[$paras],170,$size,"","0:111:111:111","","k",$offset_y_fix);
$line_y = $line_y + 10;

}

if ($vars{'app_input_type'} =~ /^(3)$/) {

my @offset = (0,0,0,0,0);
my @size = (0,15,14,20,12);
$line_y = $line_y + 10;
ONO::Lib::PDF::Elements::Music->lines_tabs($canvas,0,$line_y+$para_y+$offset[$paras],170,$size[$paras],"","0:111:111:111","","T");
$line_y = $line_y + $size[$paras] - 2.5;

}

if ($vars{'app_input_type'} =~ /^(4)$/) {
my @size = (0,20,20,18,10);
$line_y = $line_y + 10;
ONO::Lib::PDF::Elements::Music->keyboard($canvas,0,$line_y+$para_y,170,$size[$paras],48);
$line_y = $line_y + $size[$paras];
}

if ($vars{'app_input_type'} =~ /^(5)$/) {
my @size = (0,38,38,50,38);
for (my $c = 0; $c < 5; $c++) {
ONO::Lib::PDF::Elements::Music->guitar_chord($canvas,$c*34,$line_y+$para_y+5,40,$size[$paras],0,0,0,"","",0,"","",0,"","");
}
$line_y = $line_y + $size[$paras] + 7.5;
}

if ($vars{'app_input_type'} =~ /^(6)$/) {
ONO::Lib::Audio::Pro::Guitar::Amplifier::PDF->mesa_mark_vii($canvas,5,$line_y+$para_y);
$line_y = $line_y + 40;
}

}

}

if ($vars{'app_input_type'} =~ /^(1)$/) {
my @offset = (0,5,10,15,10);
ONO::Lib::PDF::Elements::Grid->grid($canvas,0,$line_y+$para_y+10,170,$line_y+$para_y+$line_y_max+$offset[$paras],5);
}

$para_y = $para_y + $line_y_max;

my @offset = (0,0,15,23.33,17.5);

if ($paras > 1) {
$para_y = $para_y + $offset[$paras];
}
$line_y = 0;

}


}

###############################################################################
# end of script
###############################################################################

1;

__END__