Skip to content

Commit

Permalink
Don't draw item when value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhadeepJasu committed Mar 21, 2022
1 parent 6bd293b commit e48d735
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ subhadeepjasu
null.d
~*
*~
.~lock*
.~lock*
xtleak.kcg.*
9 changes: 5 additions & 4 deletions src/Core/MidiPlayers/StyleEngine/style_analyser.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ int time_stamp_index;
int time_signature_n;
int time_signature_d;

char* copyright_string;
char config_delimiters[3] = { ':', ';', ',' };

char* copyright_string;

int
style_analyser (char* style)
Expand Down Expand Up @@ -92,7 +93,7 @@ style_analyser (char* style)
}
// Get Measure
char *e;
e = strchr(string, ':');
e = strchr(string, config_delimiters[0]);
int index_measure = (int)(e - string);
int measure = 0;
if (index_measure < length && index_measure > 0)
Expand All @@ -106,7 +107,7 @@ style_analyser (char* style)
// Get Tempo
int tempo = 0;
char* f;
f = strchr(string, ';');
f = strchr(string, config_delimiters[1]);
int index_tempo = (int)(f - string);
if (index_tempo < length && index_tempo > 0)
{
Expand All @@ -124,7 +125,7 @@ style_analyser (char* style)
// Get Scale Type (whether the style is recorded in major or minor)
int chord_type = 0;
char* g;
g = strchr(string, ',');
g = strchr(string, config_delimiters[2]);
int index_chord_type = (int)(g - string);
if (index_chord_type < length && index_chord_type > 0)
{
Expand Down
124 changes: 82 additions & 42 deletions src/Core/Utils/chord_finder.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ chord_finder_infer (int key, int on, int* type)
probable_root = i;
}
}
printf("\n");
for (int i = 0; i < 144; i++) {\
// printf("\n");
for (int i = 0; i < 144; i++)
{
chord_possibility[i] = 0;
}

Expand All @@ -33,143 +34,179 @@ chord_finder_infer (int key, int on, int* type)
if (n_keys < 4)
{
// Major
for (; i < 5; i++) {
for (; i < 5; i++)
{
chord_possibility [i] = 6 * key_track[i] + key_track[i + 4] + key_track[i + 7]; // One way to play it
}
/* ^
* |
* |
* Root contribution
*/
for (; i < 9; i++) {
for (; i < 9; i++)
{
chord_possibility [i] = key_track[i - 5] + 6 * key_track[i] + key_track[i + 4]; // Another way to play it
}
for (; i < 12; i++) {
for (; i < 12; i++)
{
chord_possibility [i] = key_track[i - 8] + key_track[i - 5] + 6 * key_track[i]; // Yet another way to play it
}

// minor
for (; i < 17; i++) {
for (; i < 17; i++)
{
chord_possibility [i] = 6 * key_track[i - 12] + key_track[i - 12 + 3] + key_track[i - 12 + 7];
}
for (; i < 21; i++) {
for (; i < 21; i++)
{
chord_possibility [i] = key_track[i - 12 - 5] + 6 * key_track[i - 12] + key_track[i - 12 + 3];
}
for (; i < 24; i++) {
for (; i < 24; i++)
{
chord_possibility [i] = key_track[i - 12 - 9] + key_track[i - 12 - 5] + 6 * key_track[i - 12];
}

// diminished
for (; i < 29; i++) {
for (; i < 29; i++)
{
chord_possibility [i] = 6 * key_track[i - 24] + key_track[i - 24 + 3] + key_track[i - 24 + 6];
}
for (; i < 33; i++) {
for (; i < 33; i++)
{
chord_possibility [i] = key_track[i - 24 + 6] + 6 * key_track[i - 24] + key_track[i - 24 + 3];
}
for (; i < 36; i++) {
for (; i < 36; i++)
{
chord_possibility [i] = key_track[i - 24 - 9] + key_track[i - 24 - 6] + 6 * key_track[i - 24];
}

// suspended 2
for (; i < 41; i++) {
for (; i < 41; i++)
{
chord_possibility [i] = 6 * key_track[i - 36] + key_track[i - 36 + 2] + key_track[i - 36 + 7];
}
for (; i < 45; i++) {
for (; i < 45; i++)
{
chord_possibility [i] = key_track[i - 36 - 5] + 6 * key_track[i - 36] + key_track[i - 36 + 2];
}
for (; i < 48; i++) {
for (; i < 48; i++)
{
chord_possibility [i] = key_track[i - 36 - 10] + key_track[i - 36 - 5] + 6 * key_track[i - 36];
}

// suspended 4
for (; i < 53; i++) {
for (; i < 53; i++)
{
chord_possibility [i] = (i - 48 == probable_root && n_keys > 2 ? 7 : 6) * key_track[i - 48] + key_track[i - 48 + 5] + key_track[i - 48 + 7];
}
for (; i < 57; i++) {
for (; i < 57; i++)
{
chord_possibility [i] = key_track[i - 48 - 5] + (i - 48 == probable_root && n_keys > 2 ? 7 : 6) * key_track[i - 48] + key_track[i - 48 + 5];
}
for (; i < 60; i++) {
for (; i < 60; i++)
{
chord_possibility [i] = key_track[i - 48 - 7] + key_track[i - 48 - 5] + (i - 48 == probable_root && n_keys > 2 ? 7 : 6) * key_track[i - 48];
}

// augmented
for (; i < 65; i++) {
for (; i < 65; i++)
{
chord_possibility [i] = 6 * key_track[i - 60] + key_track[i - 60 + 4] + key_track[i - 60 + 8];
}
for (; i < 69; i++) {
for (; i < 69; i++)
{
chord_possibility [i] = key_track[i - 60 - 4] + 6 * key_track[i - 60] + key_track[i - 60 + 4];
}
for (; i < 72; i++) {
for (; i < 72; i++)
{
chord_possibility [i] = key_track[i - 60 - 8] + key_track[i - 60 - 4] + 6 * key_track[i - 60];
}
}
else if (n_keys == 4)
{
// Dominant Sixth
for (i = 72; i < 77; i++) {
for (i = 72; i < 77; i++)
{
chord_possibility [i] = 6 * key_track[i - 72] + key_track[i - 72 + 4] + key_track[i - 72 + 7] + key_track[i - 72 + 9];
}
for (; i < 81; i++) {
for (; i < 81; i++)
{
chord_possibility [i] = key_track[i - 72 - 5] + key_track[i - 72 - 3] + 6 * key_track[i - 72] + key_track[i - 72 + 4];
}
for (; i < 84; i++) {
for (; i < 84; i++)
{
chord_possibility [i] = key_track[i - 72 - 8] + key_track[i - 72 - 5] + key_track[i - 72 - 3] + 6 * key_track[i - 72];
}

// Dominant Seventh
for (; i < 89; i++) {
for (; i < 89; i++)
{
chord_possibility [i] = 6 * key_track[i - 84] + key_track[i - 84 + 4] + key_track[i - 84 + 7] + key_track[i - 84 + 10];
}
for (; i < 93; i++) {
for (; i < 93; i++)
{
chord_possibility [i] = key_track[i - 84 - 5] + key_track[i - 84 - 2] + 6 * key_track[i - 84] + key_track[i - 84 + 4];
}
for (; i < 96; i++) {
for (; i < 96; i++)
{
chord_possibility [i] = key_track[i - 84 - 8] + key_track[i - 84 - 5] + key_track[i - 84 - 2] + 6 * key_track[i - 84];
}

// Major Seventh
for (; i < 101; i++) {
for (; i < 101; i++)
{
chord_possibility [i] = 6 * key_track[i - 96] + key_track[i - 96 + 4] + key_track[i - 96 + 7] + key_track[i - 96 + 11];
}
for (; i < 105; i++) {
for (; i < 105; i++)
{
chord_possibility [i] = key_track[i - 96 - 5] + key_track[i - 96 - 1] + 6 * key_track[i - 96] + key_track[i - 96 + 4];
}
for (; i < 108; i++) {
for (; i < 108; i++)
{
chord_possibility [i] = key_track[i - 96 - 8] + key_track[i - 96 - 5] + key_track[i - 96 - 1] + 6 * key_track[i - 96];
}

// minor seventh
for (; i < 113; i++) {
for (; i < 113; i++)
{
chord_possibility [i] = 6 * key_track[i - 108] + key_track[i - 108 + 3] + key_track[i - 108 + 7] + key_track[i - 108 + 10];
}
for (; i < 117; i++) {
for (; i < 117; i++)
{
chord_possibility [i] = key_track[i - 108 - 5] + key_track[i - 108 - 2] + 6 * key_track[i - 108] + key_track[i - 108 + 3];
}
for (; i < 120; i++) {
for (; i < 120; i++)
{
chord_possibility [i] = key_track[i - 108 - 9] + key_track[i - 108 - 5] + key_track[i - 108 - 2] + 6 * key_track[i - 108];
}

// add9
for (; i < 125; i++) {
for (; i < 125; i++)
{
chord_possibility [i] = 6 * key_track[i - 120] + key_track[i - 120 + 4] + key_track[i - 120 + 7] + key_track[i - 120 + 2];
}
for (; i < 129; i++) {
for (; i < 129; i++)
{
chord_possibility [i] = key_track[i - 120 - 5] + key_track[i - 120 + 2] + 6 * key_track[i - 120] + key_track[i - 120 + 4];
}
for (; i < 132; i++) {
for (; i < 132; i++)
{
chord_possibility [i] = key_track[i - 120 - 8] + key_track[i - 120 - 5] + key_track[i - 120 - 10] + 6 * key_track[i - 120];
}
}
else if (n_keys == 5)
{
// Dominant 9th
for (; i < 137; i++) {
for (; i < 137; i++)
{
chord_possibility [i] = 6 * key_track[i - 132] + key_track[i - 132 + 4] + key_track[i - 132 + 7] + key_track[i - 132 + 10] + key_track[i - 132 + 2];
}
for (; i < 141; i++) {
for (; i < 141; i++)
{
chord_possibility [i] = key_track[i - 132 - 5] + key_track[i - 132 - 2] + key_track[i - 120 + 2] + 6 * key_track[i - 132] + key_track[i - 132 + 4];
}
for (; i < 144; i++) {
for (; i < 144; i++)
{
chord_possibility [i] = key_track[i - 132 - 8] + key_track[i - 132 - 5] + key_track[i - 132 - 2] + 6 * key_track[i - 132] + key_track[i - 120 - 10];
}
}
Expand All @@ -179,9 +216,11 @@ chord_finder_infer (int key, int on, int* type)
int max_i = n_keys < 4 ? 72 : n_keys == 4 ? 132 : 144;
int max = -1;
int max_index = 0;
for (; i < max_i; i++) {
printf("%d ", chord_possibility[i]);
if (max < chord_possibility[i]) {
for (; i < max_i; i++)
{
// printf("%d ", chord_possibility[i]);
if (max < chord_possibility[i])
{
max = chord_possibility[i];
max_index = i;
}
Expand Down Expand Up @@ -242,7 +281,8 @@ chord_finder_infer (int key, int on, int* type)
}

// Return the root note
if (max > 0) {
if (max > 0)
{
if (max_index >= 0 && max_index <= 6)
{
return max_index;
Expand Down
21 changes: 12 additions & 9 deletions src/Shell/Widgets/StyleItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
tempo_label.get_style_context ().add_class ("menu-item-description");
tempo_label.halign = Gtk.Align.END;

var copyright_button = new Gtk.Button.from_icon_name ("text-x-copying-symbolic", Gtk.IconSize.BUTTON) {
margin_top = 6,
margin_start = 4,
margin_end = 4,
tooltip_text = accomp_style.copyright_notice
};
copyright_button.get_style_context ().add_class ("menu-item-icon");

var category_label = new Gtk.Label ("");
var style_grid = new Gtk.Grid ();
if (show_category) {
Expand All @@ -40,7 +32,18 @@
style_grid.attach (style_label, 0, 0, 1, 2);
style_grid.attach (category_label, 1, 0, 2, 1);
style_grid.attach (tempo_label, 1, 1, 1, 1);
style_grid.attach (copyright_button, 2, 1, 1, 1);

if (accomp_style.copyright_notice != null && accomp_style.copyright_notice != "") {
var copyright_button = new Gtk.Button.from_icon_name ("text-x-copying-symbolic", Gtk.IconSize.BUTTON) {
margin_top = 6,
margin_start = 4,
margin_end = 4,
tooltip_text = accomp_style.copyright_notice
};
copyright_button.get_style_context ().add_class ("menu-item-icon");
style_grid.attach (copyright_button, 2, 1, 1, 1);
}

this.add (style_grid);
}
}
Expand Down

0 comments on commit e48d735

Please sign in to comment.