File: bsecategories.proc

package info (click to toggle)
beast 0.7.4-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 33,500 kB
  • sloc: ansic: 197,348; cpp: 59,114; sh: 11,030; perl: 2,523; makefile: 2,474; xml: 1,026; lisp: 549; awk: 270; sed: 8
file content (157 lines) | stat: -rw-r--r-- 5,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* BSE - Better Sound Engine	-*-mode: c;-*-
 * Copyright (C) 2003 Tim Janik
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * A copy of the GNU Lesser General Public License should ship along
 * with this library; if not, see http://www.gnu.org/copyleft/.
 */
#include <bse/bsecategories.h>
#include <bse/bseprocedure.h>
#include <bse/bseplugin.h>


AUTHORS	= "Tim Janik <timj@gtk.org>";
LICENSE	= "GNU Lesser General Public License";


PROCEDURE (bse-categories-match-typed, "Categories/Match Typed") {
  HELP  = "List BSE categories according to a pattern and type match.";
  IN	= sfi_pspec_string ("pattern", "Pattern", "Pattern to match category, supports '*' and '?' wildcards.",
			    "*", SFI_PARAM_STANDARD);
  IN	= sfi_pspec_string ("type", "Type", "Base type for categories to conform to.",
			    NULL, SFI_PARAM_STANDARD);
  OUT   = bse_param_spec_boxed ("categories", "Categories", NULL, BSE_TYPE_CATEGORY_SEQ, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
      const GValue      *in_values,
      GValue            *out_values)
{
  /* extract parameter values */
  gchar *pattern   = sfi_value_get_string (in_values++);
  gchar *type_name = sfi_value_get_string (in_values++);
  GType  type      = type_name ? g_type_from_name (type_name) : 0;
  BseCategorySeq *cseq = NULL;
  
  /* check parameters */
  if (!pattern)
    return BSE_ERROR_PROC_PARAM_INVAL;
  
  if (type)
    cseq = bse_categories_match_typed (pattern, type);
  if (!cseq)
    cseq = bse_category_seq_new ();
  
  /* set output parameters */
  bse_value_take_boxed (out_values++, cseq);
  
  return BSE_ERROR_NONE;
}

PROCEDURE (bse-categories-match, "Categories/Match") {
  HELP  = "List BSE categories according to a pattern match.";
  IN	= sfi_pspec_string ("pattern", "Pattern", "Pattern to match category, supports '*' and '?' wildcards.",
			    "*", SFI_PARAM_STANDARD);
  OUT   = bse_param_spec_boxed ("categories", "Categories", NULL, BSE_TYPE_CATEGORY_SEQ, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
      const GValue      *in_values,
      GValue            *out_values)
{
  /* extract parameter values */
  gchar *pattern   = sfi_value_get_string (in_values++);
  BseCategorySeq *cseq = NULL;
  
  /* check parameters */
  if (!pattern)
    return BSE_ERROR_PROC_PARAM_INVAL;
  
  cseq = bse_categories_match_typed (pattern, 0);
  if (!cseq)
    cseq = bse_category_seq_new ();
  
  /* set output parameters */
  bse_value_take_boxed (out_values++, cseq);
  
  return BSE_ERROR_NONE;
}

PROCEDURE (bse-category-from-id, "Categories/From ID") {
  HELP  = "Find a BSE category from it's unique ID.";
  IN	= sfi_pspec_int ("category_id", "Category ID", NULL,
			 1, 1, G_MAXINT, 1, SFI_PARAM_STANDARD);
  OUT   = bse_param_spec_boxed ("category", "Category", NULL, BSE_TYPE_CATEGORY, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
      const GValue      *in_values,
      GValue            *out_values)
{
  /* extract parameter values */
  guint id = sfi_value_get_int (in_values++);
  BseCategory *cat;

  cat = bse_category_from_id (id);
  
  /* set output parameters */
  bse_value_take_boxed (out_values++, cat);
  
  return BSE_ERROR_NONE;
}

static gboolean
categories_check_method (BseCategory *cat,
                         gpointer     data)
{
  GType *type_p = data;
  GType ptype = g_type_from_name (cat->type);
  gboolean match = FALSE;
  if (BSE_TYPE_IS_PROCEDURE (ptype))
    {
      BseProcedureClass *proc = g_type_class_ref (ptype);
      if (proc->n_in_pspecs >= 1 &&
          g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (proc->in_pspecs[0]), *type_p))
        match = TRUE;
      g_type_class_unref (proc);
    }
  return match;
}

PROCEDURE (bse-categories-match-method, "Categories/Match Method") {
  HELP  = "List BSE categories according to a pattern, of type procedure and applying to a certain object type.";
  IN	= sfi_pspec_string ("pattern", "Pattern", "Pattern to match category, supports '*' and '?' wildcards.",
			    "*", SFI_PARAM_STANDARD);
  IN	= sfi_pspec_string ("type", "Type", "Object base type for methods to conform to.",
			    NULL, SFI_PARAM_STANDARD);
  OUT   = bse_param_spec_boxed ("categories", "Categories", NULL, BSE_TYPE_CATEGORY_SEQ, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
      const GValue      *in_values,
      GValue            *out_values)
{
  /* extract parameter values */
  gchar *pattern   = sfi_value_get_string (in_values++);
  gchar *type_name = sfi_value_get_string (in_values++);
  GType  type      = type_name ? g_type_from_name (type_name) : 0;
  BseCategorySeq *cseq = NULL;
  
  /* check parameters */
  if (!pattern)
    return BSE_ERROR_PROC_PARAM_INVAL;
  
  cseq = bse_categories_match (pattern, BSE_TYPE_PROCEDURE, categories_check_method, &type);
  if (!cseq)
    cseq = bse_category_seq_new ();
  
  /* set output parameters */
  bse_value_take_boxed (out_values++, cseq);
  
  return BSE_ERROR_NONE;
}