improved audio generation line (still not that good though)

master
Fabien Benetou 14 years ago
parent 10995b4e4a
commit eb520ecd50
  1. 484
      pmwiki_recipes/pim_functions.php

@ -1,242 +1,242 @@
<?php <?php
/* PIM functions (for PmWiki) /* PIM functions (for PmWiki)
consider adding other related scripts here too (e.g. MemoryRecipe, Recalls, GroupStats, Coeditions, ...) consider adding other related scripts here too (e.g. MemoryRecipe, Recalls, GroupStats, Coeditions, ...)
http://fabien.benetou.fr/pub/graphformatexporter.php.txt http://fabien.benetou.fr/pub/graphformatexporter.php.txt
http://fabien.benetou.fr/pub/memorization.php.txt http://fabien.benetou.fr/pub/memorization.php.txt
note that the order is important though note that the order is important though
e.g. currently MemoryRecipe is loaded after thus can't be called here e.g. currently MemoryRecipe is loaded after thus can't be called here
add to http://fabien.benetou.fr/repository/ add to http://fabien.benetou.fr/repository/
it would be particularly useful to refactor each properly it would be particularly useful to refactor each properly
especially since they share variables (e.g. first edit) but also some have better function especially since they share variables (e.g. first edit) but also some have better function
e.g. caching in Coeditions e.g. caching in Coeditions
change ProcessingJS generation by first producing JSON change ProcessingJS generation by first producing JSON
via http://www.php.net/manual/en/function.json-encode.php via http://www.php.net/manual/en/function.json-encode.php
cf http://fabien.benetou.fr/Tools/Processing and http://fabien.benetou.fr/Tools/JavaScript cf http://fabien.benetou.fr/Tools/Processing and http://fabien.benetou.fr/Tools/JavaScript
this might be even faster on most computers since JS engines are improving this might be even faster on most computers since JS engines are improving
*/ */
//handle implicit linking //handle implicit linking
/* /*
cf http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#ImplicitLinking cf http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#ImplicitLinking
*/ */
function ImplicitLinking(){ function ImplicitLinking(){
return "list of pages generated on the fly"; return "list of pages generated on the fly";
} }
//$AutoCreate['/\\.GroupStats$/'] = array( 'ctime' => $Now, 'text' => ImplicitLinking()); //$AutoCreate['/\\.GroupStats$/'] = array( 'ctime' => $Now, 'text' => ImplicitLinking());
//$AutoCreate['/^Categora\\./'] = array('ctime' => $Now); //$AutoCreate['/^Categora\\./'] = array('ctime' => $Now);
//doesn't work, AutoCreate present in pmwiki.php and example too //doesn't work, AutoCreate present in pmwiki.php and example too
// category works though // category works though
// TODO try making it global $AutoCreate; // TODO try making it global $AutoCreate;
//display working status //display working status
// see http://fabien.benetou.fr/Tools/Greasemonkey#VirtualBlinders // see http://fabien.benetou.fr/Tools/Greasemonkey#VirtualBlinders
Markup("currenttask", "directives", "/\(:currenttask:\)/", GetCurrentTask()); Markup("currenttask", "directives", "/\(:currenttask:\)/", GetCurrentTask());
function GetCurrentTask(){ function GetCurrentTask(){
$currenttask = trim(file_get_contents("/home/utopiah/web/benetou.fr/fabien/pub/currenttask")); $currenttask = trim(file_get_contents("/home/utopiah/web/benetou.fr/fabien/pub/currenttask"));
if ($currenttask == "") if ($currenttask == "")
return "(either available or asleep, Im usually on CET)"; return "(either available or asleep, Im usually on CET)";
return "[[CognitiveEnvironments/".$currenttask."]]"; return "[[CognitiveEnvironments/".$currenttask."]]";
} }
Markup("timetable", "fulltext", "/\(:timetable:\)/", Markup("timetable", "fulltext", "/\(:timetable:\)/",
"\n||border=1\n||!Time ||!Action ||\n" "\n||border=1\n||!Time ||!Action ||\n"
.preg_replace("/echo -level HILIGHT -window 1 /","", .preg_replace("/echo -level HILIGHT -window 1 /","",
preg_replace("/.* (\d+) (\d+).* \/(.*)/","||$1:$2||$3||",file_get_contents("/home/utopiah/.irssi/cron.save")) preg_replace("/.* (\d+) (\d+).* \/(.*)/","||$1:$2||$3||",file_get_contents("/home/utopiah/.irssi/cron.save"))
) )
.""); ."");
//load a dedicated edition page for the admin (shouldn't be hard coded but I dont use Auth) //load a dedicated edition page for the admin (shouldn't be hard coded but I dont use Auth)
//global $GLOBALS; //global $GLOBALS;
if ($GLOBALS['action'] == 'edit' && ( $GLOBALS['Author'] == 'Fabien' || $GLOBALS['Author'] == 'Utopiah' ) ) if ($GLOBALS['action'] == 'edit' && ( $GLOBALS['Author'] == 'Fabien' || $GLOBALS['Author'] == 'Utopiah' ) )
{ {
//TODO fails since moved in cookbook directory, thus added back there //TODO fails since moved in cookbook directory, thus added back there
global $SkinDir,$pagename; global $SkinDir,$pagename;
LoadPageTemplate($pagename, "$SkinDir/edit.tmpl"); LoadPageTemplate($pagename, "$SkinDir/edit.tmpl");
} }
//display editions through an horizontal line //display editions through an horizontal line
/* /*
fomally done via GnuPlot, cf http://fabien.benetou.fr/Wiki/Visualization#timeline fomally done via GnuPlot, cf http://fabien.benetou.fr/Wiki/Visualization#timeline
http://www.scholarpedia.org/article/Spike-response_model is probably too complicated for the small resolution http://www.scholarpedia.org/article/Spike-response_model is probably too complicated for the small resolution
yet provide interesting non-linear properties yet provide interesting non-linear properties
*/ */
function DisplayVisualEdits($pagename){ function DisplayVisualEdits($pagename){
global $ScriptUrl, $PubDir, $FarmD; global $ScriptUrl, $PubDir, $FarmD;
# equivalent to 404 # equivalent to 404
if (!PageExists($pagename)) return; if (!PageExists($pagename)) return;
$processingpath = '/pub/libraries/processing.js'; $processingpath = '/pub/libraries/processing.js';
$processingfile = "/pub/visualization/edits_per_page/$pagename.pjs"; $processingfile = "/pub/visualization/edits_per_page/$pagename.pjs";
$processinglib = "<script src=\"$processingpath\" type=\"text/javascript\"></script>"; $processinglib = "<script src=\"$processingpath\" type=\"text/javascript\"></script>";
$first_edit = 1212192000; $first_edit = 1212192000;
$now = time(); $now = time();
// draw the timeline from the first edit to now() // draw the timeline from the first edit to now()
// get the list of edits of the current page // get the list of edits of the current page
// "get inspired" by PrintDiff() in scripts/pagerev.php // "get inspired" by PrintDiff() in scripts/pagerev.php
$canvaswidth = 600-2*10; $canvaswidth = 600-2*10;
$canvasheight = 10; $canvasheight = 10;
$block_width = 4; $block_width = 4;
$block_height = 8; $block_height = 8;
$page = ReadPage($pagename); $page = ReadPage($pagename);
if (!$page) return; if (!$page) return;
krsort($page); reset($page); krsort($page); reset($page);
// newest first // newest first
// for each edit // for each edit
$canvas = " $canvas = "
void setup() void setup()
{ {
size($canvaswidth, $canvasheight); size($canvaswidth, $canvasheight);
PFont font; PFont font;
font = loadFont(\"FFScala-Bold-12.vlw\"); font = loadFont(\"FFScala-Bold-12.vlw\");
textFont(font); textFont(font);
} }
void mouseMoved() { void mouseMoved() {
checkButtons(); checkButtons();
} }
void mouseDragged() { void mouseDragged() {
checkButtons(); checkButtons();
} }
void draw() void draw()
{ {
background(251); background(251);
fill(0,0,255,20); fill(0,0,255,20);
noStroke(); noStroke();
"; ";
$mousePressed = "void mousePressed() {"; $mousePressed = "void mousePressed() {";
$destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=diff#diff"; $destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=diff#diff";
$mousePressed .= "\t\tif (lastHovered>0) { link(\"$destination_link\"+lastHovered); }\n"; $mousePressed .= "\t\tif (lastHovered>0) { link(\"$destination_link\"+lastHovered); }\n";
$checkButtons = "void checkButtons() {"; $checkButtons = "void checkButtons() {";
print $processinglib.'<canvas data-src="'.$processingfile.'" width="'.$canvaswidth.'" height="'.$canvasheight.'"></canvas>'; print $processinglib.'<canvas data-src="'.$processingfile.'" width="'.$canvaswidth.'" height="'.$canvasheight.'"></canvas>';
// set to false to de-activate cache (practical for tests) // set to false to de-activate cache (practical for tests)
$newest_diff = true; $newest_diff = true;
//$newest_diff = false; //$newest_diff = false;
//$first_diff = true; //$first_diff = true;
foreach($page as $k=>$v) { foreach($page as $k=>$v) {
if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue; if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue;
$diff = $match[1]; $diff = $match[1];
$diffclass = $match[3]; $diffclass = $match[3];
if ($diffclass=='minor') if ($diffclass=='minor')
{ $canvas .= "\t\tfill(0,255,0,20);\n"; } { $canvas .= "\t\tfill(0,255,0,20);\n"; }
else else
{ $canvas .= "\t\tfill(0,0,255,20);\n"; } { $canvas .= "\t\tfill(0,0,255,20);\n"; }
//if ($first_diff) //if ($first_diff)
// { $canvas .= "\t\tfill(255,0,0,20);\n"; $first_diff = false;} // { $canvas .= "\t\tfill(255,0,0,20);\n"; $first_diff = false;}
$buttonname = "over".$diff."Button"; $buttonname = "over".$diff."Button";
//$bools .= "boolean $buttonname = false;\n"; //$bools .= "boolean $buttonname = false;\n";
if (file_exists($FarmD.$processingfile) && $newest_diff) if (file_exists($FarmD.$processingfile) && $newest_diff)
if ( filemtime($FarmD.$processingfile) > $diff) if ( filemtime($FarmD.$processingfile) > $diff)
return; return;
$newest_diff = false; $newest_diff = false;
// add a sightly transparent tick rectangle with its Unix timestamp link to the diff page // add a sightly transparent tick rectangle with its Unix timestamp link to the diff page
// the mouse over a certain edit should change its color // the mouse over a certain edit should change its color
// see http://processingjs.org/learning/basic/embeddedlinks // see http://processingjs.org/learning/basic/embeddedlinks
// or clicablerects.js via Pomax on :mozilla2/#processing.js (14/05/2011 ~11pm) // or clicablerects.js via Pomax on :mozilla2/#processing.js (14/05/2011 ~11pm)
$x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$diff)) / ($now - $first_edit))); $x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$diff)) / ($now - $first_edit)));
$y = 1; $y = 1;
$checkButtons .= "\t\tif ( mouseX > $x && mouseX < $x+$block_width) lastHovered = $diff; \n"; $checkButtons .= "\t\tif ( mouseX > $x && mouseX < $x+$block_width) lastHovered = $diff; \n";
// if (mouseY > $y && mouseY < $y+$block_height) not really required // if (mouseY > $y && mouseY < $y+$block_height) not really required
// others should be set to false else one always jump to the olded diff mouved over // others should be set to false else one always jump to the olded diff mouved over
$canvas .= "\t\trect($x,$y,$block_width,$block_height);\n"; $canvas .= "\t\trect($x,$y,$block_width,$block_height);\n";
} }
$canvas .= "\t\tstroke(0,155);\n"; $canvas .= "\t\tstroke(0,155);\n";
$canvas .= "\t\tfill(0,0,255,80);\n"; $canvas .= "\t\tfill(0,0,255,80);\n";
$canvas .= "\t\ttext(\"Edits:\",2,10 );\n"; $canvas .= "\t\ttext(\"Edits:\",2,10 );\n";
$canvas .= "\t\tfill(0,0,255,40);\n"; $canvas .= "\t\tfill(0,0,255,40);\n";
for ($year=2009;$year<2012;$year++){ //each year until now for ($year=2009;$year<2012;$year++){ //each year until now
$unixyear = mktime(0,0,0,1,1,$year); $unixyear = mktime(0,0,0,1,1,$year);
$x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$unixyear)) / ($now - $first_edit))); $x = round ( ($canvaswidth - $block_width) * ( (($now - $first_edit)-($now-$unixyear)) / ($now - $first_edit)));
$y = 0; $y = 0;
$canvas .= "line($x,$y,$x,$y+$block_height+2); text(\"$year\",$x+2,$y+10 );\n"; $canvas .= "line($x,$y,$x,$y+$block_height+2); text(\"$year\",$x+2,$y+10 );\n";
} }
$canvas = $bools . $canvas ."}" . $mousePressed ."}" .$checkButtons . "}"; $canvas = $bools . $canvas ."}" . $mousePressed ."}" .$checkButtons . "}";
// load ProcessinJS // load ProcessinJS
$write_result = file_put_contents($FarmD.$processingfile,$canvas); $write_result = file_put_contents($FarmD.$processingfile,$canvas);
// print resulting canvas // print resulting canvas
$older_gnuplot_version = "<div><center><img src=\"/pub/visualization/edits_per_page/{$pagename}.png\" alt=\"/pub/visualization/edits_per_page/{$pagename}.png\"/></br>(<a href=\"$ScriptUrl/Wiki/Visualization#timeline\">visualization details</a>).</center></div><hr />"; $older_gnuplot_version = "<div><center><img src=\"/pub/visualization/edits_per_page/{$pagename}.png\" alt=\"/pub/visualization/edits_per_page/{$pagename}.png\"/></br>(<a href=\"$ScriptUrl/Wiki/Visualization#timeline\">visualization details</a>).</center></div><hr />";
} }
// generated via e.g. // generated via e.g.
// P=ReadingNotes.TurtlesTermitesAndTrafficJams; grep ^text= $P | sed "s/%0a/\\n/g" | sed "s/[^a-zA-Z]/ /g" > $P.txt && espeak -f $P.txt -w $P.wav && oggenc $P.wav && rm $P.wav // P=ReadingNotes.TheThingsWeDo; grep ^text= $P | sed "s/%0a/\\n/g" | sed "s/[^a-zA-Z]/ /g" > $P.txt && espeak -f $P.txt -w ../pub/audio/$P.wav && oggenc ../pub/audio/$P.wav && rm ../pub/audio/$P.wav $P.txt
// note that the output could be improved by better parsing and exploring SSML/HTML support // note that the output could be improved by better parsing and exploring SSML/HTML support
// details on the HTML markup // details on the HTML markup
// https://developer.mozilla.org/en/HTML/Element/audio // https://developer.mozilla.org/en/HTML/Element/audio
// http://www.w3.org/TR/html5/video.html#attr-media-controls // http://www.w3.org/TR/html5/video.html#attr-media-controls
function DisplayAudio($pagename){ function DisplayAudio($pagename){
global $ScriptUrl, $PubDir, $FarmD; global $ScriptUrl, $PubDir, $FarmD;
$audiofile = $FarmD."/pub/audio/".$pagename.".ogg"; $audiofile = $FarmD."/pub/audio/".$pagename.".ogg";
$audiourl = $ScriptUrl."/pub/audio/".$pagename.".ogg"; $audiourl = $ScriptUrl."/pub/audio/".$pagename.".ogg";
if (file_exists($audiofile)) if (file_exists($audiofile))
print "<div width=\"100px\"><a name=\"audiodisplay\"> print "<div width=\"100px\"><a name=\"audiodisplay\">
<audio width=\"100\" controls=\"controls\" > <audio width=\"100\" controls=\"controls\" >
<source src=\"$audiourl\" type=\"audio/ogg\" /> <source src=\"$audiourl\" type=\"audio/ogg\" />
Your browser does not allow HTML5 audio.</audio> Your browser does not allow HTML5 audio.</audio>
</a></br>"; </a></br>";
print "Download the <a href=\"$audiourl\">audio file (ogg)</a> to play later.</div>"; print "Download the <a href=\"$audiourl\">audio file (ogg)</a> to play later.</div>";
} }
//display images with transparancy invertionnaly proportional to last time of update //display images with transparancy invertionnaly proportional to last time of update
// http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#VisualDecayOfInformation // http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#VisualDecayOfInformation
function DisplayDecay($pagename){ function DisplayDecay($pagename){
/* /*
consider consider
adding threshold adding threshold
not keeping it linear (e.g. log) not keeping it linear (e.g. log)
but still constantly inscreasing between 0 and 1 but still constantly inscreasing between 0 and 1
use a factor when matches (e.g. regex changing $impeding_factor or $first_edit) use a factor when matches (e.g. regex changing $impeding_factor or $first_edit)
regex would match groupname (e.g. "Person." with fast decay) or pagename or both (e.g. "Math" with slow decay) regex would match groupname (e.g. "Person." with fast decay) or pagename or both (e.g. "Math" with slow decay)
yellowish background, looking like old paper yellowish background, looking like old paper
...rest got deleted by a dumb rm... ...rest got deleted by a dumb rm...
*/ */
global $ScriptUrl; global $ScriptUrl;
$first_edit = 1212192000; $first_edit = 1212192000;
$now = time(); $now = time();
//load page //load page
$page = ReadPage($pagename); $page = ReadPage($pagename);
if (!$page) return; if (!$page) return;
$last_edit = $page["time"]; $last_edit = $page["time"];
//get last edit //get last edit
$destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=edit"; $destination_link = "$ScriptUrl/".strtr($pagename,".","/")."?action=edit";
//use the previous equation adding 1 - () //use the previous equation adding 1 - ()
$opacity = round ( 1 - ( (($now - $first_edit)-($now-$last_edit)) / ($now - $first_edit)) , 2 ); $opacity = round ( 1 - ( (($now - $first_edit)-($now-$last_edit)) / ($now - $first_edit)) , 2 );
$opacitymsg = "opacity=$opacity"; $opacitymsg = "opacity=$opacity";
if ($opacity > 0.8) if ($opacity > 0.8)
$opacitymsg = "<font color=\"red\">".$opacitymsg."</font>"; $opacitymsg = "<font color=\"red\">".$opacitymsg."</font>";
//if user if admin //if user if admin
if ( $GLOBALS['Author'] == 'Fabien' || $GLOBALS['Author'] == 'Utopiah' ) { if ( $GLOBALS['Author'] == 'Fabien' || $GLOBALS['Author'] == 'Utopiah' ) {
//for 1 to a multiplier of value //for 1 to a multiplier of value
for ($i=0;$i<$opacity*10;$i++){ for ($i=0;$i<$opacity*10;$i++){
// display another visual problem with a link back to improvingwiki#visualdecay // display another visual problem with a link back to improvingwiki#visualdecay
print "<div style=\"opacity:$opacity;position:absolute;top:".rand(60,800)."px;left:".rand(100,500)."px;\"><a href=\"$destination_link\">" print "<div style=\"opacity:$opacity;position:absolute;top:".rand(60,800)."px;left:".rand(100,500)."px;\"><a href=\"$destination_link\">"
.decbin(rand(0,10000))."</a></div>"; .decbin(rand(0,10000))."</a></div>";
} }
// add a good practice msg // add a good practice msg
print "<div style=\"opacity:$opacity;position:absolute;top:10px;left:450px;width:300px;background-color:gray;\"> print "<div style=\"opacity:$opacity;position:absolute;top:10px;left:450px;width:300px;background-color:gray;\">
$opacitymsg edits should be done to check if $opacitymsg edits should be done to check if
the informamtion presented is still relevant, the informamtion presented is still relevant,
links are working, links are working,
opinion expressed still correct, etc. opinion expressed still correct, etc.
</div>"; </div>";
} }
//print img with opacity + warning message //print img with opacity + warning message
print "<div style=\"opacity:$opacity;\"><a name=\"Decay\"></a>If you can read this text ($opacitymsg) if means the page has not been edited for a long time. Consequently the information it holds might be deprecated or no longer represent the opinion of this author.</div>"; print "<div style=\"opacity:$opacity;\"><a name=\"Decay\"></a>If you can read this text ($opacitymsg) if means the page has not been edited for a long time. Consequently the information it holds might be deprecated or no longer represent the opinion of this author.</div>";
} }

Loading…
Cancel
Save