some PERL playing with JSON
[mirrors/Programs.git] / c / condrum / condrum.c
1 #include "bass.h"
2 #include <conio.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 //#define DEBUG //Uncomment for debuging
7 #define MAX_CHANS 128 //Maximum lenght of line in loopfile (recomended 128 or 64)
8
9
10 // display error messages
11 void Error(const char *text)
12 {
13 printf("Error(%d): %s\n",BASS_ErrorGetCode(),text);
14 BASS_Free();
15 exit(0);
16 }
17
18 int main(int argc, char *argv)
19 {
20 if (!BASS_Init(-1,44100,0,0,NULL)) {
21 // couldn't initialize device
22 printf("Error -1- Init");
23 return(0);
24 }
25
26 char loopf[] = "loop.txt";
27 int i = 0, t = 0, sch=sizeof(char), sleep = 500; //t = total chanells
28 HSAMPLE sample[MAX_CHANS];
29 HCHANNEL channel[MAX_CHANS];
30 char *line, bar[MAX_CHANS] = {'1', '0'};
31 line = malloc(MAX_CHANS*sch);
32 FILE *loop;
33
34 loop = fopen(loopf, "r");
35
36 printf("ConDrummer\nSimple Console Drumstation for Windows\nHarvie 2oo7\nFile: %s\n\n", loopf);
37
38 while(1) {
39 fgets(line, MAX_CHANS, loop);
40 if(strstr(line, ";")) {
41 //printf("%s", line+sch);
42 continue;
43 }
44 if(strstr(line, "!")) {
45 printf("%s", line+sch);
46 continue;
47 }
48 if(strstr(line, ":")) {
49 line++;
50 memset( line+strlen(line)-1, 0, 1);
51 printf("Sample: %i = %s\n", i, line);
52 sprintf(line, "%s", line);
53 sample[i] = BASS_SampleLoad(FALSE, line, 0, 0, 100, BASS_SAMPLE_MONO);
54 channel[i] = BASS_SampleGetChannel(sample[i], FALSE); // get a sample channel
55 i++;
56 t++;
57 line--;
58 continue;
59 }
60
61 if(strstr(line, "?")) {
62 sleep = atoi(line+sch);
63 #ifdef DEBUG
64 printf("Delay: %i\n", sleep);
65 #endif
66 continue;
67 }
68 if(strstr(line, "@")) {
69 sleep = atoi(line+sch);
70 sleep = (60*1000)/(sleep*4);
71 #ifdef DEBUG
72 printf("Delay: %i\n", sleep);
73 #endif
74 continue;
75 }
76
77 if(strstr(line, "#")) {
78 break;
79 }
80 }
81
82 printf("Channels total: %i\nPlaying...\n\n", t);
83
84 //DrumLOOP
85 i = 0;
86 while(1) {
87 i = 0;
88 while(1) {
89 fgets(line, MAX_CHANS, loop);
90 if(strstr(line, "-")) {
91 sprintf(bar, "%s\x0", (line+sch));
92 break;
93 }
94 if(feof(loop)) {
95 #ifdef DEBUG
96 printf("rewind\n"); //Debug
97 #endif
98 rewind(loop);
99 while(1) {
100 fgets(line, MAX_CHANS, loop);
101 if(strstr(line, "#")) { break; }
102 }
103 }
104 }
105
106 for(i = 0;i<t;i++) {
107 if (bar[i] == '1') {
108 BASS_ChannelPlay(channel[i], FALSE);
109 }
110 }
111
112 Sleep(sleep);
113
114 }
115
116 BASS_Free();
117 return(0);
118 }
119
120 /*
121
122 TODO (unsorted):
123 - better samples (Audacity or ER-0)
124 - better (user friendly) loopfile syntax
125 - BPM 2 sleep delay calculator
126 - better icon
127 - manual
128 - sample patterns
129 - Linux port (SDL???)
130 - volume for each beat
131 - recording to wav
132
133 */
134
135
136
This page took 1.16967 seconds and 4 git commands to generate.