Mercurial > hg > jslab
annotate src/samer/midi/MidiWithAftertouch.java @ 0:bf79fb79ee13
Initial Mercurial check in.
| author | samer |
|---|---|
| date | Tue, 17 Jan 2012 17:50:20 +0000 |
| parents | |
| children | 5df24c91468d |
| rev | line source |
|---|---|
| samer@0 | 1 /* |
| samer@0 | 2 * Copyright (c) 2000, Samer Abdallah, King's College London. |
| samer@0 | 3 * All rights reserved. |
| samer@0 | 4 * |
| samer@0 | 5 * This software is provided AS iS and WITHOUT ANY WARRANTY; |
| samer@0 | 6 * without even the implied warranty of MERCHANTABILITY or |
| samer@0 | 7 * FITNESS FOR A PARTICULAR PURPOSE. |
| samer@0 | 8 */ |
| samer@0 | 9 |
| samer@0 | 10 package samer.midi; |
| samer@0 | 11 import samer.core.*; |
| samer@0 | 12 import samer.core.types.*; |
| samer@0 | 13 import samer.core.util.heavy.*; |
| samer@0 | 14 import samer.core.util.*; |
| samer@0 | 15 import samer.tools.*; |
| samer@0 | 16 import samer.maths.*; |
| samer@0 | 17 import java.util.*; |
| samer@0 | 18 import java.io.*; |
| samer@0 | 19 import javax.sound.midi.*; |
| samer@0 | 20 |
| samer@0 | 21 |
| samer@0 | 22 /** |
| samer@0 | 23 When element crosses threshold upwards: note on |
| samer@0 | 24 When element drops below threshold: note off |
| samer@0 | 25 While element remains above threshold adjust velocity |
| samer@0 | 26 */ |
| samer@0 | 27 |
| samer@0 | 28 public class MidiWithAftertouch extends MidiSynth |
| samer@0 | 29 { |
| samer@0 | 30 protected boolean [] states; |
| samer@0 | 31 |
| samer@0 | 32 public MidiWithAftertouch(VVector input) |
| samer@0 | 33 { |
| samer@0 | 34 super(input); |
| samer@0 | 35 |
| samer@0 | 36 states= new boolean[n]; |
| samer@0 | 37 for (int i=0; i<n; i++) states[i]=false; |
| samer@0 | 38 } |
| samer@0 | 39 |
| samer@0 | 40 public void run() |
| samer@0 | 41 { |
| samer@0 | 42 if (synthesizer==null) return; |
| samer@0 | 43 |
| samer@0 | 44 for (int i=0; i<n; i++) { |
| samer@0 | 45 if (x[i]>0) { |
| samer@0 | 46 int vel=mapVelocity(x[i]); |
| samer@0 | 47 if (!states[i]) { |
| samer@0 | 48 cc[chans[i]].noteOn(nnums[i]+offset.value,vel); |
| samer@0 | 49 states[i]=true; |
| samer@0 | 50 } else { |
| samer@0 | 51 // note is still on - adjust pressure--not working |
| samer@0 | 52 cc[chans[i]].setPolyPressure(nnums[i]+offset.value,vel); |
| samer@0 | 53 } |
| samer@0 | 54 } else if (states[i]) { // note is on but now below thresh |
| samer@0 | 55 if (!pedal.value) cc[chans[i]].noteOff(nnums[i]+offset.value, 0); |
| samer@0 | 56 states[i]=false; |
| samer@0 | 57 } |
| samer@0 | 58 } |
| samer@0 | 59 } |
| samer@0 | 60 } |
