sscore.h

Includes:
"sscore_graphics.h"
<stdbool.h>

Introduction

The base C interface to SeeScoreLib

This interface provides functions to read a MusicXML file and create a score layout consisting of a set of systems to be displayed one above the next.

Important Types:

  • sscore (opaque) defines the whole score.

  • sscore_system (opaque) defines a single system with 1 or more parts, and a range of bars. Reference-counted

  • sscore_systemlist (opaque) is convenient (not required) for handling a set of systems

  • sscore_libkeytype is defined in a key file, either evaluation_key.c which is supplied with the SDK or a special key file provided by Dolphin Computing for a fee to unlock specific features and remove the 'watermark'

Important Functions:

  • sscore_getversion() return the version number of the library

  • sscore_loadxmlfile loads a MusicXML file (.xml or .mxl) and returns type sscore*

  • sscore_loadxmldata loads in-memory MusicXML text data and returns type sscore*. It will read .mxl data if sscore_loadoptions.compressed is set

  • sscore_dispose releases the memory allocated in the sscore*

  • sscore_numparts returns the total number of parts available in the score.

  • sscore_numbars returns the total number of bars (measures) in the score

  • sscore_getheader returns information in the MusicXML header - title, composer etc

  • sscore_layout1system returns a single part sscore_system, useful for displaying the first few bars of a part (eg for part selection UI)

  • sscore_layout lays out all systems in the entire score. Since this function takes appreciable time for a large score it is designed to be called on a background thread, with regular updates to the UI for each new complete system using sscore_layout_callback_fn, which is passed as an argument. Sample code is provided with the SDK to demonstrate the thread handling.

  • sscore_system_retain, sscore_system_release used to increment and decrement the reference-count for a sscore_system, which is automatically disposed when the reference count becomes 0

  • sscore_system_index the index of the system

  • sscore_system_numbars returns the start bar index and the number of bars in a system.

  • sscore_system_bounds returns the (width,height) of the system

  • sscore_system_draw draws the system

  • sscore_system_getcursorrect return the rectangle for a particular bar in a system which can be used for drawing a rectangular bar cursor

  • sscore_system_partindexforypos() and sscore_system_barindexforxpos() can be used to identify the location of a tap or mouse in a system

  • sscore_systemlist_create, sscore_systemlist_dispose,sscore_systemlist_clear, sscore_systemlist_size, sscore_systemlist_add,sscore_systemlist_at, sscore_systemlist_bounds,sscore_systemlist_sysforbar various convenient functions provided for handling sscore_systemlist

  • sscore_compressxml, sscore_decompressxml are convenience functions for converting between .xml and .mxl files

Coordinates: In all coordinates x increases to the left and y increases downwards

Bar indices: The first bar in the score has always index 0, and the bars are indexed sequentially to the end.

System indices: The top system has index 0, and other systems are indexed sequentially downwards.

Thread Info: All functions in this interface must be called from a single thread (probably the main thread) EXCEPT for sscore_layout.
NB The callback function sscore_layout_callback_fn is called on the same thread as sscore_layout, but it must still call other functions in this interface in the normal thread



C Pseudoclasses

sscore

the score

sscore_system

a single laid out system with all parts and a number of bars

sscore_systemlist

the list of systems



Groups

The sscore_systemlist interface

functions to access a simple list of system

Group members:

sscore_systemlist_add

add a system to the end of ss

sscore_systemlist_at

get a system by index

sscore_systemlist_bounds

return the bounds of the score

sscore_systemlist_clear

clear all sytems from the list

sscore_systemlist_create

create a new sscore_systemlist

sscore_systemlist_defaultspacing

return the default inter-system spacing

sscore_systemlist_dispose

clear all systems from the list and dispose it

sscore_systemlist_size

return the number of systems held in ss

sscore_systemlist_sysforbar

return the system index for the bar index in the systemlist

 

The main sscore interface

obtain information about the score

Group members:

sscore_abbrevpartnameforpart

return the abbreviated partname for the part

sscore_dispose

free the score memory, and any undisposed systems

sscore_fullpartnameforpart

return the partname for the part

sscore_getheader

get the xml score-header information

sscore_layout

