GUIDOLib  1.7.7
A Music Score Rendering Engine
Sample code

This section provides examples of the GUIDO library use.

Displaying a score

#include <iostream>
#include "GUIDOEngine.h"
#include "GDevicePostScript.h"
using namespace std;
// ---------------------------------------------------------------------------
// This example of code is intended to show the minimum steps to read a
// GMN file and to display it.
// Take care that for simplicity, this example doesn't check return codes
// ---------------------------------------------------------------------------
void DrawGMNFile (const char * filename)
{
ARHandler arh;
// use a GDevicePostScript with a 72 dpi resolution
GDevicePostScript dev ((int)(21*72/2.54), (int)(29.7*72/2.54), "outfile.eps", "", "");
// declare a data structure for engine initialisation
// we'll make use of the default graphic device (embedded in the library)
// Guido font is guido2 and text font is times
GuidoInitDesc gd = { &dev, 0, "guido2", "Times" };
GuidoOnDrawDesc desc; // declare a data structure for drawing
GuidoInit (&gd); // Initialise the Guido Engine first
// and parse the GMN file to get a GGR handle directly stored in the drawing struct
GuidoParseFile (filename, &arh);
GuidoAR2GR (arh, 0, &desc.handle);
desc.hdc = &dev; // we'll draw on the postscript device
desc.page = 1; // draw the first page only
desc.updateRegion.erase = true; // and draw everything
desc.scrollx = desc.scrolly = 0; // from the upper left page corner
desc.sizex = desc.sizey = 500; // size of the drawing region
GuidoOnDraw (&desc);
}
int main(int argc, char **argv)
{
const char * file = argv[1];
DrawGMNFile (file);
return 0;
}

Building music using the GUIDO Factory

#include "GUIDOFactory.h"
// ---------------------------------------------------------------------------
// Guido Factory example of use
// Take care that for simplicity, this example doesn't check return codes
// ---------------------------------------------------------------------------
void TestGuidoFactory()
{
GuidoFactoryOpen(&f); // open the GUIDO Factory first
GuidoFactoryOpenMusic(f); // and create a new score
GuidoFactoryOpenVoice(f); // open a new voice
GuidoFactoryOpenEvent(f, "c" ); // open a new note
GuidoFactoryCloseEvent(f); // close the note which is now part of the opened voice
GuidoFactoryOpenEvent(f, "e" ); // open another new note
GuidoFactoryAddSharp(f); // add a sharp to the opened note
GuidoFactoryCloseEvent(f); // and close the note which is now part of the opened voice
GuidoFactoryCloseVoice(f); // close the voice which is now part of the opened score
GuidoFactoryOpenVoice(f); // open a second voice
GuidoFactoryOpenEvent(f, "a" ); // open a new voice
GuidoFactoryAddFlat(f); // add a flat to the opened note
GuidoFactoryCloseEvent(f); // and close the note which is now part of the second voice
GuidoFactoryOpenEvent(f, "d" ); // open another new note
GuidoFactoryCloseEvent(f); // and close the note which is now part of the second voice
GuidoFactoryCloseVoice(f); // close the voice which is now part of the opened score
// - Extract AR and GR
ar = GuidoFactoryCloseMusic(f); // extract the GAR handle
GuidoAR2GR( ar, 0, &gr ); // and the GGR handle
GuidoFactoryClose(f); // close the GUIDO Factory which won't be used any more
if( gr ) // check for the handle validity
{
// ... Do something with the GGR handle (i.e: draw)
}
}
GuidoInitDesc
A data structure containing all information required by GuidoInit()
Definition: GUIDOEngine.h:49
GuidoOnDrawDesc::scrolly
int scrolly
Definition: GUIDOEngine.h:169
GuidoOnDrawDesc
Contains all graphic-related information required by GuidoOnDraw()
Definition: GUIDOEngine.h:152
GuidoFactoryOpen
GuidoErrCode GuidoFactoryOpen(ARFactoryHandler *outFactory)
Opens the Guido Factory.
GuidoFactoryOpenEvent
GuidoErrCode GuidoFactoryOpenEvent(ARFactoryHandler inFactory, const char *inEventName)
Creates and opens a new event (note or rest).
GuidoFactoryAddFlat
GuidoErrCode GuidoFactoryAddFlat(ARFactoryHandler inFactory)
Add a flat to the current event.
GUIDOEngine.h
GuidoFactoryOpenVoice
GuidoErrCode GuidoFactoryOpenVoice(ARFactoryHandler inFactory)
Creates and opens a new voice.
GuidoFactoryClose
void GuidoFactoryClose(ARFactoryHandler inFactory)
Closes the Guido Factory.
ARFactoryHandler
void * ARFactoryHandler
Definition: GUIDOFactory.h:48
GuidoOnDraw
GuidoErrCode GuidoOnDraw(GuidoOnDrawDesc *desc)
Draws one page of score into a graphic device.
GuidoInit
GuidoErrCode GuidoInit(GuidoInitDesc *desc)
GuidoOnDrawDesc::sizey
int sizey
Definition: GUIDOEngine.h:176
GuidoFactoryOpenMusic
GuidoErrCode GuidoFactoryOpenMusic(ARFactoryHandler inFactory)
Creates and opens a new music score.
GuidoFactoryAddSharp
GuidoErrCode GuidoFactoryAddSharp(ARFactoryHandler inFactory)
Adds a sharp to the current event.
GuidoOnDrawDesc::handle
GRHandler handle
A Guido handler to a graphic representation.
Definition: GUIDOEngine.h:155
GuidoOnDrawDesc::updateRegion
GPaintStruct updateRegion
Indicates what to (re)draw.
Definition: GUIDOEngine.h:162
GuidoFactoryCloseMusic
ARHandler GuidoFactoryCloseMusic(ARFactoryHandler inFactory)
Closes the current music score.
GUIDOFactory.h
GRHandler
struct NodeGR * GRHandler
Definition: GUIDOEngine.h:37
GuidoParseFile
GuidoErrCode GuidoParseFile(const char *filename, ARHandler *ar) GUIDOAPI_deprecated
GuidoOnDrawDesc::hdc
VGDevice * hdc
A graphic device context.
Definition: GUIDOEngine.h:158
GuidoOnDrawDesc::page
int page
The page number. Starts from 1.
Definition: GUIDOEngine.h:160
GuidoFactoryCloseEvent
GuidoErrCode GuidoFactoryCloseEvent(ARFactoryHandler inFactory)
Closes the current event.
ARHandler
struct NodeAR * ARHandler
Definition: GUIDOEngine.h:36
GPaintStruct::erase
bool erase
a flag to ignore the following rect and to redraw everything
Definition: GUIDOEngine.h:67
GuidoFactoryCloseVoice
GuidoErrCode GuidoFactoryCloseVoice(ARFactoryHandler inFactory)
Closes the current voice.
GuidoAR2GR
GuidoErrCode GuidoAR2GR(ARHandler ar, const GuidoLayoutSettings *settings, GRHandler *gr)
GuidoOnDrawDesc::sizex
int sizex
Definition: GUIDOEngine.h:176
GuidoOnDrawDesc::scrollx
int scrollx
Definition: GUIDOEngine.h:169

Guido Project Copyright © 2019 Grame-CNCM