35
35
}
36
36
37
37
$ skin = 1 ; // Blue by default
38
+ $ midi_player = "MIDIjs " ;
39
+ // $midi_player = "html-midi-player";
38
40
39
41
require_once ("_settings.php " );
40
42
$ bp_application_path = ".. " .SLASH ;
377
379
z.className=(z.className=='hidden')?'unhidden':'hidden'; }
378
380
} \n" ;
379
381
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
+
380
393
echo "function settogglescales() {
381
394
var z = document.getElementById( \"scales \");
382
395
if(z) {
@@ -3515,6 +3528,57 @@ function find_replace_form() {
3515
3528
return ;
3516
3529
}
3517
3530
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> <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> <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 😀</p> " ;
3578
+ }
3579
+ return $ undo_message ;
3580
+ }
3581
+
3518
3582
function do_replace ($ content ) {
3519
3583
if (isset ($ _POST ['replace ' ])) {
3520
3584
$ text = $ _POST ['thistext ' ] ?? '' ;
@@ -3878,6 +3942,7 @@ function save_midiressources($filename,$warn) {
3878
3942
function save_midiport ($ thisfilename ,$ acceptFilters ,$ passFilters ,$ outFilters ) {
3879
3943
global $ MIDIinput , $ MIDIoutput , $ MIDIinputname , $ MIDIinputcomment , $ MIDIoutputname , $ MIDIoutputcomment ; // These are tables!
3880
3944
global $ NumberMIDIinputs , $ NumberMIDIoutputs , $ MIDIchannelFilter , $ MIDIpartFilter ;
3945
+ global $ permissions ;
3881
3946
$ file = fopen ($ thisfilename ,'w ' );
3882
3947
if ($ file ) {
3883
3948
for ($ i = 0 ; $ i < $ NumberMIDIoutputs ; $ i ++) {
@@ -3900,7 +3965,7 @@ function save_midiport($thisfilename,$acceptFilters,$passFilters,$outFilters) {
3900
3965
if (isset ($ passFilters [$ i ])) fwrite ($ file ,"MIDIpassFilter \t" .$ i ."\t" .$ passFilters [$ i ]."\n" );
3901
3966
}
3902
3967
fclose ($ file );
3903
- chmod ($ thisfilename ,0775 );
3968
+ chmod ($ thisfilename ,$ permissions );
3904
3969
return true ;
3905
3970
}
3906
3971
return false ;
@@ -4365,14 +4430,27 @@ function make_links_clickable($text) {
4365
4430
return $ text_with_links ;
4366
4431
}
4367
4432
4433
+
4368
4434
function midifile_player ($ midi_file_link , $ filename , $ width , $ piano_roll ) {
4435
+ global $ bp_application_path ,$ midi_player ;
4369
4436
$ text = "<table><tr> " ;
4370
4437
$ 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> " ;
4374
4449
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 MIDI 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 MIDI 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 MIDI file</a></td> " ;
4376
4454
$ text .= "</tr></table> " ;
4377
4455
return $ text ;
4378
4456
}
0 commit comments