layout a set of systems and return them through a callback function

sscore_layout1system

layout a single system with a single part.

sscore_loadxmldata

load in-memory xml or mxl data and return score

sscore_loadxmlfile

load xml or mxl file and return score

sscore_numbars

return the total number of bars in the score

sscore_numparts

return the number of parts in the score

 

General utility Functions

Group members:

sscore_compressxml

convert xml file to mxl

sscore_decompressmxl

convert mxl file to xml

sscore_getversion

return the version number of the library

 

The sscore_system interface

functions accessing the system - a range of bars and parts to display in a rectangle

Group members:

sscore_system_barindexforxpos

return the bar index for a x-coord in the system

sscore_system_bounds

return the bounding box of the system

sscore_system_defaultspacing

return a default system spacing

sscore_system_draw

draw the system at the given point

sscore_system_getcursorrect

return the cursor rectangle for a particular system and bar

sscore_system_index

return the index (from the top of the score) of the system

sscore_system_numbars

return the start bar index and number of bars for the given system

sscore_system_partindexforypos

return the part index for a y-coord in the system

sscore_system_release

decrement the retain count of the system

sscore_system_retain

increment the retain count of the system


Functions

sscore_abbrevpartnameforpart

return the abbreviated partname for the part

sscore_compressxml

convert xml file to mxl

sscore_decompressmxl

convert mxl file to xml

sscore_dispose

free the score memory, and any undisposed systems

sscore_fullpartnameforpart

return the partname for the part

sscore_getheader

get the xml score-header information

sscore_getversion

return the version number of the library

sscore_layout

layout a set of systems and return them through a callback function

sscore_layout1system

layout a single system with a single part.

sscore_loadxmldata

load in-memory xml or mxl data and return score

sscore_loadxmlfile

load xml or mxl file and return score

sscore_numbars

return the total number of bars in the score

sscore_numparts

return the number of parts in the score

sscore_system_barindexforxpos

return the bar index for a x-coord in the system

sscore_system_bounds

return the bounding box of the system

sscore_system_defaultspacing

return a default system spacing

sscore_system_draw

draw the system at the given point

sscore_system_getcursorrect

return the cursor rectangle for a particular system and bar

sscore_system_index

return the index (from the top of the score) of the system

sscore_system_numbars

return the start bar index and number of bars for the given system

sscore_system_partindexforypos

return the part index for a y-coord in the system

sscore_system_release

decrement the retain count of the system

sscore_system_retain

increment the retain count of the system

sscore_systemlist_add

add a system to the end of ss

sscore_systemlist_at

get a system by index

sscore_systemlist_bounds

return the bounds of the score

sscore_systemlist_clear

clear all sytems from the list

sscore_systemlist_create

create a new sscore_systemlist

sscore_systemlist_defaultspacing

return the default inter-system spacing

sscore_systemlist_dispose

clear all systems from the list and dispose it

sscore_systemlist_size

return the number of systems held in ss

sscore_systemlist_sysforbar

return the system index for the bar index in the systemlist

sscore_unionrect

return the union of 2 rectangles


sscore_abbrevpartnameforpart


return the abbreviated partname for the part

EXPORT const char *sscore_abbrevpartnameforpart(
    const sscore *sc,
    int partindex);  
Parameters
sc

the sscore pointer returned from sscore_load*

partindex

the index of the part [0..numparts-1]

Return Value

pointer to char NULL-terminated C-style string


sscore_compressxml


convert xml file to mxl

EXPORT bool sscore_compressxml(
    const char *xmlfilepath,
    const char *dest_path,
    char *mxlfilename,
    int fnsize);  
Parameters
xmlfilepath

the full pathname for the xml source file

dest_path

the full pathname for the directory to receive the file to be created

mxlfilename

a buffer of size fnsize to receive the filename of the new file

fnsize

the size of the mxlfilename buffer

Return Value

true if success


sscore_decompressmxl


convert mxl file to xml

EXPORT bool sscore_decompressmxl(
    const char *mxlfilepath,
    const char *dest_path,
    char *xmlfilename,
    int fnsize);  
Parameters
mxlfilepath

the full pathname for the mxl source file

dest_path

the full pathname for the directory to receive the file to be created

