Skip to content

Commit

Permalink
autoformat + edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
thelowsunoverthemoon committed Jan 12, 2024
1 parent 038241b commit 0165bb2
Show file tree
Hide file tree
Showing 23 changed files with 689 additions and 399 deletions.
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
BasedOnStyle: Microsoft
Cpp11BracedListStyle: 'false'
PointerAlignment: Left
SpaceBeforeCpp11BracedList: 'true'
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: Consecutive
AlwaysBreakAfterDefinitionReturnType: All

...
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div align="center">

<a href="">![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/thelowsunoverthemoon/mahler.c/run_unit_tests.yml)</a>
<a href="">![Static Badge](https://img.shields.io/badge/code_coverage-100%25-%23327da8)</a>
<a href="">[![Static Badge](https://img.shields.io/badge/coverage-100%25-%23327da8)](https://github.com/thelowsunoverthemoon/mahler.c/tree/master/test)</a>
<a href="">[![Stack Overflow Badge](https://img.shields.io/badge/docs-purple)](https://github.com/thelowsunoverthemoon/mahler.c/blob/master/doc/README.md)</a>

<a href="">[![Static Badge](https://img.shields.io/badge/clang--format-brown)](https://github.com/thelowsunoverthemoon/mahler.c/tree/master/.clang-format)</a>
</div>

<p align="center">Simple library for Western music theory in C99</p>
Expand Down
4 changes: 2 additions & 2 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Returns a ```struct mah_chord``` with root ```root``` and type ```type```. You m
```C
void mah_return_chord(struct mah_note const notes[], int num, struct mah_chord_result_list* list, struct mah_chord_check* custom, enum mah_error* err)
```
Populates the ```results``` member of ```list``` with the potential chords containing every note in ```notes``` . ```num``` is the number of entries in ```notes```. The ```pitch``` of each ```struct mah_chord_result``` note is 0. Defining ```custom``` will check for chords specified in ```struct chord_list```. Set to ```MAH_CHORD_LIST_DEFAULT``` if you would like to use the predefined chord list (see Predefined). Returned results include enharmonic results (eg, Bb+ triad is also A#+ triad). If there are more possible chords than ```max``` member of ```list```, the ```err``` is set to ```MAH_ERROR_OVERFLOW_CHORD_RETURN```. This function tests for chords up to one accidental (eg, flat, natural, and sharp).
Populates the ```results``` member of ```list``` with the potential chords containing every note in ```notes``` . ```num``` is the number of entries in ```notes```. The ```pitch``` of each ```struct mah_chord_result``` note is 0. Defining ```custom``` will check for chords specified in ```struct chord_list```. Set to ```MAH_CHORD_LIST_DEFAULT``` if you would like to use the predefined chord list (see Predefined). Returned results include enharmonic results (eg, Bb+ triad is also A#+ triad), in the range of non theoretical keys. If there are more possible chords than ```max``` member of ```list```, the ```err``` is set to ```MAH_ERROR_OVERFLOW_CHORD_RETURN```. This function tests for chords up to one accidental (eg, flat, natural, and sharp).

---

Expand Down Expand Up @@ -514,7 +514,7 @@ Returns the accidental of the given ```note``` based on ```key```. Note that thi
#### mah_write_note()

```C
char* mah_write_note(struct mah_note const note, char buf[], size_t size, enum mah_error* err)
char* mah_write_note(struct mah_note const note, char buf[], int size, enum mah_error* err)
```
This returns the buffer with ```note``` in text up to 4 accidentals (ie, ````bbbb -> ####````). If ```acci``` exceeds that range or the ```note``` member is invalid, the ```err``` is set to ```MAH_ERROR_INVALID_PRINT_NOTE```. If the given buffer is not large enough, the ```err``` is set to ```MAH_ERROR_OVERFLOW_PRINT_NOTE```.
Expand Down
26 changes: 15 additions & 11 deletions ex/chart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdio.h>
#include "mahler.h"
#include <stdio.h>

// Create a Major Scale Chart starting from C0 //
/*
Expand All @@ -13,23 +13,27 @@
C1 D1 E1 F1 G1 A1 B1 C2
*/

int
main(void)
int main(void)
{
struct mah_note sc_notes[8];
struct mah_scale scale = mah_get_scale(
(struct mah_note) {MAH_C, MAH_NATURAL, 0}, &MAH_MAJOR_SCALE, sc_notes, MAH_ASCEND, NULL
(struct mah_note) {
MAH_C,
MAH_NATURAL,
0,
},
&MAH_MAJOR_SCALE, sc_notes, MAH_ASCEND, NULL,
);

char disp[MAH_DISP_LEN];
for (int i = 0; i < scale.size; i++) {

for (int i = 0; i < scale.size; i++)
{

struct mah_note temp_notes[8];
struct mah_scale temp = mah_get_scale(
scale.notes[i], &MAH_MAJOR_SCALE, temp_notes, MAH_ASCEND, NULL
);

for (size_t j = 0; j < scale.size; j++) {
struct mah_scale temp = mah_get_scale(scale.notes[i], &MAH_MAJOR_SCALE, temp_notes, MAH_ASCEND, NULL);

for (int j = 0; j < scale.size; j++)
{
printf("%-3s ", mah_write_note(temp.notes[j], disp, MAH_DISP_LEN, NULL));
}
putchar('\n');
Expand Down
27 changes: 13 additions & 14 deletions ex/fifth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdio.h>
#include "mahler.h"
#include <stdio.h>

// Generate the Major Circle of 5ths for 12 iterations //
/*
Expand All @@ -21,28 +21,27 @@

void gen_circle_fifths(struct mah_note buf[], int iter);

int
main(void)
int main(void)
{

struct mah_note buf[GEN_SIZE];
gen_circle_fifths(buf, GEN_SIZE);

char disp[MAH_DISP_LEN];
for (int i = 0; i < GEN_SIZE; i++) {
for (int i = 0; i < GEN_SIZE; i++)
{
struct mah_key_sig key = mah_get_key_sig(buf[i], MAH_MAJOR_KEY);
printf("%s -> %d\n", mah_write_note(buf[i], disp, MAH_DISP_LEN, NULL), key.alter);
}
}

void
gen_circle_fifths(struct mah_note buf[], int iter)
void gen_circle_fifths(struct mah_note buf[], int iter)
{
struct mah_note prev = (struct mah_note) {MAH_C, MAH_NATURAL, 0};
buf[0] = prev;

for (int i = 1; i < iter; i++) {
buf[i] = prev = mah_get_inter(prev, (struct mah_interval) {5, MAH_PERFECT}, NULL);
struct mah_note prev = (struct mah_note) { MAH_C, MAH_NATURAL, 0 };
buf[0] = prev;

for (int i = 1; i < iter; i++)
{
buf[i] = prev = mah_get_inter(prev, (struct mah_interval) { 5, MAH_PERFECT }, NULL);
}

}
28 changes: 13 additions & 15 deletions ex/trans.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stdio.h>
#include "mahler.h"
#include <stdio.h>

// Transpose Melody up Perfect 5th //
/*
Expand All @@ -10,31 +10,29 @@

void transpose(struct mah_note mel[], struct mah_note buf[], int size, struct mah_interval inter);

int
main(void)
int main(void)
{
struct mah_note mel[] = {
{MAH_C, MAH_NATURAL, 3},
{MAH_D, MAH_FLAT, 3},
{MAH_F, MAH_SHARP, 4},
{ MAH_C, MAH_NATURAL, 3 },
{ MAH_D, MAH_FLAT, 3 },
{ MAH_F, MAH_SHARP, 4 },
};

struct mah_note buf[BUF_SIZE];
int mel_len = sizeof(mel) / sizeof(*mel);
transpose(mel, buf, mel_len, (struct mah_interval) {
5, MAH_PERFECT
});

transpose(mel, buf, mel_len, (struct mah_interval) { 5, MAH_PERFECT });

char disp[MAH_DISP_LEN];
for (int i = 0; i < mel_len; i++) {
for (int i = 0; i < mel_len; i++)
{
printf("%s ", mah_write_note(buf[i], disp, MAH_DISP_LEN, NULL));
}
}

void
transpose(struct mah_note* mel, struct mah_note* buf, int size, struct mah_interval inter)
void transpose(struct mah_note* mel, struct mah_note* buf, int size, struct mah_interval inter)
{
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
{
buf[i] = mah_get_inter(mel[i], inter, NULL);
}
}
Loading

0 comments on commit 0165bb2

Please sign in to comment.