[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Denemo-devel] What is the duration of a measure
From: |
Jeremiah Benham |
Subject: |
Re: [Denemo-devel] What is the duration of a measure |
Date: |
Tue, 22 Sep 2009 08:56:21 -0500 |
On Tue, 2009-09-22 at 09:07 +0100, Richard Shann wrote:
> Jeremiah
> Do you know if we have a function to get the duration of a whole measure
> given the time signature?
> I am trying to improve the whole measure rest thing, I can do that if I
> can transform
> 4/4 --> r1
> 12/8 --> r1.
I started witting something like that in importmidi.c In midi there is
a value called ppqn. This stands for Pulses Per Quarter Note. Usually
this value is set to 384. To find out how many pulses are in a measure
you do this:
gint barlength = ppqn * 4 * numerator / denominator;
numerator and denominator refer to the time signature.
Then in importmidi.c line 776. There is this:
while(mididata->barlength - mididata->bartime){
rest = mididata->barlength - mididata->bartime;
struct notetype length = ConvertLength(rest, mididata);
new_dnm_object(mididata, mididata->currentnote, length, FALSE);
mididata->bartime += ConvertNoteType2ticks(mididata, &length);
mididata->lastoff += ConvertNoteType2ticks(mididata, &length);
}
and lines 786-791:
if (rest){
struct notetype length = ConvertLength(rest, mididata);
new_dnm_object(mididata, mididata->currentnote, length, FALSE);
mididata->bartime = mididata->bartime +
ConvertNoteType2ticks(mididata, &length);
mididata->lastoff += ConvertNoteType2ticks(mididata, &length);
rest = 0;
So now you need the function ConvertLength:
notetype ConvertLength(gint duration, midicallback *mididata){
/*convert length to 2 = quarter, 1 = half, 0 = whole etc...... */
/* quarter = 384, half = 768, whole = 1536*/
notetype gnotetype;
gint PPQN = mididata->smf->ppqn;
gint notetype = 0;
gint numofdots = 0;
gint tied = 0;
gint leftover = 0;
gint dsq = (4 * PPQN);
while ((dsq >> notetype) > duration)
notetype++;
leftover = duration - (dsq >> notetype);
while (leftover >= (dsq >> (notetype +1))){
leftover -= (dsq >> (notetype +1));
numofdots++;
}
gnotetype.notetype =
notetype;
gnotetype.numofdots = numofdots;
gnotetype.tied = leftover;
return gnotetype;
}
ConvertLength converts ticks to a notetype. I also have this function if
you need to go the other way around:
ConvertNoteType2ticks(midicallback *mididata, notetype *gnotetype){
gint ticks;
gint PPQN = mididata->smf->ppqn;
gint notetype = (int) gnotetype->notetype;
gint numofdots = (int) gnotetype->numofdots;
gint dsq = (4 * PPQN);
gint i = 0;
ticks = dsq >> notetype;
while (i++ < numofdots)
ticks += dsq >> notetype + 1;
return ticks;
}
IHTH,
Jeremiah
> and so on
> (hmm, for all possible keysigs? it would mean
>
> 5/8 --> r2 r8
>
> or anything equivalent but I don't personally need this)
>
> My question is about Denemo internals really - is there some conversion
> from keysignature to whole measure length that you have come across
> doing the stuff you have done so far?
> Richard
>
>
>
>
> _______________________________________________
> Denemo-devel mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/denemo-devel