xmlfilename

a buffer of size fnsize to receive the filename of the new file

fnsize

the size of the xmlfilename buffer

Return Value

return true if success


sscore_dispose


free the score memory, and any undisposed systems

EXPORT void sscore_dispose(
    sscore *sc);  
Parameters
sc

the sscore pointer returned from sscore_load*


sscore_fullpartnameforpart


return the partname for the part

EXPORT const char *sscore_fullpartnameforpart(
    const sscore *sc,
    int partindex);  
Parameters
sc

the sscore pointer returned from sscore_load*

partindex

the index of the part [0..numparts-1]

Return Value

pointer to char NULL-terminated C-style string


sscore_getheader


get the xml score-header information

EXPORT void sscore_getheader(
    const sscore *sc,
    sscore_header *header);  
Parameters
sc

the sscore pointer returned from sscore_load*

header

pointer to a struct of type sscore_header to receive the data

Discussion

NB The returned pointers inside header are owned by sc. The caller should copy any required data


sscore_getversion


return the version number of the library


sscore_layout


layout a set of systems and return them through a callback function

EXPORT enum sscore_error sscore_layout(
    sscore *sc,
    sscore_graphics *graphics, 
    float width,
    float max_system_height, 
    const bool *parts, 
    sscore_layout_callback_fn cb,
    void *arg, 
    float magnification, 
    const sscore_layoutoptions *opt);  
Parameters
sc

the sscore pointer returned from sscore_load*

graphics

the sscore_graphics returned from sscore_graphics_create or sscore_graphics_create_from_bitmap is used to measure bounds of items, particularly text.

width

the width available to display the systems in screen coordinates

max_system_height

the maximum height available to display each system to control truncation. =0 for no truncation

parts

array of bool, 1 per part, true to include, false to exclude

cb

the callback function to be called for each completed system

arg

the context argument to be passed to cb

magnification

the scale at which to display this (1.0 is default)

opt

pointer to options or NULL for default

Return Value

any error

Discussion

This should be called on a background thread and it will call cb for each system laid out, from top to bottom. cb will normally add the system to a sscore_systemlist on the foreground (gui event dispatch) thread. systems are stored in sc as they are produced


sscore_layout1system


layout a single system with a single part.

EXPORT sscore_system *sscore_layout1system(
    sscore *sc,
    sscore_graphics *graphics, 
    int startbarindex,
    float width,
    float max_height, 
    int partindex,
    float magnification);  
Parameters
sc

the sscore pointer returned from sscore_load*

graphics

the sscore_graphics returned from sscore_graphics_create or sscore_graphics_create_from_bitmap is used to measure bounds of items, particularly text.

startbarindex

the index of the first bar in the system (usually 0)

width

the width available to display the system in screen coordinates

max_height

the maximum height available to display the system to control truncation. =0 for no truncation

partindex

the index of the single part to layout [0..numparts-1]

magnification

the scale at which to display this (1.0 is default)

Return Value

the system

Discussion

useful for display of a single part for part selection


sscore_loadxmldata


load in-memory xml or mxl data and return score

EXPORT sscore *sscore_loadxmldata(
    const char *data,
    int len, 
    const sscore_loadoptions *opt, 
    sscore_loaderror *err);  
Parameters
data

a pointer to the data in memory

len

the number of bytes of data

opt

the options for load, or NULL for default options

err

pointer to a struct to take error (and warning) information. May be NULL if info not required


sscore_loadxmlfile


load xml or mxl file and return score

EXPORT sscore *sscore_loadxmlfile(
    const char *filepath, 
    const sscore_loadoptions *opt, 
    sscore_loaderror *err);  
Parameters
filepath

the full pathname of the file

opt

the options for load, or NULL for default options

err

pointer to a struct to take error (and warning) information. May be NULL if info not required


sscore_numbars


return the total number of bars in the score

EXPORT int sscore_numbars(
    const sscore *sc);  
Parameters
sc

the sscore pointer returned from sscore_load*

Return Value

the number of bars in the score


sscore_numparts


return the number of parts in the score

EXPORT int sscore_numparts(
    const sscore *sc);  
Parameters
sc

the sscore pointer returned from sscore_load*

Return Value

the number of parts in the score


sscore_system_barindexforxpos


return the bar index for a x-coord in the system

EXPORT int sscore_system_barindexforxpos(
    const sscore_system *sys,
    float xpos);  
Parameters
sys

the system

xpos

the x coord

Return Value

the bar index in the system containing this x coord, or -1 if outside the system


sscore_system_bounds


return the bounding box of the system

Parameters
sys

the system

Return Value

the size of the system


sscore_system_defaultspacing


return a default system spacing

EXPORT float sscore_system_defaultspacing(
    const sscore_system *sys);  
Parameters
sys

the system

Return Value

the default inter-system spacing


sscore_system_draw


draw the system at the given point

EXPORT void sscore_system_draw(
    sscore_graphics *graphics,
    const sscore_system *sys,
    const sscore_point *tl,
    float magnification);  
Parameters
graphics

the graphics context returned from sscore_graphics_create

sys

the system to draw

tl

the top left point of the system rectangle

magnification

the scale to draw at. NB This is normally 1, except during active zooming. The overall magnification is set in sscore_layout


sscore_system_getcursorrect


return the cursor rectangle for a particular system and bar

EXPORT sscore_cursor sscore_system_getcursorrect(
    sscore_graphics *graphics,
    const sscore_system *sys,
    int barIndex);  
Parameters
graphics

the graphics context returned from sscore_graphics_create

sys

the system

barIndex

the index of the bar in the system

Return Value

the cursor info


sscore_system_index


return the index (from the top of the score) of the system

EXPORT int sscore_system_index(
    const sscore_system *sys);  
Parameters
sys

the system

Return Value

the index of the system


sscore_system_numbars


return the start bar index and number of bars for the given system

Parameters
sys

the system

Return Value

the start bar and number of bars in the system


sscore_system_partindexforypos


return the part index for a y-coord in the system

EXPORT int sscore_system_partindexforypos(
    const sscore_system *sys,
    float ypos);  
Parameters
sys

the system

ypos

the y coord

Return Value

the part index in the system containing this y coord


sscore_system_release


decrement the retain count of the system

EXPORT void sscore_system_release(
    sscore *sc,
    sscore_system *sys);  
Parameters
sc

the sscore pointer returned from sscore_load*

sys

the system to be retained

Discussion

The caller must release the system when it release its pointer


sscore_system_retain


increment the retain count of the system

EXPORT void sscore_system_retain(
    sscore *sc,
    sscore_system *sys);  
Parameters
sc

the sscore pointer returned from sscore_load*

sys

the system to be retained

Discussion

The caller must retain the system when it stores its pointer


sscore_systemlist_add


add a system to the end of ss

Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

sys

the system to add to ss

Discussion

usually called from sscore_layout_callback_fn. sys retain count is incremented


sscore_systemlist_at


get a system by index

EXPORT sscore_system *sscore_systemlist_at(
    const sscore_systemlist *ss,
    int sysindex);  
Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

sysindex

the index of the system (usually from the top of the score)

Return Value

the system in the systemlist indexed by sysindex (indexed in order of add)


sscore_systemlist_bounds


return the bounds of the score

EXPORT sscore_size sscore_systemlist_bounds(
    const sscore_systemlist *ss, 
    float systemspacing);  
Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

systemspacing

the spacing between systems (0 = use default)

Return Value

the (width,height) of the score with the given systemspacing


sscore_systemlist_clear


clear all sytems from the list

Parameters
sc

the score

ss

the sscore_systemlist returned from sscore_systemlist_create


sscore_systemlist_create


create a new sscore_systemlist

Return Value

the new sscore_systemlist

Discussion

the returned value should be disposed with sscore_systemlist_dispose


sscore_systemlist_defaultspacing


return the default inter-system spacing

Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

Return Value

the default inter-system spacing


sscore_systemlist_dispose


clear all systems from the list and dispose it

Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

Discussion

If any system is still retained (may need to await completion on other threads) it will be deleted on disposal of sscore


sscore_systemlist_size


return the number of systems held in ss

EXPORT int sscore_systemlist_size(
    const sscore_systemlist *ss);  
Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

Return Value

the number of systems held in ss


sscore_systemlist_sysforbar


return the system index for the bar index in the systemlist

EXPORT int sscore_systemlist_sysforbar(
    const sscore_systemlist *ss,
    int barindex);  
Parameters
ss

the sscore_systemlist returned from sscore_systemlist_create

barindex

the index of the bar in the system

Return Value

return the system index for the bar index, or -1 if barindex invalid


sscore_unionrect


return the union of 2 rectangles

EXPORT sscore_rect sscore_unionrect(
    const sscore_rect *r1,
    const sscore_rect *r2);  
Parameters
r1

a rectangle

r2

a rectangle

Return Value

the rectangular union of r1 and r2


Typedefs

sscore_barrange

the range of bars in a system from sscore_system_numbars

sscore_colour

a colour

sscore_colour_alpha

a colour with alpha (opacity)

sscore_cursor

information about the cursor from sscore_system_getcursorrect

sscore_header

information in the score-header element of the xml file

sscore_item_handle

a unique handle for an item (note,rest,clef etc) in the score

sscore_key

a key obtained from Dolphin Computing for unlocking the SeeScoreLib capabilities

sscore_layout_callback_fn

The type of a callback called from sscore_layout

sscore_layoutoptions

options for sscore_layout

sscore_libkeytype

a key obtained from Dolphin Computing for unlocking the SeeScoreLib capabilities

sscore_loaderror

a description of any error or warnings from sscore_load

sscore_loadoptions

options for sscore_load

sscore_point

a point

sscore_rect

coords for a rectangle

sscore_size

a size

sscore_timesig

a conventional time signature

sscore_version

a version number


sscore_barrange


the range of bars in a system from sscore_system_numbars

typedef struct sscore_barrange { 
    int startbarindex; 
    int numbars; 
}sscore_barrange;  

sscore_colour


a colour

typedef struct sscore_colour { 
    float r,g,b; 
} sscore_colour;  

sscore_colour_alpha


a colour with alpha (opacity)

typedef struct sscore_colour_alpha { 
    float r,g,b,a; 
} sscore_colour_alpha;  

sscore_cursor


information about the cursor from sscore_system_getcursorrect

typedef struct sscore_cursor { 
    bool bar_in_system; 
    sscore_rect rect; 
} sscore_cursor;  

sscore_header


information in the score-header element of the xml file

typedef struct sscore_header { 
    const char *work_number; 
    const char *work_title; 
    const char *movement_number; 
    const char *movement_title; 
    const char *composer; 
    const char *lyricist; 
    const char *arranger;  
    int num_credits; 
    const char *credit_words[sscore_kMaxCredits];  
    int num_parts; 
    struct { 
        const char *name; 
        const char *abbrev; 
        } parts[sscore_kMaxParts];  
}sscore_header;  
Discussion

all are null-terminated c-style strings or 0


sscore_item_handle


a unique handle for an item (note,rest,clef etc) in the score

typedef unsigned long sscore_item_handle;  

sscore_key


a key obtained from Dolphin Computing for unlocking the SeeScoreLib capabilities

typedef struct sscore_libkeytype { 
    const char *identity; // C-style string associated with the application using the SeeScoreLib 
    unsigned capabilities[sscore_kNumCapabilityWords]; // encoded capabilities for this identity 
    unsigned key[sscore_kNumKeyWords]; // key associated with identity and capabilities 
} sscore_libkeytype;  

See Also


sscore_layout_callback_fn


The type of a callback called from sscore_layout

typedef bool ( *sscore_layout_callback_fn)(
    sscore_system *sys,
    void *arg);  
Parameters
sys

the system laid out

arg

the context argument passed to sscore_layout

Discussion

The callback is called by sscore_layout on a background thread for each system when it is laid out. This allows the ui to update while the layout is in progress The callback returns false to abort the layout, else true.


sscore_layoutoptions


options for sscore_layout

typedef struct sscore_layoutoptions { 
    bool hidepartnames; // set this so that part names are not displayed in the layout 
    bool hidebarnumbers; // set this so that bar numbers are not displayed 
    unsigned flags; // bit flags defined in enum sscore_layoutOptionsFlagBits. default set 0. 
    unsigned dummy[15]; // for future. set to zero 
} sscore_layoutoptions;  
Discussion

