GithubHelp home page GithubHelp logo

martijnversluis / chordsheetjs Goto Github PK

View Code? Open in Web Editor NEW
289.0 8.0 49.0 5.47 MB

A JavaScript library for parsing and formatting ChordPro chord sheets

License: GNU General Public License v2.0

JavaScript 0.68% PEG.js 2.22% Shell 0.07% TypeScript 97.04%
javascript chords parsing chordpro chord-sheet typescript

chordsheetjs's People

Contributors

bkeepers avatar chrismbarr avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar donkeybear avatar isaiahdahl avatar jbree avatar martijnversluis avatar pinksynth avatar samumazzi avatar spiffylogic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chordsheetjs's Issues

Adding section class to words ending with colon

In a application I'm developing, I wanted to style certain parts of the chord sheet with addinional css. For example, if I'm writing:
Verse 1:
I wanted to recognize this as a class of section (in this example with a bold text property).

Resulting in this parsed sheet:

Verse 1:
This is my lyrics for verse one.

I'm using the table formatter, so for now I have this regex checking for words ending in colon, or colon followed by any number of whitespaces in html_table_formatter.js:

key: 'cell',
    value: function cell(cssClass, value) {
      // If word ends with colon (with or without whitespaces), add section class to td:
      const regex = /:\s*$/;
      if (regex.test(value)) {
        return '<td class="section">' + (0, _html_entities_encode2.default)(value) + '</td>';
      }
      // Else return original string value
      return '<td class="' + cssClass + '">' + (0, _html_entities_encode2.default)(value) + '</td>';
    }

Downside of this, is of course if any part of the lyrics itself contains colon and printing this as bold. You may have a better solution.

I also thought of checking for specific words like intro, verse, chorus, bridge, etc - but it would be a long list of possible section names.

Any inputs on this, or maybe it could be offered as a feature?

[Feature Request] Tab render

Any plans to include the start_of_tabs and end_of_tabs directives?
I am making an opensource app with this lib and would be really usefull if the Song class already supported this directive.
Currently I need it just for a better formating of tabs on screen.
This is the source code: https://github.com/artutra/OpenChord

Isolated CSS environment via Shadow DOM (generally, web components)

This will make CSS formatting easier, and not interfered from the outside.

A suggested CSS is

  .chord-sheet {
    .row {
      display: flex;
      flex-direction: row;
    }

    .column {
      display: flex;
      flex-direction: column;
      height: 100%;
    }

    .chord, .lyrics {
      flex-grow: 1;

      &::before {
        content: '\200b';
      }

      * + & {
        margin-left: 0.5em;
      }
    }
  }

Could you please publish a new version to NPM?

I'm interested in a feature that is in your master, but unreleased on NPM (namely, divs wrapping chorus paragraphs in the HTML table formatter). Are you planning to release a new version with those changes?

Types for TypeScript

I'd like to volunteer to submit a TypeScript .d.ts file for your project to DefinitelyTyped.

formatter is breaking lines

I am building a song library using gatsby. In my project, I have used a combination of ChordJs and ChordsheetJs. I am writing all the lyrics with chords in a Markdown file. Until now the output of a ChordPro sheet was as defined in the docs, but since last week I am experiencing a bug on adding a new lyrics MD file to the project.

To parse the file I use:
const [song] = useState(new ChordSheetJS.ChordProParser().parse(post.internal.content))

and to render the html output:
const htmlChordSheet = new ChordSheetJS.HtmlDivFormatter().format(song)

while using the HtmlDivFormatter() the HTML on the webpage now looks like this
divformatter

I tried replacing HtmlDivFormatter() with HtmlTableFormatter(), this solved the issue but raised another one. The spacing between paragraphs was no longer there.
The highlited area shows the end of a paragraph.
tableformatter

There is also issue with the regular chord sheet. On the webpage, chords move forward from their defined postion.

Expected output
expected_regular-sheets

output on webpage
output-on-page

[Feature request] Inline chords

What about a inline chord notation? Like:

Intro: [[C]] [[Am]]
[C]Som[G]e random lyrics

So it will be rendered this way:

Intro: C Am
C G
Some random lyrics

ChordProParser - whitespaces on the end of the line

When chordProParser parser this:

C                G              F  C/E Dm          C
Whisper words of wisdom, let it be

It is ignoring the whitespaces after the Dm chord and formating like this:

[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm] [C]

Shouldn't it format like this?

[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm]          [C]

[Feature Request] Transpose chords

How about adding a configuration to transpose all chords of the music?
This method should do the trick for each chord:

function transposeChord(chord, amount) {
    var scale = [["C"],
                 ["C#","Db"],
                 ["D"],
                 ["D#","Eb"],
                 ["E"],
                 ["F"],
                 ["F#","Gb"],
                 ["G"],
                 ["G#","Ab"],
                 ["A"],
                 ["A#","Bb"],
                 ["B"]];
    return chord.replace(/[CDEFGAB](#|b)?/g, function(match) {
        for (var i = scale.length - 1; i >= 0; i--) {
            if(scale[i].indexOf(match) != -1){
                var j = (i+amount) % scale.length;
                return scale[ j < 0 ? j + scale.length : j ][0];
            }
        }
    });
}

