[PYTHON] Matching karaoke keys ~ I tried to put it on Laravel ~ <on the way>

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 ^ ^;

What i did

--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.

Source code

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 addingselected 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

result

This is the initial page. スクリーンショット 2016-03-05 3.13.43.png

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. スクリーンショット 2016-03-05 3.14.03.png

Improvement points

――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

Matching karaoke keys ~ I tried to put it on Laravel ~ <on the way>
I tried to use Resultoon on Mac + AVT-C875, but I was frustrated on the way.
I tried to rescue the data of the laptop by booting it on Ubuntu
I tried to put pytest into the actual battle
I tried to notify the honeypot report on LINE
I tried to make it easy to change the setting of authenticated Proxy on Jupyter
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to launch ipython cluster to the minimum on AWS
I tried to move the ball
I tried to estimate the interval.
I tried to register a station on the IoT platform "Rimotte"
I tried to get started with Bitcoin Systre on the weekend
I tried to summarize the umask command
I tried to recognize the wake word
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried to verify the best way to find a good marriage partner
When I tried to run Python, it was skipped to the Microsoft Store
I tried to summarize the logical way of thinking about object orientation.
I tried to install Docker on Windows 10 Home but it didn't work
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to push the Sphinx document to BitBucket and it will be automatically reflected on the web server
I tried web scraping to analyze the lyrics.
I tried to optimize while drying the laundry
I tried to save the data with discord
When I tried to change the root password with ansible, I couldn't access it.
I tried to touch the API of ebay
I tried to correct the keystone of the image
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
I made an image classification model and tried to move it on mobile
I tried to verify the Big Bang theorem [Is it about to come back?]
Introduction to Python with Atom (on the way)
[I'm an IT beginner] I tried my best to implement Linux on Windows
Qiita Job I tried to analyze the job offer
Matching karaoke keys
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
LeetCode I tried to summarize the simple ones
I tried playing with the calculator on tkinter
I tried to implement the traveling salesman problem
I tried to use Twitter Scraper on AWS Lambda and it didn't work.
I tried to display the infection condition of coronavirus on the heat map of seaborn
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to scrape YouTube, but I can use the API, so don't do it.
I tried to make the phone ring when it was posted at the IoT post
I tried to put out the frequent word ranking of LINE talk with Python
I tried to understand how to use Pandas and multicollinearity based on the Affairs dataset.
It was a life I wanted to OCR on AWS Lambda to locate the characters.
[Rails] v1.0 came out on google-cloud-vision of gem, so I tried to support it
What I did when I was angry to put it in with the enable-shared option
I tried to put HULFT IoT (Agent) in the gateway Rooster of Sun Electronics
Try to Normalize Cut the image with scikit-image (although it gets angry on the way)
[Introduction] I tried to implement it by myself while explaining to understand the binary tree
[Uncorrelated test] I tried to put out the boundary line with or without rejection
I tried to learn the sin function with chainer
I tried to graph the packages installed in Python
How to put Takoyaki Oishikunaru on the segment tree
I tried Python on Mac for the first time.
I tried to detect the iris from the camera image