JBSO Csound OO system


Introduction

JBSO is a Csound framework for a kind of object oriented design. Csound itself does not offer object oriented mechanisms to implement types with memeber variables and methods. This framework still requires a developer to "manually" implement a systematic interface, but takes care of some global management in the background and offers further macros and utility opcodes to aid in a systematic standard.

Types or classes created with JBSO automatically manage type specific and global object counters, some validity checks and a global name to ID mapping system, which can be used for object lookup. Furthermore versioining of type APIs is enforced.

JBSO Version 1.1 offers a few macros to standardise status codes, like errors, warnings, information and success, as well as opcodes to handle retrieval and management of errors.

JBSO already provides a few features specifically intended for object data storage, but does not supply opcoodes to manage these, yet. Aside from a global storage format header, there is support for versioning, numerical type IDs and a provision for a types storage size.

[Back to top]


Changes and updates

Changes from version 1.0

Fixed a bug pertaining to .Size property. Updated all opcodes to use the new status codes (see macros and constants.

New opcdes: mjbsoc_get_status, m_jbsoc_move_status, m_jbsoc_set_status, m_jbsoc_get_status_string, m_jbsoc_move_status_string and m_jbsoc_set_status_string

[Back to top]


Basic concepts and ideas

The JBSO framework is implemented first as a set of User Defined Opcodes (UDOs). There are two families of opcodes:

Internally JBSO relies on Csound channels and ftables to store and pass around data. Channel names follow a fixed system. There are namespaces. Namespaces are sperated by dots ".". Each valid JBSO channel name begins with "JBSO.".

Special subspaces

Both directly under JBSO and underneath the classname there is a special namespace "Global", which means that no class/type and no object can be called Global. In the global namespaces there are properties almost exclusively managed and used by the JBSO system. These include version numbers, object counters, object IDs and lookup tables. JBSO offer opcodes to deal with these properties and query them.

Object creation and destruction

To create a JBSO type you should call m_jbsoc_new as the first call in your creation opcode. This will attempt to set up basics for your object, like its validity, object ID, error status and error message (0 and empty respectively) and name lookup, as well as increase object counters. If this operation fails, m_jbsoc_new will return a status other than 1.

to destroy an object of your type, you should call m_jbsoc_delete as the last call in your destruction opcode, this will deinitialise the same properties and decrease the object counters. This opcode also return 1 upon success, which allows you to print a further error message or otherwise try to handle problems.

Your object properties

As mentioned above, JBSO relies on Csound channels and ftables to store data. Channels are used to store single values, audio and character strings. ftables are used to store large collections of data, like arrays of values. To properly reference an ftable across multiple instruments, its table number should also be stored in a channel.

Channel names are hirarchical, so all properties of one object live under the names: JBSO._CLASSNAME_._OBJECTNAME_.* where _CLASSNAME_ is the name of the object's type or class and _OBJECTNAME_ is the name of the object itself.

Storage on disk a.k.a. serialisation

Some elements have been put into place for a systematic serialisation process. The channelname JBSO.Global.Header1 to JBSO.Global.Header4 hold four arbirary values that should be written to the first four elements of a stored object. This should be followed by the class/type ID, the major and minor version number of the type and the storage size. Each class should provide its storage size in JBSO._CLASSNAME_.Global.Size, if appropriate.

Opcode naming

There is nothing to enforce any system of naming opcodes, but it is helpful to choose a naming convention that includes the name of the class/type to avoid conflicts with builtin Csound opcodes or other UDOs.

JBSO itself - for example - prefixes any UDO name with m_jbso_ or m_jbsoc_. Further, whereever possible, it adopts the convention of get_* and set_* to query and change values. is_* and has_* are good contenders to query boolean values or states. There are a few conventions described in general purpose programming literature. For a clean approach it is highly useful to find one system and adhere to it! Especially when, like in this case, the environment or toolkit still leaves a lot of organisation and "encapsulation" to the developer.

[Back to top]


Macros and constants

There are several families of macros defined in JBSO. Below are organised lists. It may be helpful to reuse these macros in your own code to improve readability and robustness.

JBSO information

Status and error codes

[Back to top]


JBSO system opcodes

As noted in the basic concepts and ideas there are two families of opcodes, making up this framework, those related to the system itself and those related to types and objects within it. This section lists the UDOs that purely address the framework.

[Back to top]


Class and object related opcodes

The UDOs below are class or object related, in the case of m_jbsoc_new and m_jbsoc_delete they should be used by the developer of a JBSO class/type directly, as described in the basic concepts and ideas.

[Back to top]


List of opcodes

m_jbso_init

DESCRIPTION

Initialise the JBSO object system, i.e. set up a few global channels for management.

SYNTAX

m_jbso_init

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbso_is_valid

DESCRIPTION

Return 1 if the JBSO system is already setup, 0 otherwise.

SYNTAX

kValid m_jbso_is_valid

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbso_get_version

DESCRIPTION

Return the major and minor version numbers of the JBSO class system itself.

SYNTAX

iMajor, iMinor m_jbso_get_version

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbso_get_count

DESCRIPTION

Return the number of all JBSO object in existence. All objects should take care of the global counter.

SYNTAX

kNumberOfObject m_jbso_get_count

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbso_is_class

DESCRIPTION

Check whether the supplied name denotes an existing JBSO class. This will only work once the class has been setup.

SYNTAX

kValid m_jbso_is_class SclassName

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbso_class_version

DESCRIPTION

Return the version of JBSO class API. For this to work, the class must be initialised.

SYNTAX

iMajor, iMinor m_jbso_class_version SclassName

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of system opcodes]