sscore_layoutoptions


sscore_libkeytype


a key obtained from Dolphin Computing for unlocking the SeeScoreLib capabilities

typedef struct sscore_libkeytype { 
    const char *identity; // C-style string associated with the application using the SeeScoreLib 
    unsigned capabilities[sscore_kNumCapabilityWords]; // encoded capabilities for this identity 
    unsigned key[sscore_kNumKeyWords]; // key associated with identity and capabilities 
} sscore_libkeytype;  

See Also


sscore_loaderror


a description of any error or warnings from sscore_load

typedef struct sscore_loaderror { 
    enum sscore_error err; // any error on load  
    int line; // line in the xml file of the (first) error (0 if none) 
    int col; // file column in the line (0 if none) 
    char text[sscore_kMaxErrorTextChars]; // any more information on the error  
    int numwarnings; // the number of warnings 
    struct { 
        enum sscore_warning w; // a warning value 
        unsigned dummy[4]; // for future 
        } warn[sscore_kMaxWarnings]; // any warnings on load  
    unsigned dummy[16]; // for future 
} sscore_loaderror;  

sscore_loadoptions


options for sscore_load

typedef struct sscore_loadoptions { 
    const sscore_libkeytype *key; // use NULL for evaluation of SeeScoreLib 
    bool compressed; 
    unsigned dummy[16]; // for future. set to zero 
} sscore_loadoptions;  

sscore_point


a point

typedef struct sscore_point { 
    float x,y; 
} sscore_point;  

sscore_rect


coords for a rectangle

typedef struct sscore_rect { 
    float xorigin,yorigin,width,height; 
} sscore_rect;  

sscore_size


a size

typedef struct sscore_size { 
    float width,height; 
} sscore_size;  

sscore_timesig


a conventional time signature

typedef struct sscore_timesig { 
    int numbeats; // number of beats in bar 
    int beattype; // 8 = quaver; 4 = crochet; 2 = minim etc 
} sscore_timesig;  

sscore_version


a version number

typedef struct sscore_version { 
    int major; 
    int minor; 
} sscore_version;  

Enumerated Types

sscore_error

all errors

sscore_layoutOptionsFlagBits

bit flags for layout options flags field NB This value is the bit shift for the flag

sscore_warning

all warnings


sscore_error


all errors

enum sscore_error { 
    sscore_NoError = 0, 
    sscore_OutOfMemoryError, 
    sscore_XMLValidationError, 
    sscore_NoBarsInFileError, 
    sscore_WidthTooSmallError, 
    sscore_NullGraphicsError, 
    sscore_MagnificationTooSmallError, 
    sscore_MagnificationTooLargeError, 
    sscore_NoPartsError, 
    sscore_NoPartsToDisplayError, 
    sscore_UnknownError, 
    sscore_BadHeightError, 
    sscore_WidthTooLargeForIphoneError, // the system width is limited on the iPhone-only licensed framework 
    sscore_HeightTooLargeForIphoneError, // the system height is limited on the iPhone-only licensed framework 
    sscore_NullScoreError, 
    sscore_NoBufferError, // the buffer point supplied to a function is NULL or the buffersize is too small 
    sscore_BadPartIndexError, 
    sscore_BadBarIndexError, 
    sscore_UnlicensedFunctionError, // a function has been called with an invalid license 
    sscore_NoImplError, // a function or feature is not currently implemented 
    sscore_InternalFault, 
    sscore_ItemNotFoundError, 
    sscore_ArgumentError, 
    sscore_SoundSampleLoadFailedError, 
    sscore_SoundSetupFailedError, 
    sscore_SynthStartFailedError 
};  

sscore_layoutOptionsFlagBits


bit flags for layout options flags field NB This value is the bit shift for the flag

enum sscore_layoutOptionsFlagBits { 
    sscore_simplifyHarmonyEnharmonicSpelling // set this flag so F-double-sharp appears in a harmony as G 
};  

sscore_warning


all warnings

enum sscore_warning { 
    sscore_NoWarning, 
    sscore_MissingAccidentalsWarning // the xml file is missing required accidental elements which will be reconstructed 
};