How to use the chordsheetjs.ChordProFormatter function in chordsheetjs

To help you get started, we’ve selected a few chordsheetjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github martijnversluis / ChordFiddle / js / chord_pro_editor.js View on Github external
importChordSheet(chordSheet) {
    const song = new ChordSheetJS.ChordSheetParser().parse(chordSheet);
    this.editor.value = new ChordSheetJS.ChordProFormatter().format(song);
    this.onEditorChange();
  }
github artutra / OpenChord / app / containers / SongEdit.tsx View on Github external
function switchToChordPro() {
    let song = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: false }).parse(content)
    let chordPro = new ChordSheetJS.ChordProFormatter().format(song)
    setContent(chordPro)
    setMode('CHORD_PRO')
  }
  function switchToChordSheet() {
github martijnversluis / ChordFiddle / src / utils / chord_sheet_transformations.js View on Github external
export const convertChordSheetToChordPro = (chordSheet) => {
  const parser = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: false });
  const formatter = new ChordSheetJS.ChordProFormatter();
  const song = parser.parse(chordSheet);
  return formatter.format(song);
};
github artutra / OpenChord / app / containers / Config.tsx View on Github external
function seedSongDb() {
    for (var i = 0; i < allSongs.length; i++) {
      let s: string = allSongs[i]
      const parser = new ChordSheetJS.ChordProParser();
      const formatter = new ChordSheetJS.ChordProFormatter();
      const parsedSong = parser.parse(s);

      let artist = new Artist(parsedSong.getMetaData('artist')!)
      let song = new Song(parsedSong.getMetaData('title')!, formatter.format(parsedSong), artist)
      realm.write(() => {
        Song.create(song)
      })
    }
  }
  return (
github martijnversluis / ChordFiddle / js / chord_pro_editor.js View on Github external
(new TextareaSelection(this.editor)).replace(selection => {
      const song = new ChordSheetJS.ChordProParser().parse(selection);
      this.transitSong(song, processor);
      const transposedSong = new ChordSheetJS.ChordProFormatter().format(song);
      return transposedSong;
    });
github artutra / OpenChord / app / containers / SongEdit.tsx View on Github external
function saveSong() {
    if (title.trim() == '') return setError('Invalid Title')
    if (artist.trim() == '') return setError('Invalid Artist')
    if (content.trim() == '') return setError('Invalid content')
    let artistName = artist.trim()
    let songTitle = title.trim()
    let header =
      `{title: ${songTitle}}\n` +
      `{artist: ${artistName}}\n`
    let chordPro: string
    if (mode == 'CHORD_PRO') {
      chordPro = header + content
    } else {
      const formatter = new ChordSheetJS.ChordProFormatter();
      let chordSheetSong = new ChordSheetJS.ChordSheetParser({ preserveWhitespace: true }).parse(content)
      chordPro = header + formatter.format(chordSheetSong)
    }
    let songId = props.navigation.getParam('id')
    let artistDb: Artist | undefined = Artist.getByName(artistName)
    if (artistDb == null) {
      artistDb = Artist.create(artistName)
    }
    if (songId) {
      Song.update(songId, artistDb, songTitle, chordPro)
    } else {
      let song = Song.create(artistDb, songTitle, chordPro)
      songId = song.id
    }
    props.navigation.replace(ROUTES.SongView, { id: songId, title: songTitle })
  }
github artutra / OpenChord / app / db / Song.ts View on Github external
static populateDb() {
    if (this.shouldUpdateDb()) {
      for (var i = 0; i < allSongs.data.length; i++) {
        let s: string = allSongs.data[i]
        const parser = new ChordSheetJS.ChordProParser();
        const formatter = new ChordSheetJS.ChordProFormatter();
        const parsedSong = parser.parse(s);
        let artistName = parsedSong.getMetaData('artist')!
        let songTitle = parsedSong.getMetaData('title')!
        let songContent = formatter.format(parsedSong)

        let artist = Artist.create(artistName)
        Song.create(artist, songTitle, songContent)
      }
    }
  }
github martijnversluis / ChordFiddle / src / utils / chord_sheet_transformations.js View on Github external
const transformChordSheet = (chordSheet, processor) => {
  const song = new ChordSheetJS.ChordProParser().parse(chordSheet);
  const processedSong = transformSong(song, processor);
  return new ChordSheetJS.ChordProFormatter().format(processedSong);
};
github artutra / OpenChord / app / components / SongTransformer.tsx View on Github external
const processChord = (item: (ChordSheetJS.ChordLyricsPair | ChordSheetJS.Tag), processor: (parsedChord: Chord) => Chord) => {
  if (item instanceof ChordSheetJS.ChordLyricsPair) {
    if (item.chords) {
      const parsedChord = Chord.parse(item.chords);

      if (parsedChord) {
        const processedChordLyricsPair = item.clone();
        processedChordLyricsPair.chords = processor(parsedChord).toString();
        return processedChordLyricsPair;
      }
    }
  } else {
    if (item.name == 'comment' && item.value) {
      let commentSong = new ChordSheetJS.ChordProParser().parse(item.value)
      commentSong = transformSong(commentSong, processor);
      item.value = new ChordSheetJS.ChordProFormatter().format(commentSong)
    }
  }
  return item;
};

chordsheetjs

A JavaScript library for parsing and formatting chord sheets

GPL-2.0
Latest version published 2 months ago

Package Health Score

78 / 100
Full package analysis