m_jbsoc_new

DESCRIPTION

This is a utility opcode meant only to be used in higher level UDOs to create JBSO objects. It is highly recommended to use it in tandem with m_jbsoc_delete .

SYNTAX

iSuccess m_jbsoc_new SclassName, Sname, iVersionMajor, iVersionMinor

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_delete

DESCRIPTION

The final operations to be performed when destroying a JBSO object.

SYNTAX

iSuccess m_jbsoc_delete SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_is_object

DESCRIPTION

Check whether the supplied name refers to an object of the given class.

SYNTAX

kValid m_jbsoc_is_object SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_get_count

DESCRIPTION

Return the number of existing objects of the given class, or $JBSO_STAT_ERR otherwise.

SYNTAX

kNumberOfObjects m_jbsoc_get_count SclassName

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_get_id

DESCRIPTION

Return the numerical ID of a JBSO object. This ID is used for management purposes.

SYNTAX

iID m_jbsoc_get_id SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_get_size

DESCRIPTION

Return the storage size for objects of the given class/type or $JBSO_STAT_ERR on error.

SYNTAX

kSize m_jbsoc_get_size SclassName

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_get_status

DESCRIPTION

Retrieve the status code from the specified object.

SYNTAX

iStatus m_jbsoc_get_status SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_move_status

DESCRIPTION

Retrieve the status code from the specified object and reset the code to $JBSO_STAT_OK, only if the previous code was _NOT_ $JBSO_STAT_ERR .

SYNTAX

iStatus m_jbsoc_move_status SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_set_status

DESCRIPTION

Set an object's status.

SYNTAX

kResult m_jbsoc_set_status SclassName, Sname, kStatus

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_get_status_string

DESCRIPTION

Return the status string of an object.

SYNTAX

Sstatus m_jbsoc_get_status_string SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_move_status_string

DESCRIPTION

Return the object's status message. Reset the message if - and only if - the object status code is _NOT_ $JBSO_STAT_ERR .

SYNTAX

Sstatus m_jbsoc_move_status_string SclassName, Sname

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]


m_jbsoc_set_status_string

DESCRIPTION

Set an object's status message.

SYNTAX

kResult m_jbsoc_set_status_string SclassName, Sname, SstatusString

INITIALIZATION

PERFORMANCE

CREDITS

Author: Jeanette C.

[Back to top] [Back to list of object opcodes]