Ik heb het volgende stukje code. Ik krijg op regel 79 een sigmantation fault. Ik snap alleen niet hoe dit nou kan ontstaan. Eerder in de code gebruik ik hem ook al. Wanneer die fout ontstaat draait die in een while loop en in een if statement. Zou dit uit maken?
Wat ik in dit programma doe is een midi poort uitlezen voor input. Als code 74 binnenkomt moet het geluid harder en als code 73 binnen komt het geluid zachter. ./volume is dan het proggie waarmee je het volume harder en zachter kan zetten.
Dit draai ik allemaal onder linux.
Wat ik in dit programma doe is een midi poort uitlezen voor input. Als code 74 binnenkomt moet het geluid harder en als code 73 binnen komt het geluid zachter. ./volume is dan het proggie waarmee je het volume harder en zachter kan zetten.
Dit draai ik allemaal onder linux.
code:
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
| #include <iostream>
#include <signal.h>
#include "RtMidi.h"
#include <unistd.h>
#define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
bool done;
static void finish(int ignore){ done = true;}
void usage(void) {
// Error function in case of incorrect command-line
// argument specifications.
std::cout << "\nuseage: remini <port>\n";
std::cout << " where port = the device to use (default = 0).\n\n";
exit(0);
}
int main(int argc, char *argv[])
{
RtMidiIn *midiin = 0;
std::vector<unsigned char> message;
int nBytes;
double stamp;
char commando[256];
int volume;
// volume op normaal niveau instellen
volume = 20;
sprintf(commando, "./volume -r %d -l %d", volume, volume);
system(commando);
// Minimal command-line check.
if ( argc > 2 ) usage();
// RtMidiIn constructor
try {
midiin = new RtMidiIn();
}
catch (RtError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
// Check available ports vs. specified.
unsigned int port = 0;
unsigned int nPorts = midiin->getPortCount();
if ( argc == 2 ) port = (unsigned int) atoi( argv[1] );
if ( port >= nPorts ) {
delete midiin;
std::cout << "Invalid port specifier!\n";
usage();
}
try {
midiin->openPort( port );
}
catch (RtError &error) {
error.printMessage();
delete midiin;
exit(1);
}
// Don't ignore sysex, timing, or active sensing messages.
midiin->ignoreTypes( false, false, false );
// Install an interrupt handler function.
done =false;
(void) signal(SIGINT, finish);
// Periodically check input queue.
while ( !done ) {
stamp = midiin->getMessage( &message );
nBytes = message.size();
if ((int)message[1] == 74 && (int)message[0] == 144 && (volume < 100) && (nBytes > 0)) {
volume = volume + 5;
sprintf(commando, "./volume -r %d -l %d", volume, volume);
system(commando);
}
if ((int)message[1] == 73 && (int)message[0] == 144 && (volume > 10) && (nBytes > 0)) {
volume = volume - 5;
sprintf(commando, "./volume -r %d -l %d", volume, volume);
system(commando);
}
SLEEP( 10 );
}
delete midiin;
return 0;
} |
[ Voor 11% gewijzigd door harmageddon op 25-05-2005 14:16 ]
Aap!