summaryrefslogtreecommitdiff
path: root/mediasettings.h
blob: b6072d0ff272e1bf4b6e8a40a9c014770b0ec5d2 (plain)
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
/******************************************************
 *
 * audiosettings - get/set audio preferences from within Pd-patches
 * Copyright (C) 2010-2019 IOhannes m zmölnig
 *
 *   forum::für::umläute
 *
 *   institute of electronic music and acoustics (iem)
 *   university of music and dramatic arts, graz (kug)
 *
 *
 ******************************************************
 *
 * license: GNU General Public License v.3 or later
 *
 ******************************************************/
#include "m_pd.h"
#include "s_stuff.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAXNDEV 20
#define DEVDESCSIZE 80

#ifndef BUILD_DATE
# define BUILD_DATE "on " __DATE__ " at " __TIME__
#endif

/**
 * find EOS of a string of tokens
 * where EOS might be indicated by \0, }
 */
unsigned int findEOT(const char*s, unsigned int length) {
  unsigned int len=0;
  do {
    char c=s[len];
    len++;
    switch(c) {
    case '{':
      len+=findEOT(s+len, length-len);
      break;
    case '}':
      if('{'!=s[0])
        return len;
      else
        return len-1;
    case '\0':
      return len;
    }
  } while(len<length);
  return len;
}

/**
 * parse a string like "jack 3" into the name "jack" and the ID '3'
 */
static
int common_parsedriver(const char*str, const int inlen, 
                       char*name, int length, 
                       int *id) {
  /* find beginning of trailing number */
  int stop=inlen-1;
  int start1=0;
  int stop1=0;
  int start=0;
  int ret=0;

  while('\0'==str[stop] && stop>=0)
    stop--;

  start=stop;
  while(start>=0) {
    char c=str[start];
    if(c<48 || c>=57) break;
    start--;
  }
  if(start==stop || start<0)
    return ret;

  stop1=start;
  while(stop1>=0) {
    char c=str[stop1];
    if(!isspace(c))
      break;
    stop1--;
  }
  if(stop1<0)
    return ret;

  if((   str[start1]=='"' && str[stop1]=='"') 
     || (str[start1]=='\''  && str[stop1]=='\'')
     || (str[start1]=='{'  && str[stop1]=='}')
     ) {
    start1++;
    stop1--;
  }
  stop1+=2;
  if(stop1>=length)stop1=length-1;
  snprintf(name, stop1-start1, "%s", str+start1);
  ret=(1==sscanf(str+start, "%d", id));

  return ret;
}


static
void mediasettings_boilerplate(const char*name, const char*version) {
  post("%s%c%s", name, (version?' ':'\0'), version);
  verbose(0,"          compiled "BUILD_DATE"");
  verbose(0,"          Copyright © 2010-2016 IOhannes m zmölnig");
  verbose(0,"          for the IntegraLive project");
  verbose(0,"          institute of electronic music and acoustics (iem), KUG, Graz");
  verbose(0,"          published under the GNU General Public License version 3 or later");
}