song::serialize

Hi, Great package! Thanks for it.

I have a use-case which is saving the parsed song to a db in JSON format so that I can index on meta data, eg. title, capo etc instead of saving in chordpro, parsing on the server and extracting out meta data into separate db fields.

I don't see a public method to do this. Am I missing something? It would be easy enough to serialize/deserialize just the static properties, but of course the methods would be problematic without some tinkering and/or using a third-party library. Thoughts? I'm happy to issue PRs if needed.

How to render metadata other than title and subtitle

I tried to add other metadata such as key and also to name the verse, but it seems it is not rendered.

Example song

{title: Let it be}
{subtitle: ChordSheetJS example version}
{key: C}

{start_of_verse: Verse 1}
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be
{end_of_verse}

{start_of_chorus}
[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm] [C]
{end_of_chorus}

Handle multiple chords on the same syllable

To begin with, thank you for this beautiful piece of software.

I was just playing on ChordFiddle here, and I have to encode a song where a single syllable is long enough to be covered by multiple chords.

[A][B][C]Multi[A]ple

I finally handled it this way to make it readable:

[A]Mu [B]--- [C]- lti[A]ple

Is there something that can be done in the library to make this (edge?) case handled ? It seems to me a bit difficult, because it'd be needed to make chordsheetjs kind of syllable-aware...

Not recognizing package

I'm now getting an error in my code

 ERROR  Failed to compile with 1 errors                                                                               

This dependency was not found:

* chordsheetjs in ./src/pages/index.js

To install it, you can run: npm install --save chordsheetjs                                                                                                

This is after I've installed ChordSheetJS; I can see it in the node_modules folder.

It looks like the /lib folder is missing from the npm package

ChordSheetJS.ChordSheetParser is not a constructor

I try to execute it with a basic typescript file as follows:

  1. tsc --init
  2. npm install chordsheetjs
  3. create a file app.ts with :

var ChordSheetJS = require('chordsheetjs'); const parser = new ChordSheetJS.ChordSheetParser();

  1. In order to allow the 'require' function :
    npm install @types/node --save

  2. Compile the typescript with success:
    tsc

6)Execute with:
node app.js

ERROR: ChordSheetJS.ChordSheetParser is not a constructor

May you put an example to test your library? Thank you.

Fix linting

  • allow running Eslint locally by adding the necessary modules and scripts to package.json
  • add .eslintignore
  • re-enable import/prefer-default-export and no-unused-expressions
  • remove legacy Hound config files

Use in Angular

Hi, I would like use your library in Angular:

  1. npm install chordsheetjs --save
  2. import { ChordSheetJS } from 'chordsheetjs'; //in my component

Error:
Could not find a declaration file for module 'chordsheetjs'.
'd:/xxxx/node_modules/chordsheetjs/lib/chordsheet.js' implicitly has an 'any' type.
Try npm install @types/chordsheetjs if it exists or add a new declaration (.d.ts) file containing `declare module 'chordsheetjs';

Can you give me an idea?

HtmlFormatter - Responsive html chord

How about an option to allow the htmlFormatter to render chord pro
from this:

Some r[C]andom lyrics

to this:

<p>Some r<div class="chord">C</div>andom lyrics</p>

So it would be possible to use css to make a responsive design like this
cresponsivity2
ps: Ignore the tablature

Exceptions while parsing meta tags

When using chord pro format, it would be great to handle a custom exception when it is not possible to parse a meta tag.
For example, the user may write (incorrectly) something like:
{ title: Let it be}

(Note the ' ' before title)

Add ChordProFormatter

In order to perform transformations like modulations there should be a ChordProFormatter to convert a edited song back to ChordPro format.

[Bug] Ultimate Guitar tab to Chordsheet gives too much spaces in chord names

Hello. I use this program to convert ultimate guitar tabs to chordsheets but it gives a weird output for chords.
Example (https://tabs.ultimate-guitar.com/tab/ajj-andrew-jackson-jihad/normalization-blues-chords-2953307):

E
I'm detached and I'm distracted
E
All keyed up and unproductive
E
Vacillating between being all excited and disgusted
A
And then dozing lackadaisically
A                                       E
In this bubble where I've made my mental home
 B7                                 A
Connection's more important now than it ever was
                    E
But I'd rather be alone

Gives

[E]I'm detached and I'm distracted
[E]All keyed up and unproductive
[E]Vacillating between being all excited and disgusted
[A]And then dozing lackadaisically
[A                                      ]In this bubble where I've made my mental[E]home
C[B7                                ]onnection's more important now than[A]it ever was
[                   ]But I'd rather be al[E]one

Notice the spaces in the chord names

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.