aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/cycling74/msp/MSPSignal.java
blob: 0fb9635d46d9154a5e88e9b5112efb81ff7c6ab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.cycling74.msp;

/**
 * Signals representation; signals inlets will copy signal data to this 
 * object.
 */
public class MSPSignal {
    
    /**
     * Tells the number of time this signal is connected. This is always
     * 1 in pure-data.
     */
    public short cc = 1;
    
    /**
     * Tells if this signal is connected. This is always true in pure-data.
     */
    public boolean connected = true;
    
    /**
     * Number of sample in vector.
     */
    public int n;
    
    /**
     * The sampling rate.
     */
    public double sr;
    
    /**
     * The current sample data.
     */
    public float[] vec;
    
    MSPSignal() {
    }
    
    public MSPSignal(float vec[], double sr, int n, short cc) {
        this.vec = vec;
        this.sr = sr;
        this.n = n;
        this.cc = cc;
    }

    /**
     * Returns a copy of this signal but with the same sample buffer. 
     * @return the new signal with the same buffer
     */
    public MSPSignal alias() {
        return new MSPSignal(vec, sr, n, cc);
    }
    
    /**
     * Returns the a duplicated signal object. Also copies the array.
     * @return the new signal with the same value
     */
    public MSPSignal dup() {
        return new MSPSignal((float [])vec.clone(), sr, n, cc);
    }
    
    /**
     * Returns the a duplicated signal object, but the sample vector is
     * re-initialized.
     * @return the new signal with empty value (silence)
     */
    public MSPSignal dupclean() {
        return new MSPSignal(new float [vec.length], sr, n, cc);
    }
    
}