Generic Just Intonation Tuner

need a feature, suggest here

Re: Generic Just Intonation Tuner

Postby Broomy » Thu Dec 07, 2017 8:13 pm

I've added fprintf lines to the code, see [url]commit[/url].
line 695 in gxtuner.cpp is the culprit.
I want something that isn't working.
What I want is an 2d array[53][25] which looks something like this:
Cbbb--7\0
Db+21\0
E#-\0
etc.

From which the tuner can choose the corresponding note depending on the frequency.

The hardest part is that I need a way to construct the notenames.
The note name can be divided in several parts:
Basename - first comma(s) - second comma(s) - third comma(s) - etc
The basename is always one character but the comma's can be either nothing or several of the same.
Here are some examples:
1. D //only basename, commas are NULL
2. Eb77 // basename, first comma is one "b", second comma is NULL, third comma is two times "77".

What would you advice?

Kind regards!

Hans
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby brummer10 » Fri Dec 08, 2017 5:52 am

Hi Hans

Well, memory management within C could be a pitta,
You need to allocate the memory for tuner->tempscaletranslatednames. Right now, it is just a pointer, but it points to nothing. So when you try to wrote on it, there is no space to store the values.

First of, change in gxtuner.h the definition from
char** tempscaletranslatednames;
to
char* tempscaletranslatednames[MAXSCALENOTES]; //replace MAXSCALENOTES with the size you really need.

Then you could allocate the memory in gx_tuner_init like that:

Code: Select all
    for(int i=0;i<MAXSCALENOTES;i++) {
    tuner->tempscaletranslatednames[i] = (char*)malloc(sizeof(char*) ); // allocate
    memset(tuner->tempscaletranslatednames[i], 0, sizeof(char));
    }


That initialize the memory for each char in the array. Again replace MAXSCALENOTES with the needed MAXNOTES.

Now you could construct the Note array and the program will run up to Fase V creating names
were the next segfault happen.
Again, memory corruption.

(For free the memory we could later add a function which free the used memory on program exit. But first, the construction must work. :) )
User avatar
brummer10
Site Admin
 
Posts: 782
Joined: Thu Mar 26, 2009 6:57 pm

Re: Generic Just Intonation Tuner

Postby Broomy » Sat Dec 09, 2017 1:40 pm

Thanks, that seemed to work a lot better.
Still a seg fault but the notenames and ratio's are calculated good so far.

New commit here.

Hans
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby brummer10 » Sat Dec 09, 2017 2:21 pm

Broomy wrote:Still a seg fault but the notenames and ratio's are calculated good so far.


remove ALL free() calls, they are in the wrong place and mostly ain't needed. At least there it will segfault (double free or corruption).

We need to add a
static void gx_tuner_destroy(GObject *object)
function were we free the allocated memory, but that could be done later, when all other stuff work.

Also, please be careful, don't upload the compiled binary!!
That will pump up the git repository size because they will never been removed from the history.
I wonder how you've managed that, as it is on the ignore list. :)

regards
hermann
User avatar
brummer10
Site Admin
 
Posts: 782
Joined: Thu Mar 26, 2009 6:57 pm

Re: Generic Just Intonation Tuner

Postby Broomy » Sat Dec 09, 2017 3:48 pm

I selected the wrong file when uploading the files (I'm using the website to upload the files instead of commandline). Why it passed the ignore list, I can't tell... ;-)

Will remove the free() stuff.

I'll be back!

Hans
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby Broomy » Sat Dec 09, 2017 7:11 pm

Kinda works now.
But the array with the temp note names is giving some trouble, some note names keep growing when the tuner is activated (finally resulting in a seg fault).

For now I'm considering to go for the option you suggested earlier:
You could display the note in multiple steps, from multiple arrays, like:

Code: Select all
cairo_set_source_rgba(cr, fabsf(scale)*3.0, 1-fabsf(scale)*3.0, 0.2,1-fabsf(scale)*2);
cairo_set_font_size(cr, 18.0);
cairo_move_to(cr,x0+50 -9 , y0+30 +9 );
cairo_show_text(cr, tuner->just_note[display_note]);
cairo_move_to(cr,x0+55 -9 , y0+30 +9 );
cairo_show_text(cr, tuner->comma[display_comma]);
cairo_move_to(cr,x0+60 -9 , y0+30 +9 );
cairo_show_text(cr, tuner->chroma[display_chroma]);
cairo_set_font_size(cr, 8.0);
cairo_move_to(cr,x0+54 , y0+30 +16 );
cairo_show_text(cr, octave[indicate_oc]);



This will avoid the need to stick a new array together on the fly, which is indeed complicated in pure C.


make static const char* arrays with all the comma's and read from them, using the int tempscaletranslated array (which seems to work) to read from them and pass that to cairo.

I will sleep on it for now.

Hans!
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby brummer10 » Sun Dec 10, 2017 3:00 am

Broomy wrote:Kinda works now.
But the array with the temp note names is giving some trouble, some note names keep growing when the tuner is activated


Just empty all buffers before refill.
Code: Select all
    for(int i=0;i<MAXSCALENOTES;i++) {
         memset(tuner->tempscaletranslatednames[i], 0, sizeof(char));
    }
 

instead
Code: Select all
memset(tuner->tempscaletranslatednames[0], 0, sizeof(tuner->tempscaletranslatednames));


Other then that, it should be fortune to move the creation of the Note buffer out of the expose callback into a own function, which then be called when on of the input variables changed.
It makes no sense to recreate it on any expose callback.

regards
hermann
User avatar
brummer10
Site Admin
 
Posts: 782
Joined: Thu Mar 26, 2009 6:57 pm

Re: Generic Just Intonation Tuner

Postby Broomy » Sun Dec 10, 2017 7:02 am

brummer10 wrote:Just empty all buffers before refill.

Thanks that worked. Finally starting to grasp how C "thinks".

It seems stable now.
I'll add all the comma's to the mix and some scales and start experimenting if all the calculations are right (I already noticed some errors I've made).

brummer10 wrote:Other then that, it should be fortune to move the creation of the Note buffer out of the expose callback into a own function, which then be called when on of the input variables changed.
It makes no sense to recreate it on any expose callback.


I agree, I've thought of that also. Advantage of this method is that at every cycle all parameters are rechecked.

Hans
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby Broomy » Sun Dec 10, 2017 9:10 pm

Reworked the math. C - scale3diatonic works now.
I've to fix the ratios if the basenote is other then C but would not be that much of a problem.

Bigger problem is that the char* array is still overflowing once a comma is selected.
made a commit with the latest changes.

Kind regards!

Hans
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby brummer10 » Mon Dec 11, 2017 4:01 am

Broomy wrote:Bigger problem is that the char* array is still overflowing once a comma is selected.
made a commit with the latest changes.


from what I could se, it's because the variable
tuner->tempscaletranslated[n][i]

is continues growing in line 682.

regards
hermann
User avatar
brummer10
Site Admin
 
Posts: 782
Joined: Thu Mar 26, 2009 6:57 pm

Previous

Return to Suggestion Box

Who is online

Users browsing this forum: No registered users and 1 guest

cron