To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / Messages.h

History | View | Annotate | Download (3.03 KB)

1
/*
2

3
 Copyright (C) 2016  Queen Mary University of London 
4
 Author: Fiore Martin
5

6
 This file is part of Collidoscope.
7
 
8
 Collidoscope is free software: you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation, either version 3 of the License, or
11
 (at your option) any later version.
12

13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 GNU General Public License for more details.
17

18
 You should have received a copy of the GNU General Public License
19
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21

    
22
#pragma once
23

    
24
/**
25
 * Enumeration of all the possible commands exchanged between audio thread and graphic thread.
26
 *
27
 */ 
28
enum class Command {
29
    // message carrying info about one chunk of recorder audio. 
30
    WAVE_CHUNK,
31
    // message sent when a new recording starts. The gui resets the wave upon receiving it. 
32
    WAVE_START,
33

    
34
    // new grain created 
35
    TRIGGER_UPDATE,
36
    // synth became idle
37
    TRIGGER_END,
38

    
39
    NOTE_ON,
40
    NOTE_OFF,
41

    
42
    LOOP_ON,
43
    LOOP_OFF
44
};
45

    
46
/** Message sent from the audio thread to the graphic wave when a new wave is recorded. 
47
 *  
48
 *  The graphic thread sets the chunks of the wave to reflect the level of the recorded audio. 
49
 *  The algorithm takes the maximum and minimum value of a group of samples and this becomes the top and bottom of the chunk.
50
 *  The message carries also the index of the chunk it refers to 
51
 */
52
struct RecordWaveMsg
53
{
54
    Command cmd; // WAVE_CHUNK or WAVE_START
55
    std::size_t index;
56
    float arg1;
57
    float arg2;
58
};
59

    
60
/**
61
 * Utility function to create a new RecordWaveMsg.
62
 */ 
63
inline RecordWaveMsg makeRecordWaveMsg( Command cmd, std::size_t index, float arg1, float arg2 )
64
{
65
    RecordWaveMsg msg;
66
    msg.cmd = cmd;
67
    msg.index = index;
68
    msg.arg1 = arg1;
69
    msg.arg2 = arg2;
70

    
71
    return msg;
72
}
73

    
74
/**
75
 * Message sent from the audio thread to the graphic thread when a new grain is triggered in the granular synthesizer. 
76
 * This creates a new cursor that travels from the beginning to the end of the selection to graphically represent the evolution of the grain in time. 
77
 *
78
 */ 
79
struct CursorTriggerMsg
80
{
81
    Command cmd; // TRIGGER_UPDATE or TRIGGER_END
82
    int synthID;
83
};
84

    
85
/**
86
 * Utility function to create a new CursorTriggerMsg.
87
 */ 
88
inline CursorTriggerMsg makeCursorTriggerMsg( Command cmd, std::uint8_t synthID )
89
{
90
    CursorTriggerMsg msg;
91

    
92
    msg.cmd = cmd;
93
    msg.synthID = synthID;
94

    
95
    return msg;
96
}
97

    
98
/**
99
 * Message sent from the graphic (main) thread to the audio thread to start a new voice of the granular synthesizer.
100
 */ 
101
struct NoteMsg
102
{
103
    Command cmd; // NOTE_ON/OFF ot LOOP_ON/OFF 
104
    int midiNote;
105
    double rate;
106
};
107

    
108
/**
109
 * Utility function to create a new NoteMsg.
110
 */ 
111
inline NoteMsg makeNoteMsg( Command cmd, int midiNote, double rate )
112
{
113
    NoteMsg msg;
114

    
115
    msg.cmd = cmd;
116
    msg.midiNote = midiNote;
117
    msg.rate = rate;
118

    
119
    return msg;
120
}