Generic Just Intonation Tuner

need a feature, suggest here

Re: Generic Just Intonation Tuner

Postby brummer10 » Sat Dec 02, 2017 5:39 pm

gxtuner.cpp/h is a GTK3 widget written in C. You shouldn't use C++ inside this object.
So, no std::string inside the widget object code is possible.

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 02, 2017 9:51 pm

Ahh, that might be the cause of my trouble then.

There are two issues I have a hard time to resolve.

1. Each mode loads a reference scale with a different amount of notes. To implement this I need a dynamic array. From what I find on internet using a vector is common solution to do so. But loading the c library <vector.h> doesn't work.
2. When I want to construct the names for the notes I have to add several short strings to make one notename. For example "C" + "#" + "-" + "7" ==> "C#-7". I've tried to use a similar method you used in Tuner.cpp to set the title of the window, but there you use a std::string type.

I'll keep pondering on it, but advice is very welcome!

Kind regards,

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

Re: Generic Just Intonation Tuner

Postby brummer10 » Sun Dec 03, 2017 4:45 am

Broomy wrote:1. Each mode loads a reference scale with a different amount of notes. To implement this I need a dynamic array. From what I find on internet using a vector is common solution to do so. But loading the c library <vector.h> doesn't work.


You know the maximum needed size, so best would be to allocate the array to the max size and then just count the elements you put in. Other then that there is no dynamic array implementation in C.
If you would do it dynamically you need to implement a struct to do it (reallocate), but in this case here, I ain't see any advance in do so. Just use the max size and allocate the array in init.

int max_notes = 99;
char * test = malloc((sizeof(char) * max_notes)+1); // allocate
memset(test[0], 0, sizeof(test)); // clear

after you've cleared the array, you could use it to insert your notes. Just count the notes you insert, so you know how large your note buffer really is. If you need to change the note array, just clear it again and reuse it.
we could check in the free() call later, as we need to introduce a widget class destructor then.

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 03, 2017 4:17 pm

Thanks for the advice.

From what you've said and I've found this should work, right?
Code: Select all
MAXNRNOTES = 50; // (arbitrary number)
NRPRIMES = 12;
MAXCHARDISPL = 20;
choosenscale[12][NRPIRMES]= {lots of integers};
int tempscale[MAXNRNOTES][NRPRIMES];
const char* tempscalenames[MAXNOTES][MAXCHARDISPL];

In the function:

//creating the temp array for the integers
for (int n = 0; n<numberofnotesofchoosenscale; n++){
               for (i=0; i<nNRPRIMES; i++){
               tempscale[n][i] = choosenscale[n][i];
               }
}

==> translating the tempscale array to tempscaletranslated

add free ( tempscale ); here?

//creating the temp array for the notenames using tempscaletranslated
for (int n = 0; n<numberofnotesofchoosenscale; n++){
               int m=0;
               //get basenote
               tempscalenotenames[n][m]=basenotes[tempscaletranslated[n][0];
               // add needed comma's for example comma 7
               if (tempscalestranslated[n][5]<0){
                             for(int i=0; i<abs(tempscalestranslated[n][5]), i++){
                             m += 1;
                                tempscalenotenames[n][m] = 'L';
                             }
              }
              if (tempscalestranslated[n][5]>0){
                             for(int i=0; i<abs(tempscalestranslated[n][5]), i++){
                             m += 1;
                                tempscalenotenames[n][m] = '7';
                             }
              }
              //repeat this for all comma's and end with \0
             m += 1;
              tempscalenotenames[n][m] = '\0';
               }


Now I'm thinking about a protection that m doesn't exceeds the max nr. of char to display.

Can the 'tempscalenotenames' be used to pass data to display_note?

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

Re: Generic Just Intonation Tuner

Postby brummer10 » Tue Dec 05, 2017 4:12 am

Hi Hans

I've looked at the new code, but, unfortunately it is somewhat broken that I ain't know were to start to fix it.

It looks to me that you made stuff a bit to complicated.
As a suggestion, you may use separate, pre-defined arrays for basenote, comma's and chroma's etc., and then just select from the arrays which basenote, comma and chroma to use for display.

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.

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

Re: Generic Just Intonation Tuner

Postby Broomy » Tue Dec 05, 2017 9:30 am

Thanks for the tip, I'll do that.

You don't have to fix the code, I'll do that. Your advice is already more then helpfull!

I can continue now!

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

Re: Generic Just Intonation Tuner

Postby brummer10 » Tue Dec 05, 2017 6:02 pm

Broomy wrote:You don't have to fix the code, I'll do that.


Don't get me wrong here, I ain't plan to fix it myself, what I mean is I ain't know what to suggest you to do to fix it.

When I'm working on a project, sometimes I need to do a roll-back, to a working stage, and start again from there. Sometimes I need to do that several times, before I'm "on the right track".
That's what I mean here. The idea is good, just it may need a other way to archive the goal.
And you are welcome, Hans, I enjoy how the source evolve and I like to offer a little help.

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

Re: Generic Just Intonation Tuner

Postby Broomy » Tue Dec 05, 2017 9:10 pm

brummer10 wrote:Don't get me wrong here, I ain't plan to fix it myself, what I mean is I ain't know what to suggest you to do to fix it.

Good you say that, I misunderstood your former comment. I wasn't expecting you to do so, but good to make expectations clear.

brummer10 wrote:When I'm working on a project, sometimes I need to do a roll-back, to a working stage, and start again from there. Sometimes I need to do that several times, before I'm "on the right track".
That's what I mean here. The idea is good, just it may need a other way to archive the goal.

Well that's my process of the past weeks in a nutshell... ;)
But they were few of my most educational weeks I've had so far...!

I've made a new commit, with some changes made. My goal was to get through the make && make install. That works now, but when running it gives a segmentation fault.
The code needs also to be cleared of all sorts of comments and there is some stuff which I have to add still.

Regards,

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

Re: Generic Just Intonation Tuner

Postby Broomy » Wed Dec 06, 2017 9:25 am

I can't figure out right now what's causing the segmentation fault. I have to study up on the rationale behind the c language.
User avatar
Broomy
 
Posts: 194
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby brummer10 » Wed Dec 06, 2017 9:36 am

You should set the tuner->mode in gx_tuner_init to '0' instead '1'
that will allow you to start gxtuner without segfault.

Then add some fprintf statments in the gtk_tuner_expose_just callback to find out were exactly the segmentation happen.

Most likely is a UN-initialisized array, or a buffer overrun somewere.
User avatar
brummer10
Site Admin
 
Posts: 782
Joined: Thu Mar 26, 2009 6:57 pm

PreviousNext

Return to Suggestion Box

Who is online

Users browsing this forum: No registered users and 1 guest

cron