Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Sep 30, 2020
0 parents commit 0529e1e
Show file tree
Hide file tree
Showing 16 changed files with 1,809 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_site
.DS_Store
*.swp
*.bak
js/local
style/local
Gemfile.lock
.jekyll-metadata
17 changes: 17 additions & 0 deletions .serve
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# You need to first install jekyll to run the website locally.
# See the webpage:
# https://jekyllrb.com/docs/installation
# https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll
# for instructions on installing it.
#
# To run from the comand line, type:
# ./.serve
#
# Then look for the address of the webserver, which should be:
# http://127.0.0.1:2000
#

bundle exec jekyll serve --watch --incremental

1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sheet.google.com
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem 'github-pages', group: :jekyll_plugins
26 changes: 26 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repository: "humdrum-tools/humdrum-sheet"

# the preview server used. Leave as is.
host: 127.0.0.1

# the port where the preview is rendered.
port: 2000

# these are the files and directories that jekyll will exclude from the build
exclude:
- .gitignore

highlighter: rouge
# library used for syntax highlighting

# filter used to process markdown. note that kramdown differs from
# github-flavored markdown in some subtle ways

markdown: kramdown
kramdown:
input: GFM
auto_ids: true
hard_wrap: false
syntax_highlighter: rouge


8 changes: 8 additions & 0 deletions _includes/code/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@



format:
for i in *.js; do echo Formatting $$i; clang-format -style=Google -i $$i; done



52 changes: 52 additions & 0 deletions _includes/code/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/////////////////////////////////////////////////////////////////////////////
//
// Spreadsheet event processing
//

//////////////////////////////
//
// onOpen -- function to run when loading the spreadsheet.
//

function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Humdrum')
.addItem('Escape barline rows', 'fixBarlineRows')
.addItem('Colorize data', 'recolorizeContents')
//.addSeparator()
.addSubMenu(
ui.createMenu('Add above current line')
.addItem('Interpretation line', 'addNullInterpretationLine')
.addItem('Local comment line', 'addNullCommentLine')
.addItem('Data line', 'addNullDataLine'))
.addToUi();
}



//////////////////////////////
//
// onEdit -- function to run when the spreadsheet changes.
//
// Example event:
//
// {
// "source": {},
// "authMode": "LIMITED",
// "oldValue": "!!!final: GGG",
// "user": {
// "email": "",
// "nickname": ""
// },
// "value": "!!!final: HHH",
// "range": {
// "columnEnd": 1,
// "columnStart": 1,
// "rowEnd": 16,
// "rowStart": 16
// }
// }

function onEdit(e) {
Logger.log('ONEDIT: ' + JSON.stringify(e, false, ' '));
}
20 changes: 20 additions & 0 deletions _includes/code/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Programmer: Craig Stuart Sapp ([email protected])
// Creation Date: 20 September 2020
// Last Modified: 28 September 2020
// URL: http://bit.ly/humdrum-io
//
// Description: Interface between Verovio Humdrum Viewer and Google
// Spreadsheets.
// The doPost() function receives data (nominally from VHV, but can
// be from any webpage). And doGet() will send the data as TSV
// content (typically after it has been edited in the spreadsheet).
//
// Documentation: https://doc.verovio.humdrum.org/interface/toolbar/spreadsheet
//
// To do: * Conditional formatting for colorizing data. colorizeData()
// currently does
// static colorizing.
// see:
// https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule
//
46 changes: 46 additions & 0 deletions _includes/code/input-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////
//
// Input/Output functions -- The doGet() function sends data and the doPost()
// receives data.
//

//////////////////////////////
//
// doGet -- send Humdrum data to a web page.
//

function doGet(e) {
// let ss =
// SpreadsheetApp.openById("1FIaXR2VrHwrvB7BAr90K79dwzKHH3HRht5Xa5p1mjnw");
let ss = SpreadsheetApp.getActive();
let sheet = ss.getActiveSheet();
let url = ss.getUrl();
let data = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns())
.getValues();
let text = convertDataArrayToTSV(data);
return ContentService.createTextOutput(text);
}



//////////////////////////////
//
// doPost -- receive Humdrum data from a web page.
//

function doPost(e) {
// let ss =
// SpreadsheetApp.openById("1FIaXR2VrHwrvB7BAr90K79dwzKHH3HRht5Xa5p1mjnw");
// let sheet = ss.getSheetByName("Sheet1");
let ss = SpreadsheetApp.getActive();
let sheet = ss.getActiveSheet();
let data = '';
if (e && e.parameter && e.parameter.humdrum) {
data = e.parameter.humdrum;
} else {
// Prepare a dummy score for testing:
data = '**kern\n*clefG2\n=1\n*^\n1c;\t1C;\n*v\t*v\n*test\n==\n*-\n';
}
fillSheetWithHumdrumData(sheet, data);
return ContentService.createTextOutput('FINISHED UPLOADING');
}
123 changes: 123 additions & 0 deletions _includes/code/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/////////////////////////////////////////////////////////////////////////////
//
// Menu related functions --
//

//////////////////////////////
//
// recolorizeContents -- Colorize Humdrum data. Currently only works
// on the first worksheet tab of the spreadsheet.
//

function recolorizeContents() {
let ss = SpreadsheetApp.getActive();
let sheet = ss.getActiveSheet();
let allRange = sheet.getDataRange();
let data = allRange.getValues();
if (data.length == 0) {
return;
}
let firstcolumn = getFirstColumn(data);
if (firstcolumn > 0) {
for (let i = 0; i < data.length; i++) {
data[i] = data[i].splice(0, firstcolumn);
}
}
sheet.clearFormats();
allRange.clearFormat();
colorizeData(sheet, data);
allRange.setShowHyperlink(false);
}



//////////////////////////////
//
// getFirstColumn -- Return the first non-IGNORE column
// in the data array.
//

function getFirstColumn(data) {
let output = 0;
for (let i = 0; i < data[0].length; i++) {
if (data[0][i].match(/^\s*IGNORE\s*$/)) {
continue;
}
output = i;
break;
}
return output;
}



//////////////////////////////
//
// fixBarlineRows -- Add single quotes in front of equal signs in the
// spreadsheet.
// Currently not dealing with IGNORE columns. Currently only works on the
// first worksheet of the spreadsheet. Checks the first column for lines
// that start with "=" or "'=" and then forces all contents on the line to be
// "'=".
//

function fixBarlineRows() {
let ss = SpreadsheetApp.getActive();
let sheet = ss.getActiveSheet();
let allRange = sheet.getDataRange();
let formulas = allRange.getFormulas();
let data = allRange.getValues();
if (data.length == 0) {
return;
}
for (let i = 0; i < data.length; i++) {
if (formulas[i][0]) {
data[i][0] = formulas[i][0];
}
if (!data[i][0].match(/^'?=/)) {
continue;
}
for (let j = 0; j < data[i].length; j++) {
if (formulas[i][j]) {
data[i][j] = formulas[i][j];
}
if (data[i][j].match(/^=/)) {
data[i][j] = '\'' + data[i][j];
}
}
}
allRange.setValues(data);
}



//////////////////////////////
//
// addNullInterpretationLine --
//

function addNullInterpretationLine() {
addNullLine('*');
}



//////////////////////////////
//
// addNullCommentLine --
//

function addNullCommentLine() {
addNullLine('!');
}



//////////////////////////////
//
// addNullDataLine --
//

function addNullDataLine() {
addNullLine('.');
}
Loading

0 comments on commit 0529e1e

Please sign in to comment.