Pages: [1]   Go Down
Author Topic: quantizing midi notes  (Read 1376 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

is it possible to quantize the midi notes send by a arduino sequencer?
Right now I only take the analogvalue and send that to the midi device:

Code:
void playstep(int stepnr) {
  
  if (currentSwitchState[stepnr] == 1) {
    
//this reads a potentiometer and defines the pitch of the note to be played
    AnalogValue[stepnr] = analogRead(stepnr);
    note[stepnr] = AnalogValue[stepnr]/8 ;
//this is optional if the played note should be turned of on the next step
     holdState = digitalRead(holdPin);
    if (holdState == 1) {
         noteOn(0xB0, 0x7B, 0x00);  // all notes off    
    }  
//this plays the actuall note, first midi than analog
    noteOn(0x90, note[stepnr], 0x7F); // play note
    write_value(AnalogValue[stepnr] * 4);
//this blinks the LED when the current step is played    
    for (int i=0; i<=15; i++) {
      digitalWrite(LEDpins[i], i==stepnr);
    }
  }
}
« Last Edit: January 10, 2012, 01:39:23 pm by Rupertt » Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

By "Quantize", are you referring to Frequency or Time domain Quantizing?

Frequency Quantizing:
  This will give the "nearest note" to the incoming value.

Time Quantizing:
  This will only send notes to the host at specific time intervals, creating a minimum note length.

I am guessing the latter is what you are wanting.

The simplest way is to maintain a "buffer" of incoming notes (a simple array will suffice).  Add the notes as they come in through the analog input to the array.

At specific times (either through monitoring millis() or through a timer driven interrupt - the former is better as it's bad to do heavy work in an interrupt) you then read the entire buffer and send the note information it contains to the host in one block.  Then you can wipe the buffer and start filling it afresh.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

this time i would like to quantize the note/pitch/frequency,
the sequencer runs to an external clock, so quantizing the time would not be neccesary., i think.

cheers
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1552
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Right now I only take the analogvalue and send that to the midi device:
Your code makes no sense whatever. Explain what it does.

Quote
this time i would like to quantize the note/pitch/frequency,
And nor does this. Explain what you mean.

Pete

Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did write some comments to the code, hope thats enough.
With quantizing the pitch I mean that the played note matches a note from the scale or a chord,
thats how I understand quantizing.

this is the wikipedia article on quantizing:
http://en.wikipedia.org/wiki/Quantization_%28music%29
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1552
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I did write some comments to the code, hope thats enough.
Well, DUH! If those comments had been enough I wouldn't have asked you to explain the code.
Let's put it this way. The comments do not make clear what the code is doing so if you wrote that code you can explain it.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well,
i ment i updated the above post with more comments, but here we go again:


i read a value from a potentiometer, put the value into an array " AnalogValue[stepnr] ", divide that by 8 and
put it into another array "note[stepnr]", which represents the note to be played(this one I want to quantize),
than i simply sent that note to the serial port, which is connected to midi, the noteOn function i posted below.


Code:
void playstep(int stepnr) {
  
  if (currentSwitchState[stepnr] == 1) {
    
//this reads a potentiometer and defines the pitch of the note to be played
    AnalogValue[stepnr] = analogRead(stepnr);
    note[stepnr] = AnalogValue[stepnr]/8 ;
//this is optional if the played note should be turned of on the next step
     holdState = digitalRead(holdPin);
    if (holdState == 1) {
         noteOn(0xB0, 0x7B, 0x00);  // all notes off    
    }  
//this plays the actuall note, first midi than analog
    noteOn(0x90, note[stepnr], 0x7F); // play note
    write_value(AnalogValue[stepnr] * 4);
//this blinks the LED when the current step is played    
    for (int i=0; i<=15; i++) {
      digitalWrite(LEDpins[i], i==stepnr);
    }
  }
}

Code:
void noteOn(byte cmd, byte data1, byte  data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1552
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your explanation still doesn't rise above the level of "Well, DUH".

Try again.
Quote
i read a value from a potentiometer, put the value into an array " AnalogValue[stepnr] ", divide that by 8
That is plainly obvious but why do you divide it by 8?

Quote
and put it into another array "note[stepnr]"
Why put it in another array? You can just use the AnalogValue and divide by 8 when needed (this is more a coding efficiency issue)?

Quote
which represents the note to be played(this one I want to quantize),
Which completely contradicts yourself. In your first post you said you wanted to quantize the midi notes. Then, when asked about it, you said you wanted to quantize "note/pitch/frequency". Which is it?

Quote
than i simply sent that note to the serial port, which is connected to midi, the noteOn function i posted below.
Which synthesizer are you sending this to?

What does the write_value function do, what kind of device is it connected to and why do you multiply the analog value by 4?

And to, sort of, answer your, sort of, question. If you really do want to quantize the frequency of the analog signal, I don't think it can be done. Pitch shifting requires code to do FFT (and the inverse?) and it is not a trivial operation.

Pete
Logged

Where are the Nick Gammons of yesteryear?

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The short answer is that since you're taking the 1024 level range of the Arduino  analog input and dividing by 8 to a number between 0 and 127 and then using that as the note value of your midi command, you are already quantising the input value to the 128 notes that (unmodified ) midi is capable of representing. Of course, since that's a very large range you probably want to modify it in some way. (Reduce the range to 1 or more octaves or map to particular scale.) Is that what you're asking about?

On a separate note (no pun!) your note on function is misnamed. Since you're specifying the midi command in the first parameter it's just a generic midi function.

Points that are not clear from your code and may or may not be relevant:
The purpose of the analog value - why is this needed?
How the notes get turned off - I assume this is something to do with the array but it's not clear what.

Logged

Pages: [1]   Go Up
Jump to: