Renamed to experiments and added watch for changes
| Author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-08 06:05:51 +0200 |
| Committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-08 06:05:51 +0200 |
| Commit | 65ffdf410ca5c36f059bee8619f87147f802a82e (patch) |
|
-rw-r--r-- |
.gitignore | 4 | |
-rw-r--r-- |
examples/Makefile | 5 | |
-rw-r--r-- |
experiments/soundfont_basic.c | 0 | |
-rw-r--r-- |
experiments/soundfont_from_file.c | 0 | |
-rw-r--r-- |
experiments/alsa_midi_controller.c | 0 | |
-rw-r--r-- |
experiments/.gitignore | 5 | |
-rw-r--r-- |
experiments/Makefile | 22 | |
-rw-r--r-- |
experiments/watch_file_changes.c | 30 | |
-rw-r--r-- |
experiments/watch_file_changes.txt | 3 |
9 files changed, 60 insertions, 12 deletions
| diff --git a/.gitignore b/.gitignore | |||
| 1 | examples/example1 |
||
| 2 | examples/example2 |
||
| 3 | examples/example3 |
||
| 4 | examples/example4 |
||
| 5 | ttdaw |
1 | ttdaw |
| 6 | 2 | ||
| diff --git a/examples/Makefile b/examples/Makefile | |||
| 1 | tests: |
||
| 2 | $(CC) -Wall example1.c ../minisdl_audio.c -lm -ldl -lpthread -o example1 |
||
| 3 | $(CC) -Wall example2.c ../minisdl_audio.c -lm -ldl -lpthread -o example2 |
||
| 4 | $(CC) -Wall example4.c -lasound -lm -o example4 |
||
| 5 | |||
| diff --git a/experiments/soundfont_basic.c b/experiments/soundfont_basic.c | |||
| ... |
| diff --git a/experiments/soundfont_from_file.c b/experiments/soundfont_from_file.c | |||
| ... |
| 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/.gitignore b/experiments/.gitignore | |||
| 1 | alsa_midi_controller |
||
| 2 | soundfont_basic |
||
| 3 | soundfont_from_file |
||
| 4 | watch_file_changes |
||
| 5 | |||
| 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 | |||
| diff --git a/experiments/watch_file_changes.txt b/experiments/watch_file_changes.txt | |||
| 1 | test1 |
||
| 2 | test2 |
||
| 3 | |||