f@0: /* f@0: Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation. f@0: f@0: Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: package uk.ac.qmul.eecs.depic.patterns; f@0: f@0: /** f@0: * f@0: * Immutable class containing two comparable number which represent the start and the end of a range. f@1: * f@0: * f@0: * @param f@0: */ f@0: public class Range > { f@0: protected T start; f@0: protected T end; f@0: f@0: public Range(T t1, T t2){ f@0: if(t1.compareTo(t2) < 1){ f@0: start = t1; f@0: end = t2; f@0: }else{ f@0: start = t2; f@0: end = t1; f@0: } f@0: } f@0: f@0: /** f@0: * Creates a new instance by comparing {@code mm1} and {@code mm2}. f@0: * f@0: * The minimum of this object will be the minimum value between {@code mm1.getMin()} and {@code mm2.getMin()}. f@0: * The maximum of this object will be the maximum value between {@code mm1.getMax()} and {@code mm2.getMax()}. f@0: * f@0: * @param r1 the former Range whose min and max are to be compared f@0: * @param r2 the latter Range whose min and max are to be compared f@0: */ f@0: public Range(Range r1, Range r2){ f@0: if(r1.getStart().compareTo(r2.getStart()) < 0){ // if the minimum of mm1 is less than the minimum of mm2 f@0: start = r1.getStart(); // then min is the minimum of mm1 f@0: }else{ // else f@0: start = r2.getStart(); // min is the minimum of mm2 f@0: } f@0: f@0: if(r1.getEnd().compareTo(r2.getEnd()) > 0){ // if the maximum of mm1 is greater than the maximum of mm2 f@0: end = r1.getEnd(); // then max is the maximum of mm1 f@0: }else{ // else f@0: end = r2.getEnd(); // max is the maximum of mm2 f@0: } f@0: } f@0: f@0: protected Range(){ f@0: // empty range f@0: } f@0: f@0: public T getStart() { f@0: return start; f@0: } f@0: public T getEnd() { f@0: return end; f@0: } f@0: f@0: public float lenght(){ f@0: return getEnd().floatValue() - getStart().floatValue(); f@0: } f@0: f@0: @Override f@0: public String toString(){ f@0: return "Range ["+ getStart()+","+getEnd()+"]"; f@0: } f@0: f@0: public static final Range NORMALIZED_RANGE_F = new Range<>(0.0f,1.0f); f@0: public static final Range NORMALIZED_RANGE_D = new Range<>(0.0,1.0); f@0: } f@0: