Features Help Download

Lomse Hacking Guide

6.1. LomseDoorway class

Class LomseDoorway is the access point to the Lomse library. It must be used by the user application at two points:

  1. Before using the Lomse library it is necessary to initialize it. This means setting up certain options about rendering and event handlig.
  2. Later, the user application has to use LomseDoorway for creating and accessing Document objects.

6.1.1. Creating documents

The only way the Lomse user application has to create documents is by requesting it to the LoseDoorway object. Creating a Document also involves creating all the MVC objects (see Part III: Presentation and user interaction) to manage its modification and rendering. Therefore, all document creation methods do not return a Document object but a Presenter object. Using it, you can access the relevant related components, such as the Document, its ``View and the Interactor for modifying the Document and/or the View.

There are four public methods for creating Document objects:

Presenter* new_document(int viewType);
Presenter* new_document(int viewType, const string& ldpSource,
                        ostream& reporter = cout);
Presenter* open_document(int viewType, const string& filename,
                         ostream& reporter = cout);
Presenter* open_document(int viewType, LdpReader& reader,
                         ostream& reporter = cout);

All of them receive as parameter the type of view to create.

  • Method new_document has two variants.
    1. With no more parameters it creates an empty document. It is usefull for cases in wich your application is going to add the content (i.e. interactive edition, automated music composition)
    2. The other alternative is to pass a string with the LDP source code describing the desired document content. In this case LDP code is compiled, and a document with that content is created.
  • Method open_document has also two varians. In the first one you have to pass the full path to a file in local filesystem. Two formats are supported:
    1. LMS format. This is plain text containing LDP code.
    2. LMB format. This is LenMus eBook format: a zipped archive containing many LMS files, indexes and other information.
  • The second variant of method open_document receives as parameter an LdpReader object. It will take the responsibility for providing an LDP stream from which the document content can be read. This method is oriented to facilitate Lomse usability by allowing the user application to use different sources, other than local filesystem files, for storing LDP documents. For instance, databases, network storage, compressed archives other than zip, etc. In these cases, the user application only has to create a class, derived from LdpReader and implement the necessary methods.

Parameter reporter is the ostream to be used for error reporting. By default cout is used.

(To be continued ...)