Daniel@0: /* Part of DML (Digital Music Laboratory) Daniel@0: Copyright 2014-2015 Samer Abdallah, University of London Daniel@0: Daniel@0: This program is free software; you can redistribute it and/or Daniel@0: modify it under the terms of the GNU General Public License Daniel@0: as published by the Free Software Foundation; either version 2 Daniel@0: of the License, or (at your option) any later version. Daniel@0: Daniel@0: This program is distributed in the hope that it will be useful, Daniel@0: but WITHOUT ANY WARRANTY; without even the implied warranty of Daniel@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Daniel@0: GNU General Public License for more details. Daniel@0: Daniel@0: You should have received a copy of the GNU General Public Daniel@0: License along with this library; if not, write to the Free Software Daniel@0: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Daniel@0: */ Daniel@0: Daniel@0: :- module(score_ui, [ sonify_ui//2]). Daniel@0: Daniel@0: /** Score related pages and hooks Daniel@0: Daniel@0: This module provides a web pages for displaying rendered scores and for Daniel@0: an audio player to play sonified scores. Daniel@0: It also module provides resource decorations and local view customisations Daniel@0: for Humdrum scores. Daniel@0: */ Daniel@0: Daniel@0: :- use_module(library(http/html_write)). Daniel@0: :- use_module(library(http/html_head)). Daniel@0: :- use_module(library(http/http_dispatch)). Daniel@0: :- use_module(library(http/http_parameters)). Daniel@0: :- use_module(library(semweb/rdfs)). Daniel@0: :- use_module(library(semweb/rdf_label)). Daniel@0: :- use_module(library(dcg_core)). Daniel@0: :- use_module(library(dcg_codes)). Daniel@0: :- use_module(library(decoration)). Daniel@0: :- use_module(library(rdfutils)). Daniel@0: :- use_module(library(httpfiles)). Daniel@0: :- use_module(components(score)). Daniel@0: :- use_module(components(icons)). Daniel@0: :- use_module(api(score)). Daniel@0: Daniel@0: :- set_prolog_flag(double_quotes,string). Daniel@0: Daniel@0: :- http_handler(root(dml/score/audio), score_audio, []). Daniel@0: :- http_handler(root(dml/score/view), score_view, []). Daniel@0: Daniel@0: decoration:resource_decoration(URI,Link) --> Daniel@0: {rdfs_individual_of(URI,hum:'File')}, !, Daniel@0: {http_link_to_id(score_view,[uri(URI)],ScoreURL)}, Daniel@0: {http_link_to_id(score_sonify,[uri(URI),format(ogg)],AudioURL)}, Daniel@0: html_requires(font_awesome), Daniel@0: html_requires(js('add_dummy_iframe.js')), Daniel@0: html( span( [ a(href(ScoreURL),\icon(music)) Daniel@0: , &(nbsp), a([href(AudioURL),target(dummy)],\icon(play)) Daniel@0: , &(nbsp), a([href('about:blank'),target(dummy)],\icon(stop)) Daniel@0: , &(ensp), \Link Daniel@0: ])). Daniel@0: Daniel@0: rdf_label:label_hook(URI,literal(Lit)) :- Daniel@0: rdf(URI,rdf:type,hum:'File'), Daniel@0: (var(Lit) -> Lit=Label; Lit=lang(_,Label)), Daniel@0: phrase_string(uri_label(URI),Label). Daniel@0: Daniel@0: uri_label(URI) --> Daniel@0: {atom_concat('kern:',File,URI)}, Daniel@0: file_label(URI,File). Daniel@0: Daniel@0: file_label(URI,File) --> Daniel@0: { suffix(30,File,ShortFile) }, Daniel@0: at(ShortFile), Daniel@0: if(rdf_text(URI,hum:'refcode/OTL',Title), (" - ",at(Title)," ")), Daniel@0: if((rdf_text(URI,hum:'refcode/COM',Composer),short_name(Composer,Comp)), Daniel@0: paren(at(Comp))). Daniel@0: Daniel@0: suffix(MaxLen,String,Shorter) :- Daniel@0: string_length(String,N), Daniel@0: ( N= Daniel@0: {rdfs_individual_of(URI,hum:'File')}, Daniel@0: {http_link_to_id(score_view,[uri(URI)],ViewURL)}, Daniel@0: html([ a(href=ViewURL, [\icon(music), " View score"]), &('MediumSpace') Daniel@0: , br([]), "Download as:" Daniel@0: , \seqmap(link(URI),[s-kern,s-mxml,s-lily,s-abc,a-midi]) Daniel@0: , \seqmap(render_link(URI),[pdf]) Daniel@0: , h2("Score sonification") Daniel@0: % , br([]), "Download audio as:" Daniel@0: % , \seqmap(link(URI),[a-ogg,a-mp3]) Daniel@0: % , br([]) Daniel@0: % , \score_audio_player(URI) Daniel@0: , \sonify_ui(URI,score_ui:score_audio) Daniel@0: , \pitch_class_histogram(URI) Daniel@0: ]). Daniel@0: Daniel@0: Daniel@0: score_audio(Request) :- Daniel@0: http_parameters(Request, Daniel@0: [ uri(URI, [optional(false), description("URI of score to render")]) Daniel@0: , autoplay(Auto, [boolean, default(false)]) Daniel@0: ], [form_data(Params)]), Daniel@0: reply_html_page(cliopatria(bare), [title("Audio element")], Daniel@0: \score_audio_player(URI,[autoplay(Auto)],Params), Daniel@0: [stable]). Daniel@0: Daniel@0: score_view(Request) :- Daniel@0: http_parameters(Request, Daniel@0: [ uri(URI, [optional(false), description("URI of score to render")]) Daniel@0: , width(W, [ optional(true), default(170), nonneg Daniel@0: , description("Page width in mm") ]) Daniel@0: ]), Daniel@0: ( (rdf_text(URI,hum:'refcode/OPT',Parent);rdf_text(URI,hum:'refcode/OPR',Parent)) Daniel@0: -> (rdf_text(URI,hum:'refcode/OTL',Title); Title=""), Daniel@0: format(string(FullTitle),"~w, ~w",[Parent,Title]) Daniel@0: ; (rdf_text(URI,hum:'refcode/OTL',FullTitle); FullTitle="") Daniel@0: ), Daniel@0: (rdf(URI,hum:'refcode/COM',Composer); Composer=""), Daniel@0: reply_html_page(cliopatria(demo), [title(FullTitle)], Daniel@0: [ h1(FullTitle) Daniel@0: , h2(['By ',Composer]) Daniel@0: , p([ "Resource view: ", \(cp_label:rdf_link(URI,[decoration(false), resource_format(nslabel)])) Daniel@0: % , br([]) Daniel@0: % , "Download as:" Daniel@0: % , \seqmap(link(URI),[s-kern,s-mxml,s-lily,s-abc,a-midi]) Daniel@0: % , \seqmap(render_link(URI),[pdf]) Daniel@0: , \sonify_ui(URI,score_ui:score_audio) Daniel@0: % , br([]), "Download audio as:" Daniel@0: % , \seqmap(link(URI),[a-ogg,a-mp3]) Daniel@0: % , br([]) Daniel@0: % , \score_audio_player(URI) Daniel@0: , br([]) Daniel@0: ]) Daniel@0: , \score(URI,W) Daniel@0: ], Daniel@0: [stable]). Daniel@0: Daniel@0: render_link(URI,Fmt) --> Daniel@0: {http_link_to_id(score_render,[uri(URI),layout(page),format(Fmt)],URL), Daniel@0: string_concat("score.",Fmt,Filename)}, Daniel@0: html([" ",a([href=URL,download=Filename],Fmt)]). Daniel@0: Daniel@0: link(URI,R-Fmt) --> Daniel@0: { variant_sha1(URI,Hash), Daniel@0: atomics_to_string([score,Hash,'.',Fmt],Filename), Daniel@0: get_link(URI,R-Fmt,URL) Daniel@0: }, Daniel@0: html([" ",a([href=URL,download=Filename],Fmt)]). Daniel@0: