naspro

changeset 173:71372f617827 trunk

Totally CMakeized, a bit of doc
author Stefano D'Angelo <zanga.mail@gmail.com>
date Fri Mar 26 18:54:24 2010 +0200 (22 months ago)
parents d1f0d4a83318
children 4f7243a606b1
files naspro-core/CMakeLists.txt naspro-core/COPYING naspro-core/README naspro-core/include/NASPRO/core/avl.h naspro-core/include/NASPRO/core/bridge.h naspro-core/include/NASPRO/core/dl.h naspro-core/include/NASPRO/core/env.h naspro-core/include/NASPRO/core/lv2api.h naspro-core/include/NASPRO/core/manifest.h naspro-core/include/NASPRO/core/path.h naspro-core/include/NASPRO/core/string.h naspro-core/src/avl.c naspro-core/src/manifest.c
line diff
     1.1 --- a/naspro-core/CMakeLists.txt	Thu Mar 25 18:16:12 2010 +0200
     1.2 +++ b/naspro-core/CMakeLists.txt	Fri Mar 26 18:54:24 2010 +0200
     1.3 @@ -33,3 +33,32 @@
     1.4  install(TARGETS nacore DESTINATION ${LIBDIR_INSTALL})
     1.5  install(DIRECTORY include/NASPRO DESTINATION ${INCLUDEDIR_INSTALL})
     1.6  install(FILES nacore.pc DESTINATION ${PKGCONFIGDIR_INSTALL})
     1.7 +
     1.8 +set(CPACK_PACKAGE_DESCRIPTION_FILE ${NACORE_SOURCE_DIR}/README)
     1.9 +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The NASPRO core library")
    1.10 +set(CPACK_PACKAGE_NAME "NASPRO core")
    1.11 +set(CPACK_PACKAGE_VERSION_MAJOR 0)
    1.12 +set(CPACK_PACKAGE_VERSION_MINOR 2)
    1.13 +set(CPACK_PACKAGE_VERSION_PATCH 0)
    1.14 +set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
    1.15 +set(CPACK_PACKAGE_FILE_NAME naspro-core-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM})
    1.16 +set(CPACK_SOURCE_GENERATOR TGZ)
    1.17 +set(CPACK_SOURCE_PACKAGE_FILE_NAME naspro-core-${CPACK_PACKAGE_VERSION})
    1.18 +set(CPACK_SOURCE_IGNORE_FILES
    1.19 +	"^${NACORE_BINARY_DIR}/CMakeCache.*"
    1.20 +	"^${NACORE_BINARY_DIR}/CMakeFiles.*"
    1.21 +	"^${NACORE_BINARY_DIR}/cmake.*"
    1.22 +	"^${NACORE_BINARY_DIR}/install.*"
    1.23 +	"^${NACORE_BINARY_DIR}/_CPack.*"
    1.24 +	"^${NACORE_BINARY_DIR}/CPack.*"
    1.25 +	"^${NACORE_BINARY_DIR}/Makefile$"
    1.26 +	"^${NACORE_BINARY_DIR}/naspro-.*"
    1.27 +	"^${NACORE_BINARY_DIR}/config.h$"
    1.28 +	"^${NACORE_BINARY_DIR}/nacore.pc$"
    1.29 +	"^${NACORE_BINARY_DIR}/.*\\\\.o$"
    1.30 +	"^${NACORE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}nacore.*${CMAKE_SHARED_LIBRARY_SUFFIX}.*$"
    1.31 +)
    1.32 +set(CPACK_RESOURCE_FILE_LICENSE ${NACORE_SOURCE_DIR}/COPYING)
    1.33 +set(CPACK_RESOURCE_FILE_README ${NACORE_SOURCE_DIR}/README)
    1.34 +
    1.35 +include(CPack)
     2.1 --- a/naspro-core/COPYING	Thu Mar 25 18:16:12 2010 +0200
     2.2 +++ b/naspro-core/COPYING	Fri Mar 26 18:54:24 2010 +0200
     2.3 @@ -1,4 +1,4 @@
     2.4 -Copyright (C) 2007-2009 Stefano D'Angelo <zanga.mail@gmail.com>
     2.5 +Copyright (C) 2007-2010 Stefano D'Angelo <zanga.mail@gmail.com>
     2.6  All rights reserved.
     2.7  
     2.8  Redistribution and use in source and binary forms, with or without
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/naspro-core/README	Fri Mar 26 18:54:24 2010 +0200
     3.3 @@ -0,0 +1,21 @@
     3.4 +The NASPRO core library
     3.5 +=======================
     3.6 +
     3.7 +This is just a tiny convenience library containing useful code to implement LV2
     3.8 +dynamic manifest plugins and especially bridges from other APIs to LV2.
     3.9 +
    3.10 +It offers:
    3.11 +
    3.12 + * LV2 dynamic manifest and descriptor generation;
    3.13 + * OS-independent path scanning;
    3.14 + * OS-independent environment variables retrieving;
    3.15 + * OS-independent dynamic loading;
    3.16 + * AVL trees.
    3.17 +
    3.18 +It supports the LV2 core specification (r3) and the following extensions:
    3.19 +
    3.20 + * LV2 Units extension (http://lv2plug.in/ns/extensions/units);
    3.21 + * LV2 Events (http://lv2plug.in/ns/ext/event);
    3.22 + * LV2 MIDI Events (http://lv2plug.in/ns/ext/midi);
    3.23 + * LV2 Extended Port Information (http://lv2plug.in/ns/dev/extportinfo) - only
    3.24 +     the epp:logarithmic property is supported.
     4.1 --- a/naspro-core/include/NASPRO/core/avl.h	Thu Mar 25 18:16:12 2010 +0200
     4.2 +++ b/naspro-core/include/NASPRO/core/avl.h	Fri Mar 26 18:54:24 2010 +0200
     4.3 @@ -2,7 +2,7 @@
     4.4   * NASPRO - NASPRO Architecture for Sound Processing
     4.5   * Core library
     4.6   *
     4.7 - * Copyright (C) 2007-2009  Stefano D'Angelo  <zanga.mail@gmail.com>
     4.8 + * Copyright (C) 2007-2010  Stefano D'Angelo  <zanga.mail@gmail.com>
     4.9   *
    4.10   * See the COPYING file for license conditions.
    4.11   */
    4.12 @@ -16,19 +16,81 @@
    4.13  extern "C" {
    4.14  #endif
    4.15  
    4.16 +/* WARNING: this API is not thread-safe */
    4.17 +
    4.18 +/* AVL tree handle */
    4.19  typedef struct _nacore_avl_tree * nacore_avl_tree_t;
    4.20  
    4.21 +/*
    4.22 + * Creates a new AVL tree, returns NULL in case of faliure.
    4.23 + *
    4.24 + * content_cmp is a pointer to a function which compares the content of two
    4.25 + *   nodes (strcmp()-like)
    4.26 + * key_cmp is a pointer to a function which compares the content of a node with
    4.27 +     a key value (strcmp()-like)
    4.28 + */
    4.29  nacore_avl_tree_t nacore_avl_tree_new(int (*content_cmp)(void *c1, void *c2),
    4.30  				      int (*key_cmp)(void *content, void *key));
    4.31 +
    4.32 +/*
    4.33 + * Adds a node to the tree and balances it, in case of failure the node is
    4.34 + * simply not added.
    4.35 + *
    4.36 + * tree is the AVL tree handle
    4.37 + * content is the node content
    4.38 + */
    4.39  void nacore_avl_tree_add(nacore_avl_tree_t tree, void *content);
    4.40 +
    4.41 +/*
    4.42 + * Calls a callback function for each node of the tree (the order of such calls
    4.43 + * is not defined)
    4.44 + *
    4.45 + * tree is the AVL tree handle
    4.46 + * callback is the callback function
    4.47 + * data is the data pointer which gets passed to the callback
    4.48 + */
    4.49  void nacore_avl_tree_for_each(nacore_avl_tree_t tree,
    4.50  			      void (*callback)(void *content, void *data),
    4.51  			      void *data);
    4.52 +
    4.53 +/*
    4.54 + * Finds a node in the tree by comparing node contents with a key, in case none
    4.55 + * is found NULL is returned.
    4.56 + *
    4.57 + * tree is the AVL tree handle
    4.58 + * key is the key value to look for
    4.59 + */
    4.60  void *nacore_avl_tree_find(nacore_avl_tree_t tree, void *key);
    4.61 +
    4.62 +/*
    4.63 + * Returns the number of nodes in a tree
    4.64 + * 
    4.65 + * tree is the AVL tree handle
    4.66 + */
    4.67  size_t nacore_avl_tree_get_nodes_count(nacore_avl_tree_t tree);
    4.68 +
    4.69 +/*
    4.70 + * Destroys a tree (frees the tree structure only, not nodes' content)
    4.71 + *
    4.72 + * tree is the AVL tree handle
    4.73 + */
    4.74  void nacore_avl_tree_free(nacore_avl_tree_t tree);
    4.75  
    4.76 +/*
    4.77 + * Convenience function for comparing nodes in trees of NASPRO core plugin
    4.78 + * descriptors where the URI is the ordering field.
    4.79 + *
    4.80 + * c1 and c2 are plugin descriptors
    4.81 + */
    4.82  int nacore_content_cmp_descriptor_by_uri(void *c1, void *c2);
    4.83 +
    4.84 +/*
    4.85 + * Convenience function for comparing a node's content with a key value where
    4.86 + * nodes are NASPRO core plugin descriptors and the key is a URI.
    4.87 + *
    4.88 + * content is a plugin descriptor
    4.89 + * data is the URI string
    4.90 + */
    4.91  int nacore_key_cmp_descriptor_by_uri(void *content, void *data);
    4.92  
    4.93  #ifdef __cplusplus
     5.1 --- a/naspro-core/include/NASPRO/core/bridge.h	Thu Mar 25 18:16:12 2010 +0200
     5.2 +++ b/naspro-core/include/NASPRO/core/bridge.h	Fri Mar 26 18:54:24 2010 +0200
     5.3 @@ -20,11 +20,15 @@
     5.4  extern "C" {
     5.5  #endif
     5.6  
     5.7 -/* Plugins beloging to a subclass should have the superclass disabled:
     5.8 +/*
     5.9 + * Plugin descriptor class values
    5.10 + *
    5.11 + * Plugins beloging to a subclass should have the superclass disabled:
    5.12   * e.g. if NACORE_DESCRIPTOR_CLASS_INSTRUMENT is on, then
    5.13 - * NACORE_DESCRIPTOR_CLASS_GENERATOR must be off. */
    5.14 + * NACORE_DESCRIPTOR_CLASS_GENERATOR must be off.
    5.15 + */
    5.16  
    5.17 -/* descriptor.classes_1 */
    5.18 +/* Values for the classes_1 field */
    5.19  #define NACORE_DESCRIPTOR_CLASS_GENERATOR	(1)
    5.20  #define NACORE_DESCRIPTOR_CLASS_INSTRUMENT	(1 << 1)
    5.21  #define NACORE_DESCRIPTOR_CLASS_OSCILLATOR	(1 << 2)
    5.22 @@ -54,19 +58,27 @@
    5.23  #define NACORE_DESCRIPTOR_CLASS_DISTORTION	(1 << 26)
    5.24  #define NACORE_DESCRIPTOR_CLASS_WAVESHAPER	(1 << 27)
    5.25  
    5.26 -/* descriptor.classes_2 */
    5.27 +/* Values for the classes_2 field */
    5.28  #define NACORE_DESCRIPTOR_CLASS_DYNAMICS	(1)
    5.29  #define NACORE_DESCRIPTOR_CLASS_COMPRESSOR	(1 << 1)
    5.30  #define NACORE_DESCRIPTOR_CLASS_EXPANDER	(1 << 2)
    5.31  #define NACORE_DESCRIPTOR_CLASS_LIMITER		(1 << 3)
    5.32  #define NACORE_DESCRIPTOR_CLASS_GATE		(1 << 4)
    5.33  
    5.34 -/* descriptor.properties */
    5.35 +/*
    5.36 + * Plugin descriptor property values
    5.37 + */
    5.38 +
    5.39 +/* Values for the properties field */
    5.40  #define NACORE_DESCRIPTOR_HAS_LIVE_DEP		(1)
    5.41  #define NACORE_DESCRIPTOR_INPLACE_BROKEN	(1 << 1)
    5.42  #define NACORE_DESCRIPTOR_HARD_RT_CAPABLE	(1 << 2)
    5.43  
    5.44 -/* port_descriptor.properties */
    5.45 +/*
    5.46 + * Port descriptor property values
    5.47 + */
    5.48 +
    5.49 +/* Values for the properties field */
    5.50  #define NACORE_PORT_IS_OUTPUT			(1)
    5.51  #define NACORE_PORT_IS_AUDIO			(1 << 1)
    5.52  #define NACORE_PORT_IS_MIDI			(1 << 2)
    5.53 @@ -77,11 +89,16 @@
    5.54  #define NACORE_PORT_INTEGER			(1 << 7)
    5.55  #define NACORE_PORT_LOGARITHMIC			(1 << 8)
    5.56  
    5.57 -/* port_descriptor.scale.properties */
    5.58 +/*
    5.59 + * Port descriptor scale values
    5.60 + */
    5.61 +
    5.62 +/* Values for the properties field */
    5.63  #define NACORE_SCALE_HAS_MIN			(1)
    5.64  #define NACORE_SCALE_HAS_MAX			(1 << 1)
    5.65  #define NACORE_SCALE_HAS_DEFAULT		(1 << 2)
    5.66  
    5.67 +/* Scale units */
    5.68  enum nacore_scale_unit
    5.69    {
    5.70  	nacore_scale_unit_none = 0,
    5.71 @@ -110,12 +127,14 @@
    5.72  	nacore_scale_unit_semitone
    5.73    };
    5.74  
    5.75 +/* Scale points */
    5.76  struct nacore_scale_point
    5.77    {
    5.78  	char		*label;
    5.79  	float		 value;
    5.80    };
    5.81  
    5.82 +/* Scale values for a port descriptor */
    5.83  struct nacore_port_scale
    5.84    {
    5.85  	uint32_t			 properties;
    5.86 @@ -127,6 +146,7 @@
    5.87  	size_t				 points_count;
    5.88    };
    5.89  
    5.90 +/* Port descriptor */
    5.91  struct nacore_port_descriptor
    5.92    {
    5.93  	char				*name;
    5.94 @@ -135,6 +155,7 @@
    5.95  	void				*data;
    5.96    };
    5.97  
    5.98 +/* Plugin descriptor */
    5.99  struct nacore_descriptor
   5.100    {
   5.101  	char				*name;
     6.1 --- a/naspro-core/include/NASPRO/core/dl.h	Thu Mar 25 18:16:12 2010 +0200
     6.2 +++ b/naspro-core/include/NASPRO/core/dl.h	Fri Mar 26 18:54:24 2010 +0200
     6.3 @@ -14,11 +14,37 @@
     6.4  extern "C" {
     6.5  #endif
     6.6  
     6.7 +/* Dynamically loaded module handle */
     6.8  typedef struct _nacore_dl_module * nacore_dl_module_t;
     6.9  
    6.10 +/*
    6.11 + * Loads a dynamic module, returns NULL on failure.
    6.12 + *
    6.13 + * file is its filename (absolute path)
    6.14 + */
    6.15  nacore_dl_module_t nacore_dl_open(const char *file);
    6.16 +
    6.17 +/*
    6.18 + * Retrieves the address where a symbol is loaded or NULL in case of failure.
    6.19 + *
    6.20 + * handle is the dynamic module handle
    6.21 + * symbol is the symbol name
    6.22 + */
    6.23  void * nacore_dl_sym(nacore_dl_module_t handle, const char *symbol);
    6.24 +
    6.25 +/*
    6.26 + * Unloads a dynamic module.
    6.27 + *
    6.28 + * handle is the dynamic module handle
    6.29 + */
    6.30  void nacore_dl_close(nacore_dl_module_t handle);
    6.31 +
    6.32 +/*
    6.33 + * Convenience function to filter dynamic modules based on their filenames when
    6.34 + * scanning paths.
    6.35 + *
    6.36 + * file is the filename to filter
    6.37 + */
    6.38  char nacore_dl_filename_filter(const char *file);
    6.39  
    6.40  #ifdef __cplusplus
     7.1 --- a/naspro-core/include/NASPRO/core/env.h	Thu Mar 25 18:16:12 2010 +0200
     7.2 +++ b/naspro-core/include/NASPRO/core/env.h	Fri Mar 26 18:54:24 2010 +0200
     7.3 @@ -14,7 +14,19 @@
     7.4  extern "C" {
     7.5  #endif
     7.6  
     7.7 +/*
     7.8 + * Retrieves the value of an environment variable, returns NULL on failure. If
     7.9 + * not NULL, the value must be freed using nacore_env_free_var_value().
    7.10 + *
    7.11 + * name is the name of the environment variable
    7.12 + */
    7.13  char * nacore_env_get_var(const char *name);
    7.14 +
    7.15 +/*
    7.16 + * Frees, if needed, a value returned by nacore_env_get_var().
    7.17 + *
    7.18 + * value is the value returned by nacore_env_get_var().
    7.19 + */
    7.20  void nacore_env_free_var_value(char *value);
    7.21  
    7.22  #ifdef __cplusplus
     8.1 --- a/naspro-core/include/NASPRO/core/lv2api.h	Thu Mar 25 18:16:12 2010 +0200
     8.2 +++ b/naspro-core/include/NASPRO/core/lv2api.h	Fri Mar 26 18:54:24 2010 +0200
     8.3 @@ -18,6 +18,13 @@
     8.4  extern "C" {
     8.5  #endif
     8.6  
     8.7 +/*
     8.8 + * Convenience function to fill a LV2 plugin descriptor with data found in a
     8.9 + * NASPRO core plugin descriptor (URI and function pointers).
    8.10 + *
    8.11 + * lv2_desc is a pointer to the LV2 plugin descriptor to be filled
    8.12 + * n_desc is a pointer to the NASPRO core plugin descriptor
    8.13 + */
    8.14  void nacore_lv2api_fill_desc(LV2_Descriptor *lv2_desc,
    8.15  			     struct nacore_descriptor *n_desc);
    8.16  
     9.1 --- a/naspro-core/include/NASPRO/core/manifest.h	Thu Mar 25 18:16:12 2010 +0200
     9.2 +++ b/naspro-core/include/NASPRO/core/manifest.h	Fri Mar 26 18:54:24 2010 +0200
     9.3 @@ -16,9 +16,31 @@
     9.4  extern "C" {
     9.5  #endif
     9.6  
     9.7 +/*
     9.8 + * Prints the list of known Turtle prefixes in the file represented by fp.
     9.9 + *
    9.10 + * fp is the file handle
    9.11 + */
    9.12  void nacore_manifest_print_subject_prefixes(FILE *fp);
    9.13 +
    9.14 +/*
    9.15 + * Prints the triple "<URI> a lv2_Plugin ." corresponding to the given
    9.16 + * descriptor in the file represented by fp.
    9.17 + *
    9.18 + * desc is the plugin descriptor
    9.19 + * fp is the file handle
    9.20 + */
    9.21  void nacore_manifest_print_subject_triple(struct nacore_descriptor *desc,
    9.22  					  FILE *fp);
    9.23 +
    9.24 +/*
    9.25 + * Prints all Turtle data (including prefixes) regarding a plugin in the file
    9.26 + * represented by fp.
    9.27 + *
    9.28 + * desc is the plugin descriptor
    9.29 + * fp is the file handle
    9.30 + * binary is the value to print for the lv2:binary property (excluding < and >)
    9.31 + */
    9.32  void nacore_manifest_print_data(struct nacore_descriptor *desc, FILE *fp,
    9.33  				const char *binary);
    9.34  
    10.1 --- a/naspro-core/include/NASPRO/core/path.h	Thu Mar 25 18:16:12 2010 +0200
    10.2 +++ b/naspro-core/include/NASPRO/core/path.h	Fri Mar 26 18:54:24 2010 +0200
    10.3 @@ -14,9 +14,25 @@
    10.4  extern "C" {
    10.5  #endif
    10.6  
    10.7 +/*
    10.8 + * Scans the entries in each directory of the specified path.
    10.9 + *
   10.10 + * path is the path to scan (on Windows it's a semicolon-separated list of
   10.11 + *   directories, on all other systems it's colon-separated)
   10.12 + * callback is the function which is called for each (non filtered) entry,
   10.13 + *   where file is the full filename and basename contains the filename stripped
   10.14 + *   of its directory path
   10.15 + * filter, if not NULL, is a function which filters filenames to be passed to
   10.16 + *   callback, when it returns 0 the file is not passed to callback
   10.17 + */
   10.18  void nacore_path_for_each(const char *path,
   10.19  	void (*callback)(const char *file, const char *basename, void *data),
   10.20  	char (*filter)(const char *file), void *data);
   10.21 +
   10.22 +/*
   10.23 + * Like nacore_path_for_each(), but here the directories contained in path are
   10.24 + * intended as relative to the user's home directory.
   10.25 + */
   10.26  void nacore_path_home_for_each(const char *dir,
   10.27  	void (*callback)(const char *file, const char *basename, void *data),
   10.28  	char (*filter)(const char *file), void *data);
    11.1 --- a/naspro-core/include/NASPRO/core/string.h	Thu Mar 25 18:16:12 2010 +0200
    11.2 +++ b/naspro-core/include/NASPRO/core/string.h	Fri Mar 26 18:54:24 2010 +0200
    11.3 @@ -10,6 +10,9 @@
    11.4  #ifndef _NACORE_STRING_H
    11.5  #define _NACORE_STRING_H
    11.6  
    11.7 +#include <stddef.h>
    11.8 +
    11.9 +/* Helper macro to determine whether a string (char pointer) is NULL or empty */
   11.10  #define NACORE_STRING_IS_NULL_OR_EMPTY(s)	((s == NULL) ? 1 : (*s == '\0'))
   11.11  
   11.12  #endif /* !_NACORE_STRING_H */
    12.1 --- a/naspro-core/src/avl.c	Thu Mar 25 18:16:12 2010 +0200
    12.2 +++ b/naspro-core/src/avl.c	Fri Mar 26 18:54:24 2010 +0200
    12.3 @@ -12,8 +12,6 @@
    12.4  
    12.5  #include <NASPRO/core/lib.h>
    12.6  
    12.7 -/* TODO: Nothing here is thread-safe. */
    12.8 -
    12.9  struct avl_tree_node
   12.10    {
   12.11  	size_t			 father;
    13.1 --- a/naspro-core/src/manifest.c	Thu Mar 25 18:16:12 2010 +0200
    13.2 +++ b/naspro-core/src/manifest.c	Fri Mar 26 18:54:24 2010 +0200
    13.3 @@ -17,8 +17,6 @@
    13.4  
    13.5  #include "config.h"
    13.6  
    13.7 -/* TODO: setlocale + multi-threading = ouch! */
    13.8 -
    13.9  void
   13.10  nacore_manifest_print_subject_prefixes(FILE *fp)
   13.11  {
   13.12 @@ -176,8 +174,10 @@
   13.13  	char *prev_locale;
   13.14  	size_t i;
   13.15  
   13.16 +	/* FIXME: we need a locale-independent way of printing float values */
   13.17 +
   13.18  	prev_locale = setlocale(LC_NUMERIC, NULL);
   13.19 -	setlocale(LC_NUMERIC, "C");
   13.20 +	setlocale(LC_NUMERIC, "POSIX");
   13.21  	
   13.22  	fprintf(fp, "@prefix rdf: <http://www.w3.org/1999/02/"
   13.23  		    "22-rdf-syntax-ns#> .\n");
   13.24 @@ -224,7 +224,6 @@
   13.25  
   13.26  	print_classes(fp, desc);
   13.27  
   13.28 -#if 0
   13.29  	for (i = 0; i < desc->port_descs_count; i++)
   13.30  	  {
   13.31  		if (desc->port_descs[i].properties & NACORE_PORT_IS_MIDI)
   13.32 @@ -236,7 +235,6 @@
   13.33  			break;
   13.34  		  }
   13.35  	  }
   13.36 -#endif
   13.37  
   13.38  	for (i = 0; i < desc->port_descs_count; i++)
   13.39  	  {