ChordProParser

actor ChordProParser

The ChordPro file parser

  • A dictionary with optional arguments for a directive

    Declaration

    Swift

    typealias Arguments = [ChordPro.Directive.FormattingAttribute: String]

Parse a ‘ChordPro’ file

  • Parse a ChordPro file

    Declaration

    Swift

    static func parse(
        id: UUID,
        text: String,
        transpose: Int,
        settings: AppSettings.Song,
        fileURL: URL?
    ) async -> Song

    Parameters

    id

    The ID of the song

    text

    The text of the file

    transpose

    The optional transpose of the song in the GUI

    settings

    The settings for the song

    fileURL

    The optional file url of the song

    Return Value

    A Song item

  • Add a complete section with a single directive in a line

    Declaration

    Swift

    static func addSection(
        source: String? = nil,
        sectionLabel: String? = nil,
        directive: ChordPro.Directive,
        arguments: Arguments,
        environment: ChordPro.Environment = .metadata,
        currentSection: inout Song.Section,
        song: inout Song
    )

    Parameters

    source

    The optional source of the line; else it will be calculated

    sectionLabel

    The optional override of the section label

    directive

    The Directive to add to the line

    arguments

    The optional arguments for the directive

    environment

    The optional environment for the section; defaults to ‘metadata`

    currentSection

    The current Section

    song

    The whole Song

  • Convert arguments to a single string

    Declaration

    Swift

    static func argumentsToString(_ arguments: ChordProParser.Arguments) -> String?

    Parameters

    arguments

    The arguments dictionary

    Return Value

    A single string with arguments

  • Convert an argument string into arguments

    Declaration

    Swift

    static func stringToArguments(_ parsedArgument: String?, currentSection: inout Song.Section) -> ChordProParser.Arguments

    Parameters

    parsedArgument

    The parsed argument string

    currentSection

    The current section of the song; this is to add optional warnings

    Return Value

    The arguments in a dictionary

  • Create an automatic section in the Song

    Declaration

    Swift

    static func autoSection(
        environment: ChordPro.Environment,
        currentSection: inout Song.Section,
        song: inout Song
    ) -> String

    Parameters

    environment

    The Environment of the section

    currentSection

    The current Section

    song

    The whole Song

    Return Value

    A warning as String

  • Close a section in the song

    Note

    This will open a new empty section as well

    Declaration

    Swift

    static func closeSection(
        currentSection: inout Song.Section,
        song: inout Song
    )

    Parameters

    currentSection

    The current Section

    song

    The whole Song

  • Get the full URL of an image

    Declaration

    Swift

    static func getImageURL( _ source: String, fileURL: URL?) -> URL?

    Parameters

    source

    The image source as defined in the song

    fileURL

    The optional URL of the song file

    Return Value

    An optional URL of the image

  • Get the size of an image

    Declaration

    Swift

    static func getImageSize(image: NSImage, arguments: Arguments?) -> CGSize

    Parameters

    image

    The NSImage

    arguments

    The arguments of the image in the song

    Return Value

    The CGSize of the image

  • Get the offset of a ChordPro directive

    Declaration

    Swift

    static func getOffset(_ arguments: ChordProParser.Arguments?) -> CGSize

    Parameters

    arguments

    The arguments of the directive in the song

    Return Value

    The offset as CGSize

  • Open a new section in the song

    Declaration

    Swift

    static func openSection(
        directive: ChordPro.Directive,
        arguments: Arguments,
        currentSection: inout Song.Section,
        song: inout Song
    )

    Parameters

    directive

    The Directive to add to the line

    arguments

    The optional arguments for the directive

    currentSection

    The current Section

    song

    The whole Song

Process a chord

Process a chord definition

Process a directive

Process a grid environment

Process a line

Process a strum environment

Process a tab environment

Debug stuff

  • Encode a struct

    Declaration

    Swift

    static func encode<T: Codable>(_ value: T) -> String

    Parameters

    value

    The struct

    Return Value

    A JSON string

  • Decode a JSON encoded Song

    Declaration

    Swift

    static func decode(_ string: String)

    Parameters

    string

    The Song as JSON string