Last time I wrote a program to match karaoke keys with python. This time, I made a page that can call this program from Laravel while learning.
However, since I just wrote PHP, I can hardly use the function of Laravel ^ ^;
--Called python from PHP on the command line and got the output --The range of your own and the range of the song you want to sing are acquired with the select box and sent with get.
As a memorandum for myself.
--Get $ origkey
(the highest note of your own) and $ adkey
(the highest note of the song you want to sing)
--ʻExeccalls python locally --The output result is stored in
$ outpara --The select box can be set to the initial value by adding
selected to the
php.resources/views/karaoke/index.blade.php
@extends('layout')
@section('content')
<h1>Karaoke sound matching page</h1>
<?php
if (!empty($_GET['origkey'])) {
$origkey = $_GET['origkey'];
}else {
$origkey = 'mid2G_s';
}
if (!empty($_GET['adkey'])) {
$adkey = $_GET['adkey'];
}else {
$adkey = 'hiA';
}
$oniki = ['lowF', 'lowF_s', 'lowG', 'lowG_s',
'mid1A', 'mid1A_s', 'mid1B', 'mid1C', 'mid1C_s', 'mid1D', 'mid1D_s', 'mid1E', 'mid1F', 'mid1F_s', 'mid1G', 'mid1G_s',
'mid2A', 'mid2A_s', 'mid2B', 'mid2C', 'mid2C_s', 'mid2D', 'mid2D_s', 'mid2E', 'mid2F', 'mid2F_s', 'mid2G', 'mid2G_s',
'hiA', 'hiA_s', 'hiB', 'hiC', 'hiC_s', 'hiD', 'hiD_s', 'hiE', 'hiF', 'hiF_s', 'hiG', 'hiG_s',
'hihiA', 'hihiA_s', 'hihiB'];
//Form creation started
print("<table>");
print("<tr><td>");
//origkey form{{{
print("Your highest note");
print("<form method='get' action=''>");
print("<p>");
print("<select name='origkey'>");
foreach ($oniki as $oto) {
if ($oto === $origkey)
print("<option value='$oto' selected>$oto</option>");
else
print("<option value='$oto'>$oto</option>");
}
print("</select>");
print("</p>");
//}}}
print("</td><td> </td><td>");
//adkey form{{{
print("The highest note of the song you want to sing");
print("<p>");
print("<select name='adkey'>");
foreach ($oniki as $oto) {
if ($oto === $adkey)
print("<option value='$oto' selected>$oto</option>");
else
print("<option value='$oto'>$oto</option>");
}
print("</select>");
print("</p>");
//}}}
print("</td><td> </td><td>");
//Submission form{{{
print("<p><input type='submit' value='Adjust'></p>");
print("</form>");
//}}}
//Form creation finished}}}
print("</td><td> </td><td>");
print("</td><td>A reference site for the range: <a href='http://www.music-key.com/'>Range.com</a></td><td>");
print("</td></tr></table>");
print("<hr>");
$fullpath = "python karaokeForLaravel.py $origkey $adkey";
exec($fullpath, $outpara); //At the command line$Execute the contents of fullpath and output the output result$Store in outpata
$type = $outpara[0];
$diff_key = $outpara[1];
print("Your highest note: <font size='5' color='ff0000'>$origkey</font> <br>");
print("The highest note of the song you want to sing: <font size='5' color='ff0000'>$adkey</font> <br>");
print("<font size='6'>");
print("From the original song key<font size='7' color='ff0000'>$diff_key</font>Adjustment");
switch($type){
case 'Original':
print("Then you can sing well.");
break;
case '1OctaveUp':
print("do it<font size='7' color='ff0000'>1 octave up</font>If you sing with, you can sing well.");
break;
case '1OctaveDown':
print("do it<font size='7' color='ff0000'>1 octave down</font>If you sing with, you can sing well.");
break;
}
print("</font>");
?>
@endsection
This is the initial page.
Play around with the select box and press the'Adjust' button. If you look at the URL of the updated page, you can see that the parameters have been sent by GET.
――The select box is awkward, so I want to use bootstrap or something. --The code is too dirty, so refactor it --It's too clumsy to realize side by side with the table tag, so fix it --Allows you to search for range information by song title or artist ――Borrow VPS etc. and make it publicly available
If you have any programming mistakes or advice such as "This is more elegant!", Please let us know in the comments m (__) m
Recommended Posts