1 /+ 2 Copyright Elias Batek 2017 - 2018. 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE_1_0.txt or copy at 5 https://www.boost.org/LICENSE_1_0.txt) 6 +/ 7 module midigamepad.lib.translation.mapping; 8 9 import midigamepad.lib.keyboard : Scancode; 10 11 public import dplug.client.midi : MidiControlChange; 12 13 /++ 14 A collection that stores mappings 15 +/ 16 struct MappingsCollection 17 { 18 NoteOnOffMapping[] noteOnOff; 19 } 20 21 /++ 22 Mapping base 23 24 Used for mapping MIDI input messages to keyboard scancodes 25 +/ 26 struct Mapping 27 { 28 @nogc nothrow pure @safe: 29 30 /++/ 31 Scancode _base; 32 alias _base this; 33 34 /++ 35 ctor 36 +/ 37 this(ushort scancode, bool extended) 38 { 39 this._base = Scancode(scancode, extended); 40 } 41 } 42 43 /++ 44 Used for mapping MIDI note on/off messages to keyboard scancodes 45 +/ 46 struct NoteOnOffMapping 47 { 48 @nogc nothrow pure @safe: 49 50 /++/ 51 Mapping _base; 52 alias _base this; 53 54 /++ 55 MIDI note number 56 +/ 57 byte noteNumber; 58 59 /++ 60 ctor 61 +/ 62 this(ushort scancode, bool extended, byte noteNumber) 63 in 64 { 65 // validate MIDI note number 66 // upper bound is ensured by the data type 67 assert(noteNumber >= 0); 68 } 69 body 70 { 71 this._base = Mapping(scancode, extended); 72 this.noteNumber = noteNumber; 73 } 74 } 75 76 /++ 77 Used for mapping MIDI CC on/off messages to keyboard scancodes 78 +/ 79 struct CCOnOffMapping 80 { 81 @nogc nothrow pure @safe: 82 83 /++/ 84 Mapping _base; 85 alias _base this; 86 87 /++ 88 MIDI CC 89 +/ 90 MidiControlChange control; 91 92 /++ 93 ctor 94 +/ 95 this(ushort scancode, bool extended, MidiControlChange control) 96 { 97 this._base = Mapping(scancode, extended); 98 this.control = control; 99 } 100 }