-
Notifications
You must be signed in to change notification settings - Fork 3
/
Visualizer.cpp
103 lines (87 loc) · 2.88 KB
/
Visualizer.cpp
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
// std includes
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <string>
#include <iostream>
// PortAudio includes
#include <sndfile.h>
#include <portaudio.h>
// project includes
#include "graphics_helper.h"
#include "audio_helper.h"
#include "Visualizer.h"
#include "ArgMapper.h"
extern Packet *sharedBuffer;
extern bool finished;
const char simpleArgs[] = {'c', 't', 'm', 'h'};
const char compoundArgs[] = {'f', 'w', 's', 'r'};
ArgMapper mapper;
void printUsage(const char *name){
// TODO - add a -f option for file input, default to line in
printf("Usage: %s [-f soundfile] [-w hamming|hann|cosine] [-c] [-s circle|line|wave] [-t] [-r auto|mouse]\n", name);
exit(1);
}
void printHelpMessage(const char *name){
// unimplemented, write (or generate) a help message here
printUsage(name);
}
int findInString(char needle, char *haystack, int haystackLen){
for(int i = 0; i < haystackLen; i++){
if(haystack[i] == needle){
return i;
}
}
return -1;
}
void processArgs(int numInputArgs, char *strings[]){
int curLength = 0, i = 0, j = 0;
// TODO - check for unknown arguments
for(i = 0; i < numInputArgs; i++){
if(strings[i][0] == '-'){
curLength = strlen(strings[i]);
for(j = 0; j < sizeof(simpleArgs) / sizeof(char); j++){
if(findInString(simpleArgs[j], strings[i], strlen(strings[i])) > 0){
if(simpleArgs[j] == 'h'){
printHelpMessage(strings[0]);
}
mapper.setSimpleArg(simpleArgs[j], true);
} else if(!mapper.getSimpleArg(simpleArgs[j])){ // don't unset
mapper.setSimpleArg(simpleArgs[j], false);
}
}
for(j = 0; j < sizeof(compoundArgs) / sizeof(char); j++){
// disallow compound args in clusters
if(findInString(compoundArgs[j], strings[i], strlen(strings[i])) != -1){
if(curLength > 2 || i+1 == numInputArgs){
printUsage(strings[0]);
} else {
mapper.setCompoundArg(compoundArgs[j], strings[i+1]);
}
}
}
}
}
}
int main(int argc, char *argv[]){
PaStream *stream;
sharedBuffer = (Packet *)malloc(sizeof(Packet) * BUFFER_SIZE);
processArgs(argc, argv);
if (!startAudio(stream, mapper.getCompoundArg('f').c_str(),
mapper.getCompoundArg('w').c_str())){
exit(1);
}
// TODO - get rid of glut stuff and set up context manually
setupGlut(argc, argv);
GLenum err = glewInit();
if (GLEW_OK != err){
fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
exit(1);
}
SetupRC();
glutMainLoop();
free(sharedBuffer);
endAudio(stream);
exit(0);
}