changeset 39:ef9c7ef09397

Bug fixes to standalone mode and MIDI outputs (now preserved on load)
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 21 Mar 2014 22:54:57 +0000
parents 4d97f5b4f599
children 50e4859d9769
files Source/GUI/KeyboardZoneComponent.cpp Source/GUI/KeyboardZoneComponent.h Source/MainApplicationController.cpp Source/TouchKeys/MidiKeyboardSegment.cpp Source/TouchKeys/MidiOutputController.cpp Source/TouchKeys/MidiOutputController.h
diffstat 6 files changed, 32 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/Source/GUI/KeyboardZoneComponent.cpp	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/GUI/KeyboardZoneComponent.cpp	Fri Mar 21 22:54:57 2014 +0000
@@ -190,7 +190,7 @@
         rangeHighComboBox->addItem(MainApplicationController::midiNoteName(note).c_str(), note);
     }
 
-    lastSelectedMidiOutputID_ = -100;
+    lastSelectedMidiOutputID_ = kInvalidMidiOutputId;
 
     //[/UserPreSize]
 
@@ -601,7 +601,7 @@
         counter++;
     }
 
-    if(!lastSelectedDeviceExists) {
+    if(!lastSelectedDeviceExists && lastSelectedMidiOutputID_ != kInvalidMidiOutputId) {
 #ifndef JUCE_WINDOWS
         if(lastSelectedMidiOutputID_ != MidiOutputController::kMidiVirtualOutputPortNumber)
             controller_->disableMIDIOutputPort(keyboardSegment_->outputPort());
--- a/Source/GUI/KeyboardZoneComponent.h	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/GUI/KeyboardZoneComponent.h	Fri Mar 21 22:54:57 2014 +0000
@@ -108,6 +108,10 @@
     //[UserVariables]   -- You can add your own custom variables in this section.
 
     enum {
+        kInvalidMidiOutputId = -100
+    };
+    
+    enum {
         // Offsets between Juce UI IDs and positions in vector
         kMidiOutputDeviceComboBoxOffset = 3,
         kMidiOutputModeComboBoxOffset = 1
--- a/Source/MainApplicationController.cpp	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/MainApplicationController.cpp	Fri Mar 21 22:54:57 2014 +0000
@@ -523,7 +523,15 @@
         return false;
         
     // Load the preset from this element
-    return midiInputController_.loadSegmentPreset(segmentsElement);
+    bool result = midiInputController_.loadSegmentPreset(segmentsElement);
+    
+    // Loading a preset won't set standalone mode; so re-enable it when finished
+    // if needed
+    if(touchkeyStandaloneModeEnabled_) {
+        midiTouchkeysStandaloneModeEnable();
+    }
+    
+    return result;
 }
 
 bool MainApplicationController::savePresetHelper(File& outputFile) {
@@ -539,7 +547,7 @@
 // Clear the current preset and restore default settings
 void MainApplicationController::clearPreset() {
     midiInputController_.removeAllSegments();
-    midiOutputController_.disableAllPorts();
+    //midiOutputController_.disableAllPorts();
     segmentCounter_ = 0;
     
     // Re-add a new segment, starting at 0
--- a/Source/TouchKeys/MidiKeyboardSegment.cpp	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/TouchKeys/MidiKeyboardSegment.cpp	Fri Mar 21 22:54:57 2014 +0000
@@ -556,7 +556,7 @@
     properties.setValue("outputChannelLowest", outputChannelLowest_);
     properties.setValue("outputTransposition", outputTransposition_);
     properties.setValue("damperPedalEnabled", damperPedalEnabled_);
-    properties.setValue("touchkeysStandaloneMode", touchkeyStandaloneMode_);
+    // Don't set standalone mode; that's an input parameter
     properties.setValue("usesKeyboardChannelPressure", usesKeyboardChannelPressure_);
     properties.setValue("usesKeyboardPitchWheel", usesKeyboardPitchWheel_);
     properties.setValue("usesKeyboardModWheel", usesKeyboardModWheel_);
@@ -613,9 +613,6 @@
     if(!properties.containsKey("damperPedalEnabled"))
         return false;
     damperPedalEnabled_ = properties.getBoolValue("damperPedalEnabled");
-    if(!properties.containsKey("touchkeysStandaloneMode"))
-        return false;
-    touchkeyStandaloneMode_ = properties.getBoolValue("touchkeysStandaloneMode");
     if(!properties.containsKey("usesKeyboardChannelPressure"))
         return false;
     usesKeyboardChannelPressure_ = properties.getBoolValue("usesKeyboardChannelPressure");
--- a/Source/TouchKeys/MidiOutputController.cpp	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/TouchKeys/MidiOutputController.cpp	Fri Mar 21 22:54:57 2014 +0000
@@ -23,6 +23,7 @@
 
 #include "MidiOutputController.h"
 
+#undef DEBUG_MIDI_OUTPUT_CONTROLLER
 #undef MIDI_OUTPUT_CONTROLLER_DEBUG_RAW
 
 // Constructor
@@ -70,7 +71,9 @@
         return false;
     }
     
-    //cout << "Enabling MIDI output port " << deviceNumber << " for ID " << identifier << "\n";
+#ifdef DEBUG_MIDI_OUTPUT_CONTROLLER
+    cout << "Enabling MIDI output port " << deviceNumber << " for ID " << identifier << "\n";
+#endif
     
     // Save the device in the set of ports
     MidiOutputControllerRecord record;
@@ -101,6 +104,10 @@
     
     activePorts_[identifier] = record;
     
+#ifdef DEBUG_MIDI_OUTPUT_CONTROLLER
+    cout << "Enabling virtual output port " << name << endl;
+#endif
+    
 	return true;
 }
 #endif
@@ -114,7 +121,9 @@
     if(device == 0)
         return;
     
-	//cout << "Disabling MIDI output " << activePorts_[identifier].portNumber << " for ID " << identifier << "\n";
+#ifdef DEBUG_MIDI_OUTPUT_CONTROLLER
+	cout << "Disabling MIDI output " << activePorts_[identifier].portNumber << " for ID " << identifier << "\n";
+#endif
     delete device;
     
 	activePorts_.erase(identifier);
@@ -123,8 +132,10 @@
 void MidiOutputController::disableAllPorts() {
     std::map<int, MidiOutputControllerRecord>::iterator it;
 	
-	//cout << "Disabling all MIDI output ports\n";
-	
+#ifdef DEBUG_MIDI_OUTPUT_CONTROLLER
+	cout << "Disabling all MIDI output ports\n";
+#endif
+    
 	it = activePorts_.begin();
 	
 	while(it != activePorts_.end()) {
@@ -154,54 +165,6 @@
     return ports;
 }
 
-/*
-// Open a new MIDI output port, given an index related to the list from
-// availableMidiDevices().  Returns true on success.
-
-bool MidiOutputController::openPort(int portNumber) {
-	// Close any previously open port
-    closePort();
-    
-    // Try to open the port
-    MidiOutput* device = MidiOutput::openDevice(portNumber);
-    if(device == 0)
-        return false;
-    
-    midiOut_ = device;
-    portNumber_ = portNumber;
-    
-    return true;
-}
-
-// Open a virtual MIDI port that other applications can connect to.
-// Returns true on success.
-
-bool MidiOutputController::openVirtualPort() {
-	// Close any previously open port
-    closePort();
-    
-    // Try to create a new port
-    MidiOutput* device = MidiOutput::createNewDevice(kMidiVirtualOutputName);
-    if(device == 0)
-        return false;
-    
-    midiOut_ = device;
-    portNumber_ = kMidiVirtualOutputPortNumber;
-    
-	return true;
-}
-
-// Close a currently open MIDI port
-void MidiOutputController::closePort() {
-    if(midiOut_ != 0) {
-        delete midiOut_;
-    }
-    
-    midiOut_ = 0;
-    portNumber_ = kMidiOutputNotOpen;
-}
- */
-
 // Send a MIDI Note On message
 void MidiOutputController::sendNoteOn(int port, unsigned char channel, unsigned char note, unsigned char velocity) {
 	sendMessage(port,
--- a/Source/TouchKeys/MidiOutputController.h	Fri Mar 21 16:17:29 2014 +0000
+++ b/Source/TouchKeys/MidiOutputController.h	Fri Mar 21 22:54:57 2014 +0000
@@ -60,14 +60,6 @@
     
     int enabledPort(int identifier);
     std::vector<std::pair<int, int> > enabledPorts();
-   
-	//bool openPort(int portNumber);
-	//bool openVirtualPort();
-	//void closePort();
-	
-	//bool isOpen() { return (midiOut_ != 0); }
-    //int activePort() { return portNumber_; }
-    //int numActivePorts() { return 1; } // TODO: implement me
 	
 	// Send MIDI messages
 	void sendNoteOn(int port, unsigned char channel, unsigned char note, unsigned char velocity);
@@ -86,9 +78,6 @@
 	~MidiOutputController() { disableAllPorts(); }
 	
 private:
-	//MidiOutput *midiOut_;	// Output instance from Juce; 0 if not open
-    //int portNumber_;        // Which port is currently open
-    
     std::map<int, MidiOutputControllerRecord> activePorts_;              // Destinations for MIDI data
 };