Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto transposing does not work with a custom chord renderer #664

Open
no-chris opened this issue Sep 4, 2024 · 1 comment
Open

Auto transposing does not work with a custom chord renderer #664

no-chris opened this issue Sep 4, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@no-chris
Copy link
Owner

no-chris commented Sep 4, 2024

function CustomChords() {
    return function (chord) {
        chord.formatted.symbol = chord.formatted.symbol
            .replace('M7', 'maj7')
            .replace('M9', 'maj9');
        return chord;
    };
};
function generateRenderOptions(transposeValue, accidentalsType){
    let options = {};
    let rendererFactoryOptions = { // init
        customFilters: [
            CustomChords()
        ],       
        useShortNamings: true,
        simplify : 'none', 
        transposeValue : 0, 
        accidental : 'original',
        symbolType : 'chord',
        printer : "text"
    };

    // configure rendererFactory options
    rendererFactoryOptions.transposeValue = transposeValue;
    rendererFactoryOptions.accidental = accidentalsType == 'auto' ? 'original' : accidentalsType;
    
    // define chordSymbol renderer
    options.chordSymbolRenderer = chordSymbol.chordRendererFactory(rendererFactoryOptions);
    
    // set general options 
    options.transposeValue = transposeValue;
    options.accidentalsType = accidentalsType ? accidentalsType : "auto";
   
    return options
}
function renderSongChart(songChartCode, options){    
    const parsed = chordMark.parseSong(songChartCode);    
    const rendered = chordMark.renderSong(parsed, options);  
    return rendered;
}

calling renderSongChart(songChartCode, generateRenderOptions(0, "auto")); produces the following rendering of the chord-mark code from my previous post: (rendering issue + chords are not automatically transposed between the two verses)

<div class="cmSong">
   <p class="cmLine"><span class="cmKeyDeclaration">key: D</span></p>
   <div class="cmSection cmSection-Verse">
      <p class="cmLine"><span class="cmSectionLabel">Verse 1</span></p>
      <p class="cmLine"><span class="cmChordLine"><span class="cmBarSeparator">|</span><span class="cmChordSymbol">Dm7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">G7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">Cmaj7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">%</span>     <span class="cmBarSeparator">|</span></span></p>
      <p class="cmLine"><span class="cmLyricLine">The first verse is in the key of C</span></p>
      <p class="cmLine"><span class="cmEmptyLine">&nbsp;</span></p>
      <p class="cmLine"><span class="cmKeyDeclaration">key: G</span></p>    <!-- rendering issue?: should be outside of <div> -->
   </div>
   <div class="cmSection cmSection-Verse">
      <p class="cmLine"><span class="cmSectionLabel">Verse 2</span></p>
      <p class="cmLine cmLine--isFromAutoRepeatChords"><span class="cmChordLine"><span class="cmBarSeparator">|</span><span class="cmChordSymbol">Dm7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">G7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">Cmaj7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">%</span>     <span class="cmBarSeparator">|</span></span></p>
      <p class="cmLine"><span class="cmLyricLine">And the second one in the key of G!</span></p>
   </div>
</div>

if we comment out the line: // options.chordSymbolRenderer = chordSymbol.chordRendererFactory(rendererFactoryOptions); then this is the rendered result: (same rendering issue, but chords are transposed between the two verses)


<div class="cmSong">
   <p class="cmLine"><span class="cmKeyDeclaration">key: D</span></p>
   <div class="cmSection cmSection-Verse">
      <p class="cmLine"><span class="cmSectionLabel">Verse 1</span></p>
      <p class="cmLine"><span class="cmChordLine"><span class="cmBarSeparator">|</span><span class="cmChordSymbol">Dm7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">G7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">CM7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">%</span>     <span class="cmBarSeparator">|</span></span></p>
      <p class="cmLine"><span class="cmLyricLine">The first verse is in the key of C</span></p>
      <p class="cmLine"><span class="cmEmptyLine">&nbsp;</span></p>
      <p class="cmLine"><span class="cmKeyDeclaration">key: G</span></p>    <!-- rendering issue? -->
   </div>
   <div class="cmSection cmSection-Verse">
      <p class="cmLine"><span class="cmSectionLabel">Verse 2</span></p>
      <p class="cmLine cmLine--isFromAutoRepeatChords"><span class="cmChordLine"><span class="cmBarSeparator">|</span><span class="cmChordSymbol">Gm7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">C7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">FM7</span>     <span class="cmBarSeparator">|</span><span class="cmChordSymbol">%</span>     <span class="cmBarSeparator">|</span></span></p>
      <p class="cmLine"><span class="cmLyricLine">And the second one in the key of G!</span></p>
   </div>
</div>

Originally posted by @thecodeinventor in #660 (reply in thread)

@no-chris no-chris self-assigned this Sep 4, 2024
@no-chris no-chris added the bug Something isn't working label Sep 4, 2024
@no-chris
Copy link
Owner Author

no-chris commented Sep 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant