Skip to content

Commit f3d3418

Browse files
committed
v3.2.0
1 parent 275d9d8 commit f3d3418

9 files changed

+114
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This is the most recent version of the PHP interface for Bol Processor BP3.<br />The C code of the console is at: https://github.com/bolprocessor/bolprocessor/tree/graphics-for-BP3<br />Read details on the website: https://bp3.tech<br />Install BP3 in MacOS/Windows/Linux: https://bolprocessor.org/check-bp3/<br />Join the project: https://sourceforge.net/projects/bolprocessor/lists/bolprocessor-devel<br><br>
1+
This is the most recent version of the PHP interface for Bol Processor BP3.<br />The C code of the console is at: https://github.com/bolprocessor/bolprocessor/tree/graphics-for-BP3<br />Read details on the website: https://bp3.tech<br />Install BP3 in MacOS/Windows/Linux: https://bolprocessor.org/install/<br />Join the project: https://sourceforge.net/projects/bolprocessor/lists/bolprocessor-devel<br><br>
22
Bernard Bel

php/_basic_tasks.php

+83-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
}
3636

3737
$skin = 1; // Blue by default
38+
$midi_player = "MIDIjs";
39+
// $midi_player = "html-midi-player";
3840

3941
require_once("_settings.php");
4042
$bp_application_path = "..".SLASH;
@@ -377,6 +379,17 @@
377379
z.className=(z.className=='hidden')?'unhidden':'hidden'; }
378380
}\n";
379381

382+
echo "function settoggledownload() {
383+
var z = document.getElementById(\"download\");
384+
if(z) {
385+
z.className='hidden'; }
386+
}\n";
387+
echo "function toggledownload() {
388+
var z = document.getElementById(\"download\");
389+
if(z) {
390+
z.className=(z.className=='hidden')?'unhidden':'hidden'; }
391+
}\n";
392+
380393
echo "function settogglescales() {
381394
var z = document.getElementById(\"scales\");
382395
if(z) {
@@ -3515,6 +3528,57 @@ function find_replace_form() {
35153528
return;
35163529
}
35173530

3531+
function download_form($dir,$thisfile,$type) {
3532+
echo "<span id=\"download\">";
3533+
echo "<div class=\"thinborder\" style=\"width:50%; padding-left:0.5em;\">";
3534+
$link = $dir.$thisfile;
3535+
echo "<input type=\"hidden\" name=\"file_link\" value=\"".$link."\">";
3536+
echo "<input type=\"hidden\" name=\"type_link\" value=\"".$type."\">";
3537+
echo "<a href=\"".$link."\" title=\"Click to download!\" download=\"".$thisfile."\">⬇️ Download this ".$type." file</a>";
3538+
echo "<p>&nbsp;&nbsp;&nbsp;<input type=\"file\" onclick=\"if(!checksaved()) return false;\" name=\"uploaded_replacement\" id=\"uploaded_replacement\">";
3539+
echo "<input class=\"save\" name=\"upload_replacement\" onclick=\"if(!checksaved()) return false;\" type=\"submit\" value=\"<-- UPLOAD FILE TO REPLACE THIS ".strtoupper($type)."\"></p>";
3540+
echo "</div>";
3541+
echo "</span>";
3542+
return;
3543+
}
3544+
3545+
function upload_replacement() {
3546+
global $permissions;
3547+
$upload_message = '';
3548+
if($_SERVER['REQUEST_METHOD'] === 'POST') {
3549+
if(isset($_FILES['uploaded_replacement']) AND $_FILES['uploaded_replacement']['error'] === UPLOAD_ERR_OK) {
3550+
$file_link = $_POST['file_link'];
3551+
$type_link = $_POST['type_link'];
3552+
$backup_file = $file_link."_bak";
3553+
copy($file_link,$backup_file);
3554+
echo "<input type=\"hidden\" name=\"file_link\" value=\"".$file_link."\">";
3555+
$fileTmpPath = $_FILES['uploaded_replacement']['tmp_name'];
3556+
$fileName = $_FILES['uploaded_replacement']['name'];
3557+
$fileSize = $_FILES['uploaded_replacement']['size'];
3558+
$fileType = $_FILES['uploaded_replacement']['type'];
3559+
if(move_uploaded_file($fileTmpPath,$file_link)) {
3560+
chmod($file_link,$permissions);
3561+
$upload_message .= "<p>👉 Replacement ".$type_link." file uploaded successfully: <span class=\"green-text\">".$file_link."</span>&nbsp;<input class=\"save\" name=\"undo_upload\" type=\"submit\" value=\"<-- UNDO THIS REPLACEMENT\"></p>";
3562+
}
3563+
else $upload_message .= "<p class=\"red-text\">👉 Error moving the uploaded file</p>";
3564+
}
3565+
else if(isset($_POST['upload_replacement'])) $upload_message .= "<p class=\"red-text\">👉 No file has been chosen…</p>";
3566+
}
3567+
return $upload_message;
3568+
}
3569+
3570+
function undo_upload() {
3571+
$undo_message = '';
3572+
if(isset($_POST['undo_upload'])) {
3573+
$file_link = $_POST['file_link'];
3574+
$backup_file = $file_link."_bak";
3575+
if(!copy($backup_file,$file_link))
3576+
$undo_message = "<p>👉 <span class=\"red-text\">Failed to find a backup of the file.</span></p>";
3577+
else $undo_message = "<p>👉 The previous version has been restored&nbsp;😀</p>";
3578+
}
3579+
return $undo_message;
3580+
}
3581+
35183582
function do_replace($content) {
35193583
if(isset($_POST['replace'])) {
35203584
$text = $_POST['thistext'] ?? '';
@@ -3878,6 +3942,7 @@ function save_midiressources($filename,$warn) {
38783942
function save_midiport($thisfilename,$acceptFilters,$passFilters,$outFilters) {
38793943
global $MIDIinput, $MIDIoutput, $MIDIinputname, $MIDIinputcomment, $MIDIoutputname, $MIDIoutputcomment; // These are tables!
38803944
global $NumberMIDIinputs, $NumberMIDIoutputs, $MIDIchannelFilter, $MIDIpartFilter;
3945+
global $permissions;
38813946
$file = fopen($thisfilename,'w');
38823947
if($file) {
38833948
for($i = 0; $i < $NumberMIDIoutputs; $i++) {
@@ -3900,7 +3965,7 @@ function save_midiport($thisfilename,$acceptFilters,$passFilters,$outFilters) {
39003965
if(isset($passFilters[$i])) fwrite($file,"MIDIpassFilter\t".$i."\t".$passFilters[$i]."\n");
39013966
}
39023967
fclose($file);
3903-
chmod($thisfilename,0775);
3968+
chmod($thisfilename,$permissions);
39043969
return true;
39053970
}
39063971
return false;
@@ -4365,14 +4430,27 @@ function make_links_clickable($text) {
43654430
return $text_with_links;
43664431
}
43674432

4433+
43684434
function midifile_player($midi_file_link, $filename, $width, $piano_roll) {
4435+
global $bp_application_path,$midi_player;
43694436
$text = "<table><tr>";
43704437
$text .= "<td style=\"padding-right:2em; padding-bottom:1em;\"><p class=\"shadow\" style=\"width:".$width."em;\">";
4371-
$text .= "<midi-player src=\"".nice_url($midi_file_link)."\" sound-font=\"https://storage.googleapis.com/magentadata/js/soundfonts/sgm_plus\" visualizer=\"#myVisualizer\"></midi-player>";
4372-
if($piano_roll) $text .= "<midi-visualizer type=\"piano-roll\" id=\"myVisualizer\"></midi-visualizer>";
4373-
$text .= "</p></td>";
4438+
if($midi_player == "MIDIjs") {
4439+
$text .= "<p class=\"shadow\" style=\"width:25em;\"><a style=\"color:#007BFF;\" href=\"#midi\" onClick=\"MIDIjs.play('".nice_url($midi_file_link)."');\"><img src=\"".$bp_application_path."php/pict/loudspeaker.png\" width=\"70px;\" style=\"vertical-align:middle;\" />PLAY</a>";
4440+
$text .= " (<a style=\"color:#007BFF;\" href=\"#midi\" onClick=\"MIDIjs.pause();\">Pause</a>) ";
4441+
$text .= " <a style=\"color:#007BFF;\" href=\"#midi\" onClick=\"MIDIjs.resume();\">Resume</a>";
4442+
$text .= " (<a style=\"color:#007BFF;\" href=\"#midi\" onClick=\"MIDIjs.stop();\">STOP</a>)</p>";
4443+
}
4444+
else if($midi_player == "html-midi-player") {
4445+
$text .= "<midi-player src=\"".nice_url($midi_file_link)."\" sound-font=\"https://storage.googleapis.com/magentadata/js/soundfonts/sgm_plus\" visualizer=\"#myVisualizer\"></midi-player>";
4446+
if($piano_roll) $text .= "<midi-visualizer type=\"piano-roll\" id=\"myVisualizer\"></midi-visualizer>";
4447+
}
4448+
$text .= "</td>";
43744449
if($filename <> '') $text .= "<td style=\"vertical-align:middle;\">".$filename."</td>";
4375-
$text .= "<td style=\"text-align:right;\"><a href=\"".nice_url($midi_file_link)."\" download>Download&nbsp;MIDI&nbsp;file</a><br /><small>This player does not support<br />volume, pitchbend, pan, etc.<br /><a target=\"_blank\" href=\"https://github.com/cifkao/html-midi-player/\">Visit html-midi-player</a></small></td>";
4450+
if($midi_player == "html-midi-player")
4451+
$text .= "<td style=\"text-align:right;\"><a href=\"".nice_url($midi_file_link)."\" download>Download&nbsp;MIDI&nbsp;file</a><br /><small>This player does not support<br />volume, pitchbend, pan, etc.<br /><a target=\"_blank\" href=\"https://github.com/cifkao/html-midi-player/\">Visit html-midi-player</a></small></td>";
4452+
else if($midi_player == "MIDIjs")
4453+
$text .= "<td style=\"text-align:right; vertical-align:middle;\"><a href=\"".nice_url($midi_file_link)."\" download>Download&nbsp;MIDI&nbsp;file</a></td>";
43764454
$text .= "</tr></table>";
43774455
return $text;
43784456
}

php/compile.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$filename = "Compilation";
33
require_once("_basic_tasks.php");
44
echo "<head>";
5-
echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
65
echo "<script src=\"darkmode.js\"></script>";
76
echo "</head>";
87
echo "<body>";

php/data.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,14 @@
12151215
}
12161216
else read_midiressources($filename);
12171217

1218+
$upload_message = upload_replacement();
1219+
if($upload_message <> '') $need_to_save = FALSE;
1220+
$undo_upload_message = undo_upload();
1221+
12181222
try_create_new_file($this_file,$filename);
1223+
/* echo "this_file = ".$this_file." permissions = ".$permissions."<br >";
1224+
chmod($this_file,"0775");
1225+
exec("chmod 755 ".$this_file); */
12191226
$content = @file_get_contents($this_file);
12201227
if($content === FALSE) ask_create_new_file($url_this_page,$filename);
12211228
$content = mb_convert_encoding($content,'UTF-8','UTF-8');
@@ -1535,12 +1542,14 @@
15351542
if(file_exists($capture_file)) echo "<span class=\"red-text\">👉 The current file of captured MIDI data is badly formed</span></p>";
15361543
else echo "</p>";
15371544
}
1538-
echo "<p><button class=\"edit big\"\" onclick=\"togglesearch(); return false;\">SEARCH & REPLACE</button></p>";
1545+
echo "<p><button class=\"save\"\" onclick=\"toggledownload(); return false;\">DOWNLOAD / UPLOAD</button>&nbsp;<button class=\"edit\"\" onclick=\"togglesearch(); return false;\">SEARCH & REPLACE</button></p>";
1546+
1547+
download_form($dir,$filename,"data"); find_replace_form();
1548+
echo $upload_message; echo $undo_upload_message;
1549+
15391550
echo "<br /><table border=\"0\" style=\"background-color:transparent;\"><tr style=\"background-color:transparent;\">";
15401551
echo "<td style=\"background-color:transparent;\">";
15411552

1542-
find_replace_form();
1543-
15441553
echo "<div style=\"float:right; vertical-align:middle; background-color:transparent;\">Import MusicXML: <input onclick=\"if(!checksaved()) return false;\" type=\"file\" name=\"music_xml_import\">&nbsp;<input type=\"submit\" onclick=\"if(!checksaved()) return false;\" class=\"save\" value=\"← IMPORT\"></div>";
15451554

15461555
echo "<div style=\"text-align:left; background-color:transparent;\"><input id=\"saveButton\" class=\"save big\" type=\"submit\" onclick=\"clearsave();\" formaction=\"".$url_this_page."#topedit\" name=\"savethisfile\" value=\"SAVE ‘".begin_with(20,$filename)."\"></div>";
@@ -1836,18 +1845,9 @@
18361845
echo "</table>";
18371846
echo "<script>\n";
18381847
echo "window.onload = function() {
1839-
toggleAllDisplays($NumberMIDIinputs); toggleAllDisplays($NumberMIDIoutputs); settogglesearch(); settogglescales();
1848+
toggleAllDisplays($NumberMIDIinputs); toggleAllDisplays($NumberMIDIoutputs); settogglesearch(); settoggledownload(); settogglescales();
18401849
};\n";
18411850
echo "</script>\n";
1842-
/* echo "<pre>"; // Preformatted tag to display output neatly
1843-
// Execute a shell command to list MIDI devices
1844-
// Using `system_profiler` to get audio device information which includes MIDI
1845-
system("system_profiler SPAudioDataType | grep MIDI");
1846-
echo "</pre>";
1847-
echo "<pre>";
1848-
// send_to_console("python3 midi_list.py");
1849-
system("python3 midi_list.py");
1850-
echo "</pre>"; */
18511851
echo "</body></html>";
18521852

18531853
function create_chunks($line,$i_item,$temp_dir,$temp_folder,$minchunk_size,$maxchunk_size,$measure_min,$measure_max,$label) {

php/grammar.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@
286286

287287
if($test) echo "grammar_file = ".$this_file."<br />";
288288

289+
$upload_message = upload_replacement();
290+
if($upload_message <> '') $need_to_save = FALSE;
291+
$undo_upload_message = undo_upload();
292+
289293
try_create_new_file($this_file,$filename);
290294
$content = @file_get_contents($this_file);
291295
if($content === FALSE) ask_create_new_file($url_this_page,$filename);
@@ -629,9 +633,11 @@
629633

630634
echo "<span id=\"topedit\">&nbsp;</span>";
631635
echo $save_warning;
632-
echo "<br /><button class=\"edit big\" onclick=\"togglesearch(); return false;\">SEARCH & REPLACE</button><p></p>";
636+
echo "<br /><button class=\"save\"\" onclick=\"toggledownload(); return false;\">DOWNLOAD / UPLOAD</button>&nbsp;<button class=\"edit\" onclick=\"togglesearch(); return false;\">SEARCH & REPLACE</button><p></p>";
637+
638+
download_form($dir,$filename,"grammar"); find_replace_form();
639+
echo $upload_message; echo $undo_upload_message;
633640

634-
find_replace_form();
635641
echo "<p><input class=\"save big\" type=\"submit\" id=\"saveButton\" onclick=\"clearsave();\" name=\"savethisfile\" formaction=\"".$url_this_page."\" value=\"SAVE ‘".begin_with(20,$filename)."\">";
636642
if((file_exists($output.SLASH.$default_output_name.".wav") OR file_exists($output.SLASH.$default_output_name.".mid") OR file_exists($output.SLASH.$default_output_name.".html") OR file_exists($output.SLASH.$default_output_name.".sco")) AND file_exists($result_file)) {
637643
echo "&nbsp;&nbsp;&nbsp;<input class=\"edit\" style=\"font-size:large;\" onclick=\"window.open('".nice_url($result_file)."','result','width=800,height=600,left=100'); return false;\" type=\"submit\" name=\"produce\" value=\"Show latests results\">";
@@ -802,7 +808,7 @@
802808
echo "</form>";
803809
echo "<script>\n";
804810
echo "window.onload = function() {
805-
toggleAllDisplays($NumberMIDIinputs); toggleAllDisplays($NumberMIDIoutputs); settogglesearch(); settogglescales();
811+
toggleAllDisplays($NumberMIDIinputs); toggleAllDisplays($NumberMIDIoutputs); settogglesearch(); settoggledownload(); settogglescales();
806812
};\n";
807813
echo "</script>\n";
808814
echo "</body>";

php/produce.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
else $this_title = '';
66

77
echo "<head>";
8-
echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
8+
if($midi_player == "MIDIjs") echo "<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>";
9+
else if($midi_player == "html-midi-player") echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
910
echo "<script src=\"darkmode.js\"></script>";
1011
echo "<link rel=\"stylesheet\" href=\"bp-light.css\" />\n";
1112
echo "</head>";
@@ -711,8 +712,7 @@
711712
$header .= "<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />\n";
712713
$header .= "<link rel=\"stylesheet\" href=\"".$bp_application_path."php/bp-light.css\" />\n";
713714
$header .= "<title>".$result_file."</title>\n";
714-
https://cdn.jsdelivr.net
715-
// $header .= "<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>\n";
715+
$header .= "<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>\n";
716716
$header .= "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
717717
$header .= "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js\"></script>\n";
718718
$header .= "</head><body>\n";

php/prototype.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
require_once("_header.php");
2121
display_darklight();
2222

23-
echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
23+
if($midi_player == "MIDIjs") echo "<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>";
24+
else if($midi_player == "html-midi-player") echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
2425

2526
$object_foldername = clean_folder_name($object_name);
2627

php/script.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176

177177
echo "<script>\n";
178178
echo "window.onload = function() {
179-
settogglesearch();
179+
settogglesearch(); settoggledownload();
180180
};\n";
181181
echo "</script>\n";
182182
echo "</body>";

php/timebase.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
require_once("_header.php");
1717
display_darklight();
1818

19-
echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
19+
if($midi_player == "MIDIjs") echo "<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>";
20+
else if($midi_player == "html-midi-player") echo "<script src=\"https://cdn.jsdelivr.net/combine/npm/[email protected],npm/@magenta/[email protected]/es6/core.js,npm/focus-visible@5,npm/[email protected]\"></script>";
2021

2122
$url = "index.php?path=".urlencode($current_directory);
2223
echo "<p>Workspace = <input title=\"List this workspace\" class=\"edit\" name=\"workspace\" type=\"submit\" onclick=\"window.open('".$url."','_self');\" value=\"".$current_directory."\">";

0 commit comments

Comments
 (0)