Des partitions avec SPIP !
Voici la possibilité d’insérer dans les contenus SPIP des extraits musicaux grâce à Verovio : https://www.verovio.org. L'idée est de créer des images au format SVG à la volée, en Javascript, dès le chargement de la page. Utilisation : -* Les données figurent en clair entre les balises <code><ascore></code> et <code></ascore></code>. -* Les documents sont accessibles grâce au modèle <code><scoreXX></code> où XX est l’identifiant du document. Format des données : MEI, Humdrum, MusicXML, Plaine and Easie (PAE), ABC. _ Explications : https://book.verovio.org/toolkit-reference/input-formats.htmlmaster
parent
f378b1193c
commit
8d04509b22
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) {
|
||||
return;
|
||||
}
|
||||
|
||||
function ascore_upgrade($nom_meta_base_version, $version_cible) {
|
||||
$maj = array();
|
||||
|
||||
$maj['create'] = array(
|
||||
/* Ajouter les nouvelles extensions en base pour qu'elles soient telechargeables */
|
||||
array('sql_insertq_multi', 'spip_types_documents', array(
|
||||
array('extension' => 'mei', 'titre' => 'Music Encoding Initiative', 'inclus' => 'non', 'upload' => 'oui', 'mime_type' => 'application/vnd.mei+xml', 'media_defaut' => 'file'),
|
||||
array('extension' => 'abc', 'titre' => 'ABC Music Notation', 'inclus' => 'non', 'upload' => 'oui', 'mime_type' => 'text/vnd.abc', 'media_defaut' => 'file'),
|
||||
|
||||
)),
|
||||
);
|
||||
/*
|
||||
$maj['0.1'] = array(
|
||||
array('sql_updateq', 'spip_documents', array('extension' => 'dist_cubox'), "extension='culturebox'"),
|
||||
array('sql_insertq', 'spip_types_documents', array('extension' => 'dist_cubox', 'titre' => 'CultureBox', 'inclus' => 'embed', 'upload' => 'oui')),
|
||||
);
|
||||
*/
|
||||
|
||||
include_spip('base/upgrade');
|
||||
maj_plugin($nom_meta_base_version, $version_cible, $maj);
|
||||
}
|
||||
|
||||
|
||||
function ascore_vider_tables($nom_meta_base_version) {
|
||||
sql_delete("spip_types_documents", sql_in("extension", array('mei', 'abc')));
|
||||
|
||||
effacer_meta($nom_meta_base_version);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
#ini_set('display_errors','1'); error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return;
|
||||
#---------------------------------------------------#
|
||||
# Plugin : AScore #
|
||||
# Auteur : Patrice Vanneufville, 2021 #
|
||||
# Contact : patrice¡.!vanneufville¡@!laposte¡.!net #
|
||||
# Licence : GPL #
|
||||
#--------------------------------------------------------------------------#
|
||||
# Documentation : https://contrib.spip.net/ #
|
||||
#--------------------------------------------------------------------------#
|
||||
|
||||
// balises du plugin a inserer dans les articles
|
||||
define('_SCORE_DEBUT', '<ascore>');
|
||||
define('_SCORE_FIN', '</ascore>');
|
||||
define('_VEROVIO_HEAD', "<!-- JS VEROVIO -->");
|
||||
|
||||
// filtre qui retire le code source des partitions du texte original
|
||||
function pas_de_balise_ascore($texte) {
|
||||
if(strpos($texte, _SCORE_DEBUT)===false) return $texte;
|
||||
return preg_replace(','.preg_quote(_SCORE_DEBUT).'.*?'.preg_quote(_SCORE_DEBUT).',UimsS', '', $texte);
|
||||
}
|
||||
|
||||
// aide le Couteau Suisse a calculer la balise #INTRODUCTION
|
||||
$GLOBALS['cs_introduire'][] = 'pas_de_balise_ascore';
|
||||
|
||||
?>
|
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
#ini_set('display_errors','1'); error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return;
|
||||
#---------------------------------------------------#
|
||||
# Plugin : AScore #
|
||||
# Auteur : Patrice Vanneufville, 2021 #
|
||||
# Contact : patrice¡.!vanneufville¡@!laposte¡.!net #
|
||||
# Licence : GPL #
|
||||
#--------------------------------------------------------------------------#
|
||||
# Documentation : https://contrib.spip.net/ #
|
||||
#--------------------------------------------------------------------------#
|
||||
|
||||
// fonction pre-traitement, pipeline pre_propre
|
||||
// insertion de quelques balises de reconnaissance
|
||||
function ascore_pre_typo($texte, $recurrent = false) {
|
||||
if(!strlen($texte)) return '';
|
||||
// commencer par isoler le code de la partition
|
||||
if(strpos($texte, _SCORE_DEBUT)===false || strpos($texte, _SCORE_FIN)===false) return $texte;
|
||||
list($texteAvant, $suite) = explode(_SCORE_DEBUT, $texte, 2);
|
||||
list($texte, $texteApres) = explode(_SCORE_FIN, $suite, 2);
|
||||
$texte = trim($texte);
|
||||
$msg = '';
|
||||
// le xml est-il protégé par <html/>?
|
||||
if(strpos($texte, 'class="base64"')===5) // <span ou <div
|
||||
$texte = echappe_retour($texte);
|
||||
if(strpos($texte, '<mei')!==false && strpos($texte, 'base64')!==false) {
|
||||
$msg = "\n_ ".htmlentities(_SCORE_DEBUT.'<html>your data...</html>'._SCORE_FIN);
|
||||
$msg = _L('Format MEI détecté, il est nécessaire d\'utiliser la syntaxe suivante : @syntaxe@.', array('syntaxe'=>$msg));
|
||||
}
|
||||
// recuperation du fond 'modele/score.html' en protegeant le javascript
|
||||
include_spip('public/assembler');
|
||||
$score = protege_js_modeles(recuperer_fond('modeles/score', array(
|
||||
'data' => base64_encode($texte),
|
||||
'id_score' => 0,
|
||||
'msg' => $msg,
|
||||
)));
|
||||
|
||||
return $texteAvant . $score . ascore_pre_typo($texteApres, true);
|
||||
}
|
||||
|
||||
/*
|
||||
// pipeline ramasse-miettes permet de recuperer le HTML propre *après* la reinsertion des modeles
|
||||
// les scripts de partitions (base ou inline) sont empeches en partie privee, il a fallu les echapper.
|
||||
// textwheel >= 1.3.5
|
||||
function ascore_post_echappe_html_propre($texte) {
|
||||
return echappe_retour($texte, 'VEROVIO_SCRIPTS');
|
||||
}
|
||||
*/
|
||||
|
||||
define('_VEROVIO_SCRIPT',
|
||||
'<script src="https://www.verovio.org/javascript/latest/verovio-toolkit.js" type="text/javascript"></script>');
|
||||
|
||||
// pour inserer un js
|
||||
function ascore_javascript($b) {
|
||||
$f = find_in_path("javascript/$b.js");
|
||||
return $f?'<script type="text/javascript" src="'.$f."\"></script>\n":'';
|
||||
}
|
||||
|
||||
// pipeline header_prive
|
||||
function ascore_header_prive($flux){
|
||||
$flux .= _VEROVIO_SCRIPT . ascore_javascript('verovio');
|
||||
return $flux;
|
||||
}
|
||||
|
||||
// pipeline insert_head
|
||||
function ascore_insert_head($flux){
|
||||
return $flux . _VEROVIO_HEAD;
|
||||
}
|
||||
|
||||
// Le pipeline affichage_final, execute a chaque hit sur toute la page
|
||||
// Incorporation du js dans <head> a la place de _VEROVIO_HEAD, si un score
|
||||
// est present dans la page
|
||||
function ascore_affichage_final($flux) {
|
||||
return str_replace(_VEROVIO_HEAD,
|
||||
strpos($flux, 'verovioCreate')!==false?_VEROVIO_SCRIPT . ascore_javascript('verovio'):'',
|
||||
$flux);
|
||||
}
|
||||
|
||||
/*
|
||||
// Afficher la configuration trouvee
|
||||
function ascore_affiche_milieu($flux){
|
||||
if ($flux['args']['exec'] == 'article') {
|
||||
$flux['data'].= ascore_configuration_inline($flux['args']['id_article']);
|
||||
}
|
||||
return $flux;
|
||||
}*/
|
||||
|
||||
?>
|
@ -0,0 +1,47 @@
|
||||
/* Number of the first score */
|
||||
var verovioId = 1;
|
||||
var verovioTools = [];
|
||||
var verovioRenders = [];
|
||||
|
||||
function verovioCreate(data, options, myOptions) {
|
||||
/* Create the #outputNN div */
|
||||
var id = myOptions.myId;
|
||||
var attrId = 'verovioOutput' + id;
|
||||
document.write('<' + myOptions.myBalise + ' id="' + attrId + '"></' + myOptions.myBalise + '>');
|
||||
/* Create the Vevorio toolkit instance */
|
||||
verovioTools[id] = new verovio.toolkit();
|
||||
if(myOptions.myType=='inline') {
|
||||
verovioRenders[id] = function(){
|
||||
console.log('Inline. ' + attrId);
|
||||
/* Render the data and insert it as content of the #outputNN div */
|
||||
document.getElementById(attrId).innerHTML = verovioTools[id].renderData(
|
||||
data,
|
||||
options
|
||||
);
|
||||
}
|
||||
} else if(myOptions.myType=='file') {
|
||||
verovioRenders[id] = function(){
|
||||
console.log('File. ' + attrId);
|
||||
|
||||
fetch(data)
|
||||
.then( function(response) { return response.text(); } )
|
||||
.then( function(meiXML) {
|
||||
var svg = verovioTools[id].renderData(meiXML, options);
|
||||
document.getElementById(attrId).innerHTML = svg;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
window.addEventListener("load", verovioRenders[id]);
|
||||
}
|
||||
|
||||
function verovioReDrawAll() {
|
||||
// Si ajax, on construit tout de suite les nouveaux jeux
|
||||
for (id in verovioRenders)
|
||||
if(document.getElementById("verovioOutput" + id))
|
||||
verovioRenders[id]();
|
||||
}
|
||||
|
||||
(function($){
|
||||
$(document).ready(function(){ onAjaxLoad(verovioReDrawAll); });
|
||||
})(jQuery);
|
@ -0,0 +1,31 @@
|
||||
[(#ENV**{msg}|oui)<p style="color:darkred; font-weight:bold">#ENV{msg}</p>]
|
||||
|
||||
<script type="text/javascript">
|
||||
var id = Math.round(+new Date()).toString() + ("00"+verovioId++).slice(-3);
|
||||
var myOptions = {
|
||||
myBalise: 'div',
|
||||
myId: id
|
||||
}
|
||||
var options = {
|
||||
font: 'Bravura',
|
||||
svgViewBox: true, // Use viewBox on svg root element for easy scaling of document
|
||||
breaks: 'auto', // Define page and system breaks layout (default: "auto"; other values: 'none', 'auto', 'line', 'smart', 'encoded')
|
||||
adjustPageHeight: 1 // Adjust the page height to the height of the content
|
||||
}
|
||||
<BOUCLE_doc(DOCUMENTS){id_document=#ENV{id_score}}{tout}>
|
||||
myOptions.myType = 'file';
|
||||
var file = "[(#URL_DOCUMENT|url_absolue)]";
|
||||
verovioCreate(file, options, myOptions);
|
||||
</BOUCLE_doc>
|
||||
</B_doc>
|
||||
[(#ENV**{data}|oui)
|
||||
myOptions.myType = 'inline';
|
||||
var data = atob("#ENV**{data}");
|
||||
verovioCreate(data, options, myOptions);
|
||||
]
|
||||
[(#ENV**{data}|non)
|
||||
document.write('<p style="color:darkred; font-weight:bold">Document #[(#ENV{id_score})] non trouvé ?</p>');
|
||||
]
|
||||
<//B_doc>
|
||||
</script>
|
||||
<noscript>Vous devez avoir Javascript activé pour utiliser ce module</noscript>
|
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in New Issue