Generic Just Intonation Tuner

need a feature, suggest here

Generic Just Intonation Tuner

Postby Broomy » Mon Nov 20, 2017 3:55 pm

Because the discussion of this thread moved from adding one or two preset to an idea of making a generic tuner, I thought it was better to start a new discussion.

I've made a new branch on the gxtuner repo and will use that one, to (try to) rework GXtuner in a generic just intonation tuner.

The cool thing about JI is that you have infinite (but) discrete ratios. But what is needed at a certain time is just a small selection of these intervals: A base note and a scale which contains an amount of notes with a certain (ratio based) distance from the base note.
For example the diatonic scale contains the following ratios 1/1, 9/8, 5/4, 4/3, 3/2, 5/3, 15/8, when a basenote is selected the other notes can easily be calculated.

I have the math figured out to make all the necessary calculations, but have a couple of questions about how to get an extra input switch.
@Hermann: Do you mind to add a few comments in the code of where and how the treshold or presets inputs are generated?

What I need to proceed is a couple of inputs for integers. So variable x is set at -1 or 2 or something like that and can be changed just as changing a preset (from diatonic to shruti for instance).

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

Re: Generic Just Intonation Tuner

Postby Broomy » Mon Nov 20, 2017 6:19 pm

Here's the math explained. 1/3

Just intonation is based on the natural harmonic series. When a string is strung, the note you hear is a complex of several frequencies which all relate to the root frequency, being multiples. These so called overtones are used for deriving all the different ratios used in JI.

Lets take a look. The root frequency is 100 Hz, which is called the first harmonic, the second harmonic is 2*100Hz and is an octave apart from the root. Our ears don't hear octaves as a new note, only as the same note higher or lower. The ratio between these notes is 2/1.
The third harmonic has a ratio of 3/1 and is the first non-octave. In musical term this note is called a fifth.
Let's stop here for a while.
It is common practice to use C - D - E - F - G - A - B for naming different notes.
Let's call our root C and our 3/1 ratio G.
(Btw. it's common practice to right ratio in a way that their outcomes lies between 1 and 2 (the octave). To achieve this by either multiplying the numerator or denominator with (multiplies of) 2, so our G is written as 3/2).

We can derive our second note by multiplying G with 3/2 and moving five steps up (going back to C when we reach B). This gives us the note D, with the ratio 3/2*3/2=9/4 ==> 9/8

When we keep doing this several steps up and one step down from C we get the following row of notes:

F - C - G - D - A - E - B

This row is called the cycle of fifths.
When we proceed even more to the right, we have to use F again. Here a problem arises. If we where to compare the two ratios we will noticed that they differ, so giving them the same name is prohibited.
To solve this a extra symbol is added: "#", and now we can proceed again seven steps, and add an extra "#" for the next 7 notes:

F - C - G - D - A - E - B - F# - C# - G# - D# - A# - E# - B# - F## - C## - G## -etc.

This can be reversed as well:

Fbb - Cbb - Gbb - Dbb - Abb - Ebb - Bbb - Fb - Cb - Gb - Db - Ab - Eb- Bb - F - C - G - D - A - E - B -

Note that all these notes have a different ratio (which can be calculated with 3^n/2^n), thus are different notes. Note also that a Fb has the same amount of steps to a F as F has to F# and so on.
Last edited by Broomy on Mon Nov 20, 2017 6:39 pm, edited 1 time in total.
User avatar
Broomy
 
Posts: 195
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby Broomy » Mon Nov 20, 2017 6:38 pm

2/3

Let's set this aside for awhile and move back to our harmonics.
The fourth harmonic is an octave (2*2) so isn't yielding a new note, but the fifth harmonic does.
Let's take a closer look here.

The ratio is 5/1 and when we multiply the divisor with 4 (2*2) we have our ratio. This ratio is associated with the third note thus is called E when we start from C.
Let's recall our notes from the third harmonic.

F - C - G - D - A - E - B

To make thinks visual we add our new ratio above the C, making it a 2D plane

E
F - C - G - D - A - E - B

But as stated earlier, note names may be used only once. And the E with ratio 5/1 is a bit smaller then the 81 (3^4)/16 ratio. This "bit smaller" can be calculated by dividing 81/16 by 5/1 which equals: 81/80.
Let's give this difference symbol "-", then our E with ratio 5/1 can be written as: E-

When we move one step to the right we can write a B- and so forth

E- - B- - F#- - C#- - G# - D# -
F - C - G - D - A - E - B - F#

Notice that this way we can write any note we like and calculate the corresponding ratio.
Last edited by Broomy on Mon Nov 20, 2017 7:23 pm, edited 1 time in total.
User avatar
Broomy
 
Posts: 195
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby Broomy » Mon Nov 20, 2017 7:05 pm

3/3

Now let's make the last step.
Ratios can be written as a product of prime numbers, for instance:
3/2 = 2^-1 * 3^1*5^0
5/4 = 2^-2*3^0*5^1
Or more generic 2^a*3^b*5^c and so on.
The letters a,b and c can be put in a matrix and that way ratios can easily be multiplied by summing two matrices.

For example
3/2*5/4 = 3*5 / 2*4 = 15 / 8
equals
[-1,1,0] + [-2,0,1] = [-3, 1, 1]
is 2^-3*3^1*5^1 = 15 / 8

Using matrices makes it very easy to calculate a needed ratio, for example:
We want to know the ratio of G###--
The ratiomatrix from C to G is [-1,1,0]
The ratiomatrix from G to G# is [-7,7,0], because of the three "#" we have to multiply this matrix with 3
The ratiomatrix from G to G- [-4,4,-1], because of the two "-" we have to multiply this matrix with 2

This yields the following equation:
Ratiomatrix G###-- = [-1,1,0] + 3*[-7,7,0] + 2* [-4,4,-1] = [-1,1,0] + [-21,21,0] + [-8,8,-2] = [-30, 29,-2]
This way every note can be formed and calculated with the appropriate ratio.

This is the basic train of thoughts which underlays the Just Tuner. There are some other minor issues that are to be addressed but that would not be much of a problem.
User avatar
Broomy
 
Posts: 195
Joined: Thu Apr 24, 2014 7:53 am

Re: Generic Just Intonation Tuner

Postby Broomy » Mon Nov 20, 2017 7:21 pm

Then, how do I envision the layout of the tuner:

**********************************************************************************************
**********************************************************************************************
****************************Here comes the VU-meter************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
* Base note: Selectionbox #/b (int. sb) +/- (int. sb) even more comma's********
* Scale: Selectionbox **********************************************************************
*********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************

Next step would be an option to save a certain setting as a preset, that way you can change presets in between or during songs. But one step at a time.

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

Re: Generic Just Intonation Tuner

Postby brummer10 » Tue Nov 21, 2017 4:14 am

Hi Hans

I'll put the comments on weekend, right now I'm a bit busy with my work.

Just a bit about the basic construct of GxTuner:

cmdparser.cpp and cmdparser.h -> C++ object which parse the command-line input

deskpager.cpp and deskpager.h -> C++ object which could move the GxTuner interface to a other virtual desktop

gtkknob.cc and gtkknob.h -> GTK widget written in C, well the Knob widget.

gx_pitch_tracker.cpp and gx_pitch_tracker.h -> C++ object which do the frequency tracking, this one runs on it's own thread and send a signal when the tracked frequency has changed.

gxtuner.cpp and gxtuner.h -> Gtk widget written in C, this is the widget which create the tuner background and the needle.

jacktuner.cpp and jacktuner.h -> C++ object doing the connection to jack

paintbox.cpp and paintbox.h -> GTK widget written in C, this is the Frame around the tuner.

tuner.cpp and tuner.h -> C++ object, here we create the GUI, initialize all widgets and connect the signal handlers between the objects.

resource.xml -> resource.c and resource.h -> this contain the Images in C which are used in the tuner, eg. the Icon and the frame.png

main.cpp -> well the main loop starts here.

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

Re: Generic Just Intonation Tuner

Postby Broomy » Tue Nov 21, 2017 2:15 pm

Thanks Hermann!

No hurries, I've to work my way through a C++ tutorial first anyway... :lol:

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

Re: Generic Just Intonation Tuner

Postby Broomy » Wed Nov 22, 2017 1:25 pm

I've wrote a piece of code where I can input three integers:
1. To determine which basenote to use (C, D, E, F, G, A, B) (1-7);
2. How many flats or sharps are needed;
3. How many syntonic comma's are needed.

The output is a note with all the right suffixes.

The code:
Code: Select all
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>

/* */

using namespace std;

//constants
# define NrPrimes 10  /* 2,3,5,7,11,13,17,23,29,31 */
const char BaseNotes[] = {"CDEFGAB"};
//structures

//variables
int RefNoteIn[NrPrimes] = {0};
char RefNoteOut[15];

//formules (statement)
int GetBaseNote ();
void WriteRefNote ();
int CalculateRefNote ();


int main ()
{
    GetBaseNote ();
    WriteRefNote ();
    CalculateRefNote ();
   
    cout << RefNoteOut <<"\n";
   
    return 0;
}

int GetBaseNote ()
{
    cout << "Reference Note:\n" ;
    cin >> RefNoteIn[0];
    cout << "Number of ♭ or ♯:\n" ;
    cout << "Use a \'-\' if you want a flat.\n" ;
    cin >> RefNoteIn[1];
    cout << "Number of + or -:\n" ;
    cout << "Use a \'-\' if you want a - comma.\n" ;
    cin >> RefNoteIn[2];
    /*cout << "Number of 7 or L:\n" ;
    cout << "Use a \'-\' if you want a L.\n" ;
    cin >> RefNoteIn[3];*/
    return 0;
}

void WriteRefNote (){
    //Getting the base note
    RefNoteOut[0] = BaseNotes[RefNoteIn[0]-1];
    // calculating the number of sharps or flats
    for (int n=0; n<abs(RefNoteIn[1]); n++){
            if (RefNoteIn[1] < 0){
                strcat(RefNoteOut, "♭");
            }
            else {
                strcat(RefNoteOut, "♯");
            }       
    }
    // calculating the number of + or -
    for (int n=0; n<abs(RefNoteIn[2]); n++){
            if (RefNoteIn[2] < 0){
                strcat(RefNoteOut, "-");
            }
            else {
                strcat(RefNoteOut, "+");
            }       
    }
    strcat(RefNoteOut, "\0");
    return;
}   

int CalculateRefNote ()
{
    return 0;
}   


The output of an example taken from my terminal:
Code: Select all
Reference note:
1
Number of ♭ or ♯:
Use a '-' if you want a flat.
-2
Number of + or -:
Use a '-' if you want a - comma.
+3
C♭♭+++


Next up is calculating the ratio of a given note.

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

Re: Generic Just Intonation Tuner

Postby brummer10 » Thu Nov 23, 2017 6:02 am

I've just add some comments about how to add property's to the tuner widget:
https://github.com/brummer10/gxtuner/co ... 361720498f

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

Re: Generic Just Intonation Tuner

Postby Broomy » Thu Nov 23, 2017 8:27 pm

Thank you very much Hermann,
I'll look into it.

I'll try to create and bind three +/- boxes; then I'm good to go.

I can calculate any needed ratio now and will proceed to create a scale starting from any given refnote, which can be used by the tuner.

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

Next

Return to Suggestion Box

Who is online

Users browsing this forum: No registered users and 1 guest

cron