Subversion Repositories svn.mios32

Rev

Rev 1397 | 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: MbCvMidiVoice.cpp 1960 2014-02-09 20:21:24Z tk $
3
/*
4
 * MIDIbox CV MIDI Voice Handlers
5
 *
6
 * ==========================================================================
7
 *
8
 *  Copyright (C) 2010 Thorsten Klose (tk@midibox.org)
9
 *  Licensed for personal non-commercial use only.
10
 *  All other rights reserved.
11
 *
12
 * ==========================================================================
13
 */
14
 
15
#include <string.h>
16
#include "MbCvMidiVoice.h"
17
 
18
 
19
/////////////////////////////////////////////////////////////////////////////
20
// Constructor
21
/////////////////////////////////////////////////////////////////////////////
22
MbCvMidiVoice::MbCvMidiVoice()
23
{
24
    init();
25
}
26
 
27
 
28
/////////////////////////////////////////////////////////////////////////////
29
// Destructor
30
/////////////////////////////////////////////////////////////////////////////
31
MbCvMidiVoice::~MbCvMidiVoice()
32
{
33
}
34
 
35
 
36
/////////////////////////////////////////////////////////////////////////////
37
// MIDI Voice init function
38
/////////////////////////////////////////////////////////////////////////////
39
void MbCvMidiVoice::init(void)
40
{
41
    midivoiceEnabledPorts = 0x1011; // OSC1, IN1 and USB1
42
    midivoiceChannel = 1; // 0 disables the channel
43
    midivoiceSplitLower = 0x00;
44
    midivoiceSplitUpper = 0x7f;
45
    midivoiceTranspose = 0x40;
1960 tk 46
    midivoiceModWheel = 0;
47
    midivoicePitchBender = 0;
1334 tk 48
    midivoiceLastVoice = 0;
49
    midivoiceCCNumber = 16;
50
    midivoiceAftertouch = 0;
51
    midivoiceCCValue = 64;
52
    midivoiceNRPNValue = 8192;
53
 
54
    notestackReset();
55
}
56
 
57
 
58
/////////////////////////////////////////////////////////////////////////////
59
// returns true if Port, MIDI channel (and optionally split zone) matches
60
/////////////////////////////////////////////////////////////////////////////
61
bool MbCvMidiVoice::isAssignedPort(mios32_midi_port_t port)
62
{
63
    u8 subportMask = (1 << (port&3));
64
    u8 portClass = ((port-0x10) & 0xc)>>2;
65
    u8 portMask = subportMask << (4*portClass);
66
 
67
    return (midivoiceEnabledPorts & portMask);
68
}
69
 
70
bool MbCvMidiVoice::isAssigned(u8 chn)
71
{
72
    return chn == (midivoiceChannel-1);
73
}
74
 
75
bool MbCvMidiVoice::isAssigned(u8 chn, u8 note)
76
{
77
    return chn == (midivoiceChannel-1) &&
78
        note >= midivoiceSplitLower &&
79
        (!midivoiceSplitUpper || note <= midivoiceSplitUpper);
80
}
81
 
82
 
83
/////////////////////////////////////////////////////////////////////////////
84
// Notestack Handling
85
/////////////////////////////////////////////////////////////////////////////
86
void MbCvMidiVoice::notestackReset(void)
87
{
88
    NOTESTACK_Init(&midivoiceNotestack,
89
                   NOTESTACK_MODE_PUSH_TOP,
90
                   &midivoiceNotestackItems[0],
91
                   CV_SE_NOTESTACK_SIZE);
92
}
93
 
94
void MbCvMidiVoice::notestackPush(u8 note, u8 velocity)
95
{
96
    NOTESTACK_Push(&midivoiceNotestack, note, velocity);
97
}
98
 
99
s32 MbCvMidiVoice::notestackPop(u8 note)
100
{
101
    return NOTESTACK_Pop(&midivoiceNotestack, note);
102
}
103
 
104
/////////////////////////////////////////////////////////////////////////////
105
// maps incoming CC and NRPN
106
/////////////////////////////////////////////////////////////////////////////
107
void MbCvMidiVoice::setCC(u8 ccNumber, u8 value)
108
{
109
    // currently only a single CC value is supported, but could be more in future?
110
    if( ccNumber == midivoiceCCNumber )
111
        midivoiceCCValue = value;
112
}
113
 
1394 tk 114
void MbCvMidiVoice::setNRPN(u16 value)
1334 tk 115
{
1394 tk 116
    // always assigned to NRPN LSB 0, MSB depends on channel (decoded outside)
117
    midivoiceNRPNValue = value; // 14bit
1334 tk 118
}
1397 tk 119
 
120
/////////////////////////////////////////////////////////////////////////////
121
// help functions for editor
122
/////////////////////////////////////////////////////////////////////////////
123
void MbCvMidiVoice::setPortEnabled(const u8& portIx, const bool& enable)
124
{
125
    if( enable )
126
        midivoiceEnabledPorts |= (1 << portIx);
127
    else
128
        midivoiceEnabledPorts &= ~(1 << portIx);
129
}
130
 
131
bool MbCvMidiVoice::getPortEnabled(const u8& portIx)
132
{
133
    return (midivoiceEnabledPorts & (1 << portIx)) ? 1 : 0;
134
}