File: main.c

package info (click to toggle)
csound 1%3A6.18.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 63,220 kB
  • sloc: ansic: 192,643; cpp: 14,149; javascript: 9,654; objc: 9,181; python: 3,376; java: 3,337; sh: 1,840; yacc: 1,255; xml: 985; perl: 635; lisp: 411; tcl: 341; lex: 217; makefile: 128
file content (121 lines) | stat: -rw-r--r-- 3,243 bytes parent folder | download | duplicates (3)
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
/*
    beats/main.c:

    Copyright (C) 2009,2010 John ffitch

    This file is part of Csound.

    The Csound 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.

    Csound 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.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "beats.h"

FILE *myout;
extern FILE *yyin;
int debug = 0;

double pt[13] = { 8.1757989156,  8.6619572180,  9.1770239974,  9.7227182413,
                 10.3008611535, 10.9133822323, 11.5623257097, 12.2498573744,
                 12.9782717994, 13.7500000000, 14.5676175474, 15.4338631643,
                 16.3516084259
};

INSTR *instr;

int main(int argc, char **argv)
{
    char buf[80];
    time_t timep;
    struct tm tm;
    instr = NULL;
    bpm = 60;
    permeasure = 4;
    yydebug = 0;
    yyin = stdin;
    /* Argument decode:  A litte dodgy.  In csound should have zero args */
    if (argc==3) {
      yyin = fopen(argv[1], "r");
      myout = fopen(argv[2], "w");
    }
    else if (argc==4) {
      debug = 1;
      yyin = fopen(argv[2], "r");
      myout = fopen(argv[3], "w");
    }
    else if (argc==2) {
      yydebug = debug = 1;
      myout = stdout;
    } else
      myout = stdout;
    if (yyin==NULL || myout==NULL) {
      fprintf(stderr, "Failed to open files\n");
      exit(1);
    }
    time(&timep);

#ifndef LINUX
    {
      struct tm *date_ptr = localtime(&timep);
      memcpy(&tm, date_ptr, sizeof(struct tm));
    }
#else
    localtime_r(&timep, &tm);
#endif

    strftime(buf, 80, "%a %Y %b %d %H:%M:%S", &tm);
    fprintf(myout, ";;; Generated by beats on %s\n\n", buf);
    instr = (INSTR*) calloc(1, sizeof(INSTR));
    instr->next = instr;
    instr->p = (double*) calloc(6, sizeof(double));
    instr->largest = 5;
    yyparse();
    return 0;
}

INSTR *find_instr(int n)
{                               /* search circular list fot instr n */
    INSTR *p = instr;
    do {
      if (n == p->n) return (instr = p);
      p = p->next;
    } while (p != instr);
    /* Not there so add at start of list */
    p = (INSTR*) calloc(1, sizeof(INSTR));
    p->next = instr->next;
    instr->next = p;
    p->n = n;
    return (instr=p);
}

void print_instr_structure(void)
{
    INSTR *p = instr;
    fprintf(stderr, "Instruments\n");
    do {
      fprintf(stderr, "%d: last p is %d, array is at %p\n", p->n, p->largest, p->p);
      if (p->largest>5) {
        int j;
        for (j=6; j<=p->largest; j++)
          fprintf(stderr, " %d->%lf", j, p->p[j]);
        fprintf(stderr, "\n");
        p = p->next;
      }
    } while (p!=instr);
    fprintf(stderr, "\n end \n");
}