How to use the pychord.Chord function in pychord

To help you get started, we’ve selected a few pychord 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 Miserlou / chords2midi / chords2midi / c2m.py View on Github external
progression = self.vargs['progression'][0].split(',')
            else:
                progression = self.vargs['progression']
        else:
            with open(self.vargs['input']) as fn:
                content = ''.join(fn.readlines()).strip()
                content = content.replace('\n', ' ').replace(',', '  ')
                progression = content.split(' ')
        og_progression = progression

        # If we're reversing, we don't need any of the MIDI stuff.
        if self.vargs['reverse']:
            result = ""
            key = self.vargs['key']
            for item in progression:
                comps = pychord.Chord(item).components()
                position = determine(comps, key, True)[0]
                if 'M' in position:
                    position = position.upper()
                    position = position.replace('M', '')
                if 'm' in position:
                    position = position.lower()
                    position = position.replace('m', '')
                if 'B' in position:
                    position = position + "b"
                    position = position.replace('B', '')

                result = result + position + " "
            print result
            return

        track    = 0
github erm / guitarlette / src / parser.py View on Github external
from typing import Optional, List
from dataclasses import dataclass, field


from pychord import Chord


@dataclass
class SongToken:
    content: str
    html_class: Optional[str] = None
    chord: Optional[Chord] = None

    def __post_init__(self) -> None:
        if self.content == "":
            self.html_class = "delimiter"
        else:
            try:
                self.chord = Chord(self.content.strip())
            except ValueError:
                pass
            else:
                self.html_class = "chord"

    def transpose(self, degree: int) -> None:
        if self.chord is None:
            raise ValueError("Transpose may only be called on chord tokens")
        assert self.chord is not None
github erm / guitarlette / src / song.py View on Github external
def render(self) -> str:
        s = self.content.strip().decode()
        if s == "":
            return f"<span class="delimiter"></span>"
        if s == "{$s}":
            return " "
        if s == "{$n}" and self.is_new_row:
            self.is_new_row = False
            return "<div class="row">"
        if s == "{$n}" and not self.is_new_row:
            self.is_new_row = True
            return "</div>"

        try:
            chord = Chord(s)
        except ValueError:
            return f"<span class="lyric">{s}</span>"

        if self.degree:
            chord.transpose(self.degree)
            s = str(chord)

        return f"<span class="chord">{s}</span>"
github Miserlou / chords2midi / chords2midi / c2m.py View on Github external
else:
                    pattern_mask_index = pattern_mask_index + 1
            progression = new_progression

        # We do this to allow blank spaces
        for chord in progression:

            # This is for # 'I', 'VI', etc
            progression_chord = to_chords(chord, key)
            if progression_chord != []:
                has_number = True

            # This is for 'C', 'Am', etc.
            if progression_chord == []:
                try:
                    progression_chord = [pychord.Chord(chord).components()]
                except Exception:
                    # This is an 'X' input
                    progression_chord = [None]

            chord_info = {}
            chord_info['notes'] = progression_chord[0]
            if has_number:
                chord_info['number'] = chord
            else:
                chord_info['name'] = chord

            if progression_chord[0]:
                chord_info['root'] = progression_chord[0][0]
            else:
                chord_info['root'] = None
            progression_chords.append(chord_info)
github erm / guitarlette / backend / project / parser.py View on Github external
def parse_token(self, token: str) -> Token:
        try:
            chord = Chord(token)
        except ValueError:
            return Token(content=token)
        else:
            if token not in self.chords:
                self.chords.append(token)
        return Token(content=token, chord=chord)
github erm / guitarlette / src / parser.py View on Github external
def __post_init__(self) -> None:
        if self.content == "":
            self.html_class = "delimiter"
        else:
            try:
                self.chord = Chord(self.content.strip())
            except ValueError:
                pass
            else:
                self.html_class = "chord"

pychord

A library to handle musical chords in python.

MIT
Latest version published 10 months ago

Package Health Score

56 / 100
Full package analysis

Popular pychord functions