Skip to content

Commit

Permalink
Merge pull request #35 from DhrBaksteen/Midi_Fixes
Browse files Browse the repository at this point in the history
MIDI fixes for Teensy and Windows 3.1 instrument defs
  • Loading branch information
DhrBaksteen authored Nov 18, 2018
2 parents 24c8199 + 404fc2c commit 61422c7
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ This repository contains the OPL2 Audio Board library for Arduino, Teensy, Raspb
* Experiment with the YM3812 chip
* Build your own synthesizer
* Play your own OPL2 tunes
* Instrument definitions from Adlib, The Fat Man and Windows 3.1
* Play exported OPL2 music (DRO, IMF, VGM) or Reality Adlib Tracker music files
* Use the board as a MIDI synthesizer (Teensy++ 2.0 and later example included)
* Emulation with DosBox you can use the board to output MIDI music (Teensy++ 2.0 and later)
* Emulation with DosBox; you can use the board to output MIDI music (Teensy++ 2.0 and later)

Current library version is 1.4.2
Current library version is 1.4.4

To obtain your own OPL2 Audio Board visit the [Tindie store](https://www.tindie.com/products/DhrBaksteen/opl2-audio-board/).

Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "\033[1;36m / | \\ | / /_/ | | ( /_/ ) | | ( /_/ ) __ \\|
echo "\033[1;34m \\____|__ /____/\\____ | |__|\\___/ |______ /\\___(____ /__| \\____ | "
echo "\033[1;34m \\/ \\/ \\/ \\/ \\/ \033[0m"
echo "Installation script for Raspberry Pi and compatibles"
echo "Library version 1.4.2, 14th of July 2018"
echo "Library version 1.4.4, 18th of November 2018"
echo "Copyright (c) 2016-2018 Maarten Janssen, Cheerful"
echo ""

Expand Down
18 changes: 14 additions & 4 deletions examples/Teensy/TeensyMidi/TeensyMidi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <SPI.h>
#include <OPL2.h>

// For better results with midi files created for Window exchange midi_instruments.h for midi_instruments_win31.h
// #include <midi_instruments_win31.h>
#include <midi_instruments.h>
#include <midi_drums.h>

Expand Down Expand Up @@ -55,6 +58,9 @@ void setup() {
usbMIDI.setHandleControlChange(onControlChange);
usbMIDI.setHandleSystemReset(onSystemReset);
onSystemReset();

opl2.setDeepVibrato(true);
opl2.setDeepTremolo(true);
}


Expand Down Expand Up @@ -123,6 +129,8 @@ void setOpl2ChannelVolume(byte opl2Channel, byte midiChannel) {
* Handle a note on MIDI event to play a note.
*/
void onNoteOn(byte channel, byte note, byte velocity) {
channel = channel % 16;

// Treat notes with a velocity of 0 as note off.
if (velocity == 0) {
onNoteOff(channel, note, velocity);
Expand Down Expand Up @@ -167,6 +175,7 @@ void onNoteOn(byte channel, byte note, byte velocity) {
* Handle a note off MIDI event to stop playing a note.
*/
void onNoteOff(byte channel, byte note, byte velocity) {
channel = channel % 16;
for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
if (channelMap[i].midiChannel == channel && channelMap[i].midiNote == note) {
opl2.setKeyOn(i, false);
Expand All @@ -180,20 +189,21 @@ void onNoteOff(byte channel, byte note, byte velocity) {
* Handle instrument change on the given MIDI channel.
*/
void onProgramChange(byte channel, byte program) {
programMap[channel] = min(program, 127);
programMap[channel % 16] = min(program, 127);
}


/**
* Handle MIDI control changes on the given channel.
*/
void onControlChange(byte channel, byte control, byte value) {
channel = channel % 16;

switch (control) {

// Change volume of a MIDI channel.
// Change volume of a MIDI channel. (Limited to 0.8 to prevent clipping)
case CONTROL_VOLUME: {
channelVolumes[channel] = round(min(value, 63) / 63.0);

channelVolumes[channel] = min(value / 127.0, 0.8);
for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
if (channelMap[i].midiChannel == channel && opl2.getKeyOn(i)) {
setOpl2ChannelVolume(i, channel);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arduino OPL2
version=1.4.3
version=1.4.4
author=Maarten Janssen <maarten@cheerful.nl>
maintainer=Maarten Janssen <maarten@cheerful.nl>
sentence=Use this library to control the OPL2 Audio Board
Expand Down
4 changes: 2 additions & 2 deletions src/OPL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* \____|__ /__| \____ |____/|__|___| /\____/ \_____\ \ |____| |__|
* \/ \/ \/ \/
*
* YM3812 OPL2 Audio Library for Arduino, Raspberry Pi and Orange Pi v1.4.2
* YM3812 OPL2 Audio Library for Arduino, Raspberry Pi and Orange Pi v1.4.4
* Code by Maarten Janssen (maarten@cheerful.nl) 2016-12-18
*
* Look for example code on how to use this library in the examples folder.
Expand All @@ -35,7 +35,7 @@
* IMPORTANT: Make sure you set the correct BOARD_TYPE in OPL2.h. Default is set to Arduino.
*
*
* Last updated 2018-07-02
* Last updated 2018-11-18
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2
* Details about the YM3812 and OPL chips can be found at http://www.shikadi.net/moddingwiki/OPL_chip
*
Expand Down
Loading

0 comments on commit 61422c7

Please sign in to comment.