public void ActivateScene(int scene) { this.currentScene = scene; Debug.WriteLine($"Activate song '{currentSong.Name}' scene {currentScene}"); if (currentScene >= currentSong.SceneDescriptors.Count) { throw new Exception("Invalid scene number!"); } liveAmps = new List <LiveAmp>(currentSong.MidiProgram.Amps.Count); for (int i = 0; i < currentSong.MidiProgram.Amps.Count; i++) { var liveAmp = new LiveAmp(); liveAmps.Add(liveAmp); liveAmp.SceneDescriptor = currentSong.SceneDescriptors[currentScene]; liveAmp.SceneTone = liveAmp.SceneDescriptor.Amps[i]; liveAmp.ToneDefinition = liveAmp.SceneTone.AmpToneDefinition; liveAmp.AmpDefinition = liveAmp.ToneDefinition.AmpDefinition; // Figure out the song-specific override of tone: liveAmp.SongTone = currentSong.Amps?[i].Tones?.GetValueOrDefault(liveAmp.SceneTone.Tone); // Set the gain and volume: liveAmp.Gain = liveAmp.SceneTone.Gain ?? liveAmp.SongTone?.Gain ?? liveAmp.ToneDefinition.Gain; liveAmp.VolumeMIDI = liveAmp.SceneTone.Volume ?? liveAmp.SongTone?.Volume ?? liveAmp.ToneDefinition.Volume; // Combine tone definition with scene tone override: var blockNames = liveAmp.ToneDefinition.Blocks.Keys.ToHashSet(); // Set all the controller values for the selected tone: liveAmp.FX = ( from blockName in blockNames let blockDefinition = liveAmp.AmpDefinition.Blocks[blockName] let blockDefault = liveAmp.ToneDefinition.Blocks[blockName] let songBlockOverride = liveAmp.SongTone?.Blocks?.GetValueOrDefault(blockName) let sceneBlockOverride = liveAmp.SceneTone.Blocks?.GetValueOrDefault(blockName) select new LiveFX { BlockName = blockName, EnabledCC = blockDefinition.EnabledSwitchCC, XYSwitchCC = blockDefinition.XYSwitchCC, Enabled = sceneBlockOverride?.On ?? songBlockOverride?.On ?? blockDefault.On, XY = sceneBlockOverride?.XY ?? songBlockOverride?.XY ?? blockDefault.XY } ).ToList(); // Send MIDI updates: ActivateLiveAmp(liveAmp); } // TODO: send tempo SysEx message. }
public void ActivateLiveAmp(LiveAmp liveAmp) { Debug.WriteLine($"Amp[{liveAmp.AmpDefinition.AmpNumber + 1}]: gain val (CC {liveAmp.AmpDefinition.GainControllerCC:X2}h) to {liveAmp.Gain:X2}h"); midi.SetController(channel, liveAmp.AmpDefinition.GainControllerCC, liveAmp.Gain); Debug.WriteLine($"Amp[{liveAmp.AmpDefinition.AmpNumber + 1}]: volume val (CC {liveAmp.AmpDefinition.VolumeControllerCC:X2}h) to {liveAmp.VolumeMIDI:X2}h ({MIDItoDB(liveAmp.VolumeMIDI)} dB)"); midi.SetController(channel, liveAmp.AmpDefinition.VolumeControllerCC, liveAmp.VolumeMIDI); foreach (var liveFX in liveAmp.FX) { if (liveFX.Enabled.HasValue) { Debug.WriteLine($"Amp[{liveAmp.AmpDefinition.AmpNumber + 1}]: {liveFX.BlockName} 1/0 (CC {liveFX.EnabledCC:X2}h) to {(liveFX.Enabled.Value ? "on" : "off")}"); midi.SetController(channel, liveFX.EnabledCC, liveFX.Enabled.Value ? 0x7F : 0x00); } if (liveFX.XY.HasValue && liveFX.XYSwitchCC.HasValue) { Debug.WriteLine($"Amp[{liveAmp.AmpDefinition.AmpNumber + 1}]: {liveFX.BlockName} X/Y (CC {liveFX.XYSwitchCC.Value:X2}h) to {(liveFX.XY.Value == XYSwitch.X ? "X" : "Y")}"); midi.SetController(channel, liveFX.XYSwitchCC.Value, liveFX.XY.Value == XYSwitch.X ? 0x7F : 0x00); } } }