Subversion Repositories svn.mios32

Rev

Rev 1917 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1334 tk 1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
2
// $Id: MbCvEnvironment.h 1960 2014-02-09 20:21:24Z tk $
3
/*
4
 * MIDIbox CV Toplevel
5
 * Instantiates multiple MIDIbox CV Units
6
 *
7
 * ==========================================================================
8
 *
9
 *  Copyright (C) 2010 Thorsten Klose (tk@midibox.org)
10
 *  Licensed for personal non-commercial use only.
11
 *  All other rights reserved.
12
 *
13
 * ==========================================================================
14
 */
15
 
16
#ifndef _MB_CV_ENVIRONMENT_H
17
#define _MB_CV_ENVIRONMENT_H
18
 
19
#include <mios32.h>
20
#include "MbCv.h"
21
#include "MbCvStructs.h"
22
//#include "MbCvSysEx.h"
23
#include "MbCvClock.h"
1452 tk 24
#include "MbCvPatch.h"
1885 tk 25
#include "MbCvScope.h"
1334 tk 26
 
27
class MbCvEnvironment
28
{
29
public:
30
    // Constructor
31
    MbCvEnvironment();
32
 
33
    // Destructor
34
    ~MbCvEnvironment();
35
 
36
    // instantiate the MbCv instances
37
    array<MbCv, CV_SE_NUM> mbCv;
38
 
1347 tk 39
    // CV Output value (will be mapped in MbCvEnvironment::tick() !!!)
40
    array<u16, CV_SE_NUM> cvOut;
41
 
1887 tk 42
    // CV Output meter values (with delayed dec)
43
    array<u16, CV_SE_NUM> cvOutMeter;
44
 
1347 tk 45
    // CV Gates (will be mapped in MbCvEnvironment::tick() !!!)
46
    // up to 32 gates should be sufficient for future extensions? (currently we only use 8!)
47
    u32 cvGates;
1452 tk 48
 
1960 tk 49
    // Knobs
50
    array<u8, CV_KNOB_NUM> knobValue;
51
 
52
    // Scale
53
    u16 scaleKeyMask;
54
    u8 scaleKeyMap[12];
55
 
1452 tk 56
    // sound patch
57
    MbCvPatch mbCvPatch;
1885 tk 58
 
59
    // instantiate the scopes for GLCD output
60
    array<MbCvScope, CV_SCOPE_NUM> mbCvScope;
61
    u8 scopeUpdateCtr;
62
 
1334 tk 63
    // sets the update factor
64
    void updateSpeedFactorSet(u8 _updateSpeedFactor);
65
 
66
    // Sound Engines Update Cycle
67
    // returns true if CV registers have to be updated
68
    bool tick(void);
69
 
1452 tk 70
    // Should be called each mS from a thread, e.g. for synchronized patch changes
71
    void tick_1mS(void);
72
 
1885 tk 73
    // Should be called each mS from a low-prio thread to update scope displays
74
    void tickScopes(void);
75
 
1334 tk 76
    // speed factor compared to MBCVV2
77
    u8 updateSpeedFactor;
78
 
79
    // set/get BPM
80
    void bpmSet(float bpm);
81
    float bpmGet(void);
82
 
83
    // resets internal Tempo generator
84
    void bpmRestart(void);
85
 
86
    // bank access
1452 tk 87
    s32 bankSave(u8 bank, u8 patch);
88
    s32 bankLoad(u8 bank, u8 patch, bool forceImmediateChange = false);
1334 tk 89
    s32 bankPatchNameGet(u8 bank, u8 patch, char *buffer);
90
 
91
    // MIDI
92
    void midiReceive(mios32_midi_port_t port, mios32_midi_package_t midi_package);
93
    s32 midiReceiveSysEx(mios32_midi_port_t port, u8 midi_in);
94
    void midiReceiveRealTimeEvent(mios32_midi_port_t port, u8 midi_in);
95
    void midiTimeOut(mios32_midi_port_t port);
96
 
1408 tk 97
    void midiSendNRPNDump(mios32_midi_port_t port, u16 cvChannels, bool seqOnly);
1452 tk 98
    void midiSendGlobalNRPNDump(mios32_midi_port_t port);
1394 tk 99
    void midiSendNRPN(mios32_midi_port_t port, u16 nrpnNumber, u16 value);
1911 tk 100
    void midiSendNRPNToActivePort(u16 nrpnNumber, u16 value);
1394 tk 101
 
1449 tk 102
    // Copy/Paste/Clear operations
1453 tk 103
    void channelCopy(u8 channel, u16* buffer);
104
    void channelPaste(u8 channel, u16* buffer);
1449 tk 105
    void channelClear(u8 channel);
106
 
1453 tk 107
    // also used for load/store operations
108
    u16 copyBuffer[CV_PATCH_SIZE];
109
 
1334 tk 110
    // callbacks for MbCvSysEx
111
    bool sysexSetPatch(u8 cv, cv_patch_t *p, bool toBank, u8 bank, u8 patch); // returns false if CV not available
112
    bool sysexGetPatch(u8 cv, cv_patch_t *p, bool fromBank, u8 bank, u8 patch); // returns false if CV not available
113
    bool sysexSetParameter(u8 cv, u16 addr, u8 data); // returns false if CV not available
1903 tk 114
 
115
    // NRPN parameter handling
116
    bool setNRPN(u16 nrpnNumber, u16 value);
117
    bool getNRPN(u16 nrpnNumber, u16 *value);
118
    bool getNRPNInfo(u16 nrpnNumber, MbCvNrpnInfoT *info);
1334 tk 119
 
1960 tk 120
    // global NRPNs
121
    bool setGlobalNRPN(u16 nrpnNumber, u16 value);
122
    bool getGlobalNRPN(u16 nrpnNumber, u16 *value);
123
    bool getGlobalNRPNInfo(u16 nrpnNumber, MbCvNrpnInfoT *info);
124
 
125
    // set/get knob values
126
    u8   getKnobValue(u8 knob);
127
    void setKnobValue(u8 knob, u8 value);
128
 
129
    // set/get scale keys
130
    u8   getScaleKey(u8 key);
131
    void setScaleKey(u8 key, u8 enable);
132
    void updateScaleKeyMap(void); // done automatically by setScaleKey
133
    u8   scaleValue(u8 value); // scales a 7bit value based on the scale key map
134
 
1334 tk 135
    // SysEx parsers
136
    //MbCvSysEx mbCvSysEx;
137
 
138
    // Tempo Clock
139
    MbCvClock mbCvClock;
1449 tk 140
 
1452 tk 141
    // last port and CV channels used for NRPN communication
142
    mios32_midi_port_t lastNrpnMidiPort;
143
    u16 lastNrpnCvChannels;
144
 
1911 tk 145
protected:
146
    // MIDI NRPN variables
147
    u16 nrpnAddress[16];
148
    u16 nrpnValue[16];
149
    u8  lastSentNrpnAddressMsb;
150
    u8  lastSentNrpnAddressLsb;
151
    mios32_midi_port_t activeNrpnReceivePort;
1334 tk 152
};
153
 
154
#endif /* _MB_CV_ENVIRONMENT_H */