Line | |
---|
1 | package org.apollo.meldex;
|
---|
2 |
|
---|
3 | public class NoteRounder
|
---|
4 | {
|
---|
5 | private int prevValue;
|
---|
6 |
|
---|
7 |
|
---|
8 | public void setInitialValue(int value)
|
---|
9 | {
|
---|
10 | prevValue = value;
|
---|
11 | }
|
---|
12 |
|
---|
13 |
|
---|
14 | public int round(int value, int mult)
|
---|
15 | {
|
---|
16 | return (((value + (mult/2)) / mult) * mult);
|
---|
17 | }
|
---|
18 |
|
---|
19 |
|
---|
20 | public int roundCents(int value)
|
---|
21 | {
|
---|
22 | return (round(value, 100));
|
---|
23 | }
|
---|
24 |
|
---|
25 |
|
---|
26 | public int roundNote(int value, boolean useAdaptiveTuning)
|
---|
27 | {
|
---|
28 | // If we aren't using adaptive tuning, ignore the previous value
|
---|
29 | if (useAdaptiveTuning == false) {
|
---|
30 | return (roundCents(value));
|
---|
31 | }
|
---|
32 |
|
---|
33 | // Otherwise calculate the new adaptive value
|
---|
34 | else {
|
---|
35 | int finalValue = roundCents(value + prevValue);
|
---|
36 | prevValue = (prevValue + (finalValue - value)) / 2;
|
---|
37 | return finalValue;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.