Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
raspberry committed Jan 29, 2024
2 parents 92492c9 + ebc2047 commit 175c72f
Show file tree
Hide file tree
Showing 387 changed files with 9,229 additions and 623 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
.DS_Store
*.mp4
59 changes: 45 additions & 14 deletions borne/Classes/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,69 @@ public function insertSong($user_id, $title, $mood, $tempo, $style, $addons=''){
return $this->query($sql);
}

public function getSongTitles($tonality, $directory = 'lyrics/'): array
public function insertUsedTitle($title_id){
$sql = "INSERT INTO songs_titles_used(song_title_id, used) VALUES($title_id, 1)";
return $this->query($sql);
}

public function getSongTitles($tonality): array
{
$files = scandir($directory.$tonality);
$filenames = array();

foreach($files as $key => $value){
if(mb_strlen($value)<3){
unset($files[$key]);
}else{
$filenames []= substr($value,0, -4);
$sql = "SELECT * FROM song_titles WHERE mood='$tonality'";
return $this->query($sql);
}

public function getUsedSongTitles(){
$sql = "SELECT DISTINCT song_title_id FROM songs_titles_used WHERE used=1";
return $this->querySimpleArray($sql,'song_title_id');
}

public function getUnusedSongTitles($tonality){
$used_ids = $this->getUsedSongTitles();
$sql = "SELECT * FROM song_titles WHERE mood='$tonality'";
if(sizeof($used_ids)>0){
$used_str = implode(',',$used_ids);
$sql .= " AND id NOT IN ($used_str)";
}
$res = $this->query($sql);
if(sizeof($res)>4){
return $res;
}else{
if($this->resetUsedSongTitles($tonality)){
return $this->getSongTitles($tonality);
}
}
}

return $filenames;
public function resetUsedSongTitles($tonality){
$used_ids = array_column($this->getSongTitles($tonality),'id');
$used_str = implode(',',$used_ids);
$sql = "UPDATE songs_titles_used SET used=0 WHERE song_title_id IN ($used_str)";
return $this->query($sql);
}

public function getRandomTitles($tonality, $qty, $directory = 'lyrics/'): array
public function getRandomTitles($tonality, $qty): array
{
$titles = $this->getSongTitles($tonality, $directory);
$titles = $this->getUnusedSongTitles($tonality);
$random_keys = array_rand($titles,$qty);
foreach($random_keys as $key){
$random[] = $titles[$key];
$random[] = $titles[$key]['id'];
}
shuffle($random);
return $random;
}

public function getSongInfo($id) : array
{
$sql = "SELECT * FROM song_titles WHERE id=$id";
$song_info = $this->query($sql);
return $song_info[0];
}

public function getAvailAddons(){
$addons = array('clap','hh','kick');
return $addons;
}

}


Expand Down
52 changes: 26 additions & 26 deletions borne/Classes/Tube.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@

require_once 'Machine.php';
require_once 'midiequiv.php';

class Tube extends Machine
{
public function insertChoices($song_mood, $song_tempo, $song_style, $song_addons){
$sql = "INSERT INTO song_choices(song_mood, song_tempo, song_style, song_addons) VALUES('$song_mood', $song_tempo, '$song_style', '$song_addons')";
$choice_id = $this->query($sql);
return $choice_id;
}

public function getTonality($mood){
$sql = "SELECT tonality FROM midi_prompts WHERE mood='$mood'";
$results = $this->query($sql);
$tonality = $results[array_rand($results,1)];
return $tonality['tonality'];
$sql = "SELECT tonality FROM song_moods WHERE mood='$mood'";
$res = $this->query($sql);
return $res[0]['tonality'];
}

public function getMoodName($tonality){
$mood_names = array(
'D'=>'Joyeux',
'Ab'=>'Neutre',
'C'=>'Triste'
'D'=>'Joyeuse',
'Ab'=>'Stable',
'C'=>'Mélancolique'
);

return $mood_names[$tonality];
Expand All @@ -35,7 +27,7 @@ public function getChordsDrums($style){
return $styles[$key];
}

public function getChannel($tonality){
public function getChordChannel($tonality){
$midi_channel_arr = [
'D' => 4,
'Ab' => 3,
Expand All @@ -44,6 +36,11 @@ public function getChannel($tonality){
return $midi_channel_arr[$tonality];
}

public function getSinging($song_title_id){
$sql = "SELECT * FROM song_titles WHERE id=$song_title_id";
return $this->queryAssocArray($sql);
}

public function getChords($tonality){
$sql = "SELECT chord FROM midi_avail_chords_per_tonality WHERE tonality='$tonality'";
$chords = $this->query($sql);
Expand All @@ -52,14 +49,13 @@ public function getChords($tonality){
}

public function getChordPitch($step, $do_alter, $octave){
//$octave++;
$note = $step;

if($do_alter == 1){
if($note == "B") $note .= "b";
else $note .= "#";
}

$note .= $octave;
if(array_key_exists($note, MIDIEQUIV)){
return MIDIEQUIV[$note];
Expand Down Expand Up @@ -144,12 +140,6 @@ function getStopAddon($addon){
$res = $this->query($sql);
return $res[0];
}

public function getPrompt($tonality){
$sql = "SELECT * FROM midi_prompts WHERE tonality='$tonality'";
$results = $this->query($sql);
return $results[array_rand($results,1)]['notes'];
}

public function getFormat($lines){
$text = array();
Expand Down Expand Up @@ -204,7 +194,7 @@ public function getStopTopline(){
return $results[0];
}

public function getToplineChannel($tonality){
public function getToplineChannel($tonality){
$top_channel = [
'D' => 10,
'Ab' => 11,
Expand All @@ -217,16 +207,26 @@ public function getToplinePitch(){
return rand(1,108);
}

public function getStopTopline(){
public function getStopTopline(){
$sql = "SELECT * FROM midi_actions WHERE name = 'STOP_TOPLINE'";
$results = $this->query($sql);
return $results[0];
}

public function getVoiceHarmony(){
public function getVoiceHarmony(){
$sql = "SELECT * FROM midi_actions WHERE name = 'VOICE_HARMONY'";
$results = $this->query($sql);
return $results[0];
}

function getOldTitles(){
$sql = "SELECT title FROM song_titles";
return $this->querySimpleArray($sql, 'title');
}

function getOldInspo(){
$sql = "SELECT text FROM song_inspo";
return $this->querySimpleArray($sql, 'text');
}

}
58 changes: 58 additions & 0 deletions borne/cereproc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

$text = mb_convert_encoding($line, 'UTF-8');

$credentials = 'Authorization: Basic '.base64_encode(mb_convert_encoding('[email protected]:LaMachine2022', 'UTF-8'));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://api.cerevoice.com/v2/auth");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
'accept: application/json',
$credentials
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$server_output = curl_exec($ch);
$server_output_arr = json_decode($server_output, true);

curl_close ($ch);

// Further processing ...
$res = json_decode($server_output, true);
$access_token = $res['access_token'];

if(isset($access_token)) {

$ch = curl_init();

$speech_headers = ['Authorization: Bearer ' . $access_token,
'accept: audio/mpeg',
'Content-Type: text/plain'];

$voice = urlencode('Bastien BronV1-CereWave');

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $text);
curl_setopt($ch, CURLOPT_URL, 'https://api.cerevoice.com/v2/speak?voice='.$voice.'&audio_format=mp3&sample_rate=16000&language=fr&streaming=true');
curl_setopt($ch, CURLOPT_HTTPHEADER, $speech_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // ABSOLUTELY NECESSARY IF I WANT TO SAVE EVERYTHING IN A VAR!!
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

$response = curl_exec($ch);
curl_close($ch);

if (!file_exists('audio/'.$directory)){
mkdir('audio/'.$directory, 0777, true);
}

$cereproc_audio_url = 'audio/'.$directory.'/'.$line_no.'.mp3';
file_put_contents($cereproc_audio_url, $response);

}

?>
61 changes: 61 additions & 0 deletions borne/cereproc_dedicace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

require_once("texts_dedicace.php");
$text = mb_convert_encoding(stripslashes($texts_dedicace[array_rand($texts_dedicace)]), 'UTF-8');

$credentials = 'Authorization: Basic '.base64_encode(mb_convert_encoding('[email protected]:LaMachine2022', 'UTF-8'));

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://api.cerevoice.com/v2/auth");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
'accept: application/json',
$credentials
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$server_output = curl_exec($ch);
$server_output_arr = json_decode($server_output, true);

curl_close ($ch);

// Further processing ...
$res = json_decode($server_output, true);
$access_token = $res['access_token'];

if($access_token) {

$ch = curl_init();

$speech_headers = ['Authorization: Bearer ' . $access_token,
'accept: audio/mpeg',
'Content-Type: text/plain'];

$voice = urlencode('Bastien Bron-CereWave');

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $text);
curl_setopt($ch, CURLOPT_URL, 'https://api.cerevoice.com/v2/speak?voice='.$voice.'&audio_format=mp3&sample_rate=16000&language=fr&streaming=true');
curl_setopt($ch, CURLOPT_HTTPHEADER, $speech_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // ABSOLUTELY NECESSARY IF I WANT TO SAVE EVERYTHING IN A VAR!!
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

$response = curl_exec($ch);
curl_close($ch);

if (!file_exists('audio/dedicaces')){
mkdir('audio/dedicaces', 0777, true);
}

$cereproc_audio_url = 'audio/dedicaces/'.$_SESSION['song_id'].'.mp3';
if(file_put_contents($cereproc_audio_url, $response)){
include "did_getTalk.php";
}

}

?>
3 changes: 2 additions & 1 deletion borne/create_tube.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$directory = $song_id.'_'.$directory;
$_SESSION['directory'] = $directory;

$midi_channel = $midi_tube->getChannel($song_mood);
$midi_channel = $midi_tube->getChordChannel($song_mood);
$chords = $midi_tube->getChords($song_mood);
$chords_style = $drums_style = $midi_tube->getChordsDrums($song_style);

Expand All @@ -26,6 +26,7 @@
include "song_format.php";
include "json_init.php";

$url = 'http://192.168.1.20:23456/play';

$json_obj = json_decode($json);

Expand Down
Loading

0 comments on commit 175c72f

Please sign in to comment.