|
diff --git a/experiments/alsa_midi_controller.c b/experiments/alsa_midi_controller.c
|
| ... |
| 9 |
|
9 |
|
| 10 |
static snd_seq_t *seq_handle; |
10 |
static snd_seq_t *seq_handle; |
| 11 |
static snd_seq_addr_t *ports; |
11 |
static snd_seq_addr_t *ports; |
| 12 |
static int rate = 44100; |
|
|
| 13 |
static int stop = 0; |
12 |
static int stop = 0; |
| 14 |
|
13 |
|
| 15 |
static void sighandler(int sig ATTRIBUTE_UNUSED) { |
14 |
static void sighandler(int sig ATTRIBUTE_UNUSED) { |
| ... |
| 18 |
|
17 |
|
| 19 |
int main(void) { |
18 |
int main(void) { |
| 20 |
fprintf(stdout, "Example: Reading MIDI input\n"); |
19 |
fprintf(stdout, "Example: Reading MIDI input\n"); |
| 21 |
|
|
|
| 22 |
snd_seq_t *seq_handle; |
|
|
| 23 |
|
20 |
|
| 24 |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { |
21 |
if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { |
| 25 |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
22 |
fprintf(stderr, "Error opening ALSA sequencer.\n"); |
| ... |
|
diff --git a/experiments/Makefile b/experiments/Makefile
|
|
|
1 |
CC := cc |
|
|
2 |
CFLAGS := -Wall |
|
|
3 |
LDFLAGS := -lm -ldl -lpthread -lasound |
|
|
4 |
|
|
|
5 |
all: \ |
|
|
6 |
soundfont_basic \ |
|
|
7 |
soundfont_from_file \ |
|
|
8 |
alsa_midi_controller \ |
|
|
9 |
watch_file_changes |
|
|
10 |
|
|
|
11 |
soundfont_basic: soundfont_basic.c |
|
|
12 |
$(CC) $(CFLAGS) soundfont_basic.c ../minisdl_audio.c $(LDFLAGS) -o soundfont_basic |
|
|
13 |
|
|
|
14 |
soundfont_from_file: soundfont_from_file.c |
|
|
15 |
$(CC) $(CFLAGS) soundfont_from_file.c ../minisdl_audio.c $(LDFLAGS) -o soundfont_from_file |
|
|
16 |
|
|
|
17 |
alsa_midi_controller: alsa_midi_controller.c |
|
|
18 |
$(CC) $(CFLAGS) alsa_midi_controller.c $(LDFLAGS) -o alsa_midi_controller |
|
|
19 |
|
|
|
20 |
watch_file_changes: watch_file_changes.c |
|
|
21 |
$(CC) $(CFLAGS) watch_file_changes.c $(LDFLAGS) -o watch_file_changes |
|
|
22 |
|
|
diff --git a/experiments/watch_file_changes.c b/experiments/watch_file_changes.c
|
|
|
1 |
#include <stdio.h> |
|
|
2 |
#include <unistd.h> |
|
|
3 |
#include <sys/stat.h> |
|
|
4 |
#include <time.h> |
|
|
5 |
|
|
|
6 |
int main(void) { |
|
|
7 |
struct stat file_stat; |
|
|
8 |
time_t last_mod_time; |
|
|
9 |
const char* file = "watch_file_changes.txt"; |
|
|
10 |
|
|
|
11 |
stat(file, &file_stat); |
|
|
12 |
last_mod_time = file_stat.st_mtime; |
|
|
13 |
|
|
|
14 |
while (1) { |
|
|
15 |
sleep(1); |
|
|
16 |
stat(file, &file_stat); |
|
|
17 |
if (file_stat.st_mtime != last_mod_time) { |
|
|
18 |
last_mod_time = file_stat.st_mtime; |
|
|
19 |
|
|
|
20 |
struct tm* time_info = localtime(&last_mod_time); |
|
|
21 |
char formatted_time[9]; |
|
|
22 |
strftime(formatted_time, sizeof(formatted_time), "%H:%M:%S", time_info); |
|
|
23 |
|
|
|
24 |
printf("File %s changed at %s\n", file, formatted_time); |
|
|
25 |
} |
|
|
26 |
} |
|
|
27 |
printf("hi\n"); |
|
|
28 |
return 0; |
|
|
29 |
} |
|
|
30 |
|