f@0
|
1 /*
|
f@0
|
2 Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation.
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19 package uk.ac.qmul.eecs.depic.patterns;
|
f@0
|
20
|
f@0
|
21 /**
|
f@0
|
22 *
|
f@0
|
23 * Immutable class containing two comparable number which represent the start and the end of a range.
|
f@1
|
24 *
|
f@0
|
25 *
|
f@0
|
26 * @param <T>
|
f@0
|
27 */
|
f@0
|
28 public class Range<T extends Number & Comparable<T> > {
|
f@0
|
29 protected T start;
|
f@0
|
30 protected T end;
|
f@0
|
31
|
f@0
|
32 public Range(T t1, T t2){
|
f@0
|
33 if(t1.compareTo(t2) < 1){
|
f@0
|
34 start = t1;
|
f@0
|
35 end = t2;
|
f@0
|
36 }else{
|
f@0
|
37 start = t2;
|
f@0
|
38 end = t1;
|
f@0
|
39 }
|
f@0
|
40 }
|
f@0
|
41
|
f@0
|
42 /**
|
f@0
|
43 * Creates a new instance by comparing {@code mm1} and {@code mm2}.
|
f@0
|
44 *
|
f@0
|
45 * The minimum of this object will be the minimum value between {@code mm1.getMin()} and {@code mm2.getMin()}.
|
f@0
|
46 * The maximum of this object will be the maximum value between {@code mm1.getMax()} and {@code mm2.getMax()}.
|
f@0
|
47 *
|
f@0
|
48 * @param r1 the former Range whose min and max are to be compared
|
f@0
|
49 * @param r2 the latter Range whose min and max are to be compared
|
f@0
|
50 */
|
f@0
|
51 public Range(Range<T> r1, Range<T> r2){
|
f@0
|
52 if(r1.getStart().compareTo(r2.getStart()) < 0){ // if the minimum of mm1 is less than the minimum of mm2
|
f@0
|
53 start = r1.getStart(); // then min is the minimum of mm1
|
f@0
|
54 }else{ // else
|
f@0
|
55 start = r2.getStart(); // min is the minimum of mm2
|
f@0
|
56 }
|
f@0
|
57
|
f@0
|
58 if(r1.getEnd().compareTo(r2.getEnd()) > 0){ // if the maximum of mm1 is greater than the maximum of mm2
|
f@0
|
59 end = r1.getEnd(); // then max is the maximum of mm1
|
f@0
|
60 }else{ // else
|
f@0
|
61 end = r2.getEnd(); // max is the maximum of mm2
|
f@0
|
62 }
|
f@0
|
63 }
|
f@0
|
64
|
f@0
|
65 protected Range(){
|
f@0
|
66 // empty range
|
f@0
|
67 }
|
f@0
|
68
|
f@0
|
69 public T getStart() {
|
f@0
|
70 return start;
|
f@0
|
71 }
|
f@0
|
72 public T getEnd() {
|
f@0
|
73 return end;
|
f@0
|
74 }
|
f@0
|
75
|
f@0
|
76 public float lenght(){
|
f@0
|
77 return getEnd().floatValue() - getStart().floatValue();
|
f@0
|
78 }
|
f@0
|
79
|
f@0
|
80 @Override
|
f@0
|
81 public String toString(){
|
f@0
|
82 return "Range ["+ getStart()+","+getEnd()+"]";
|
f@0
|
83 }
|
f@0
|
84
|
f@0
|
85 public static final Range<Float> NORMALIZED_RANGE_F = new Range<>(0.0f,1.0f);
|
f@0
|
86 public static final Range<Double> NORMALIZED_RANGE_D = new Range<>(0.0,1.0);
|
f@0
|
87 }
|
f@0
|
88
|