void parseMixer(LiveProject.Track track, bool isMasterTrack) { while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Mixer")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Sends": if (!reader.IsEmptyElement) { parseSends(track); } break; case "Speaker": while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "BoolEvent") { track.IsSpeakerOn = getBoolValueAttrib(); break; } } break; case "Volume": while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "FloatEvent") { track.Volume = getDoubleValueAttrib(); break; } } break; case "Tempo": if (isMasterTrack) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "FloatEvent") { project.Tempo = getDoubleValueAttrib(); break; } } } break; } } } }
void visitTrack(LiveProject.Track projectTrack) { if (visitedTracks.Contains(projectTrack) || !projectTrack.IsSpeakerOn) { return; } visitedTracks.Add(projectTrack); foreach (var projectReceive in trackReceives[projectTrack]) { if (projectReceive.Volume > 0.0) { visitTrack(projectReceive.SendingTrack); } } orderedTracks.Add(projectTrack); }
void parseTrack(bool isMasterTrack = false, bool isReturnTrack = false) { var track = new LiveProject.Track(); returnSendInfos.Add(track, new List <ReturnSendInfo>()); if (!isMasterTrack) { track.Id = getAttrib("Id"); } while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && (reader.Name == "MasterTrack" || reader.Name == "MidiTrack" || reader.Name == "AudioTrack" || reader.Name == "ReturnTrack" || reader.Name == "GroupTrack"))) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Name": if (track.Name == null) { reader.ReadToFollowing("UserName"); track.Name = getValueAttrib(); } break; case "DeviceChain": case "MasterChain": if (!reader.IsEmptyElement) { parseDeviceChain(track, isMasterTrack); } break; case "TrackGroupId": track.TrackGroupId = getValueAttrib(); break; } } } project.Tracks.Add(track); if (isReturnTrack) { project.ReturnTracks.Add(track); } if (isMasterTrack) { project.MasterTrack = track; } }
void parseDeviceChain(LiveProject.Track track, bool isMasterTrack) { while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && (reader.Name == "DeviceChain" || reader.Name == "MasterChain"))) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "DeviceChain": if (!reader.IsEmptyElement) { parseInnerDeviceChain(track); } break; case "AudioOutputRouting": if (!isMasterTrack) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Target") { outputRoutingStrings.Add(track, getValueAttrib()); break; } } } break; case "Mixer": if (!reader.IsEmptyElement) { parseMixer(track, isMasterTrack); } break; case "MainSequencer": if (!reader.IsEmptyElement) { parseMainSequencer(track); } break; } } } }
void parseClipTimeable(LiveProject.Track track) { while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "ClipTimeable")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "MidiClip": if (!reader.IsEmptyElement) { parseMidiClip(track); } break; } } } }
void parseSends(LiveProject.Track track) { while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Sends")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "TrackSendHolder": var returnSendInfo = new ReturnSendInfo(); if (!reader.IsEmptyElement) { parseTrackSendHolder(returnSendInfo); } returnSendInfos[track].Add(returnSendInfo); break; } } } }
void parseInnerDeviceChain(LiveProject.Track track) { while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "DeviceChain")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "PluginDevice": var device = new LiveProject.Device(); if (!reader.IsEmptyElement) { parsePluginDevice(device); } track.Devices.Add(device); break; } } } }
void parseMidiClip(LiveProject.Track track) { var midiClip = new LiveProject.MidiClip(); while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "MidiClip")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "CurrentStart": midiClip.CurrentStart = getDoubleValueAttrib(); break; case "CurrentEnd": midiClip.CurrentEnd = getDoubleValueAttrib(); break; case "Loop": if (!reader.IsEmptyElement) { parseMidiClipLoop(midiClip); } break; case "Disabled": midiClip.IsDisabled = getBoolValueAttrib(); break; case "KeyTracks": if (!reader.IsEmptyElement) { parseKeyTracks(midiClip); } break; } } } track.MidiClips.Add(midiClip); }
public Receive(LiveProject.Track sendingTrack, int receivingChannelIndex, double volume) { SendingTrack = sendingTrack; ReceivingChannelIndex = receivingChannelIndex; Volume = volume; }
public LiveProject Process(string fileName) { project = new LiveProject(); outputRoutingStrings = new Dictionary <LiveProject.Track, string>(); returnSendInfos = new Dictionary <LiveProject.Track, List <ReturnSendInfo> >(); using (var originalStream = new FileInfo(fileName).OpenRead()) { using (var decompressionStream = new GZipStream(originalStream, CompressionMode.Decompress)) { using (reader = XmlReader.Create(decompressionStream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Tracks": while (reader.Read() && !(reader.NodeType == XmlNodeType.EndElement && reader.Name == "Tracks")) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "MidiTrack": case "AudioTrack": case "GroupTrack": parseTrack(); break; case "ReturnTrack": parseTrack(false, true); break; } } } break; case "MasterTrack": parseTrack(true); break; case "Transport": parseTransport(); break; } } } } } } foreach (var kvp in outputRoutingStrings) { try { var routingString = kvp.Value; switch (routingString) { case "AudioOut/None": break; case "AudioOut/Master": kvp.Key.Sends.Add(new LiveProject.Send(project.MasterTrack, 1, 1.0, kvp.Key.IsSpeakerOn)); break; default: if (!routingString.StartsWith("AudioOut/")) { throw new Exception("routing string must begin with \"AudioOut/\""); } routingString = routingString.Replace("AudioOut/", ""); if (!routingString.StartsWith("Track.") && routingString != "GroupTrack") { throw new Exception("unrecognized routing string format"); } string trackId = ""; string trackInputId = ""; if (routingString == "GroupTrack") { trackId = kvp.Key.TrackGroupId; trackInputId = ""; } else { routingString = routingString.Replace("Track.", ""); var parts = routingString.Split('/'); if (routingString != "GroupTrack" && parts.Length != 2) { throw new Exception("routing string has too many parts"); } trackId = parts[0]; trackInputId = parts[1]; } LiveProject.Track sendTarget = null; int sendTargetChannelIndex = 1; foreach (var track in project.Tracks) { if (track != kvp.Key && track.Id == trackId) { sendTarget = track; break; } } if (sendTarget == null) { throw new Exception("couldn't find target track"); } if (routingString != "GroupTrack" && trackInputId != "TrackIn") { if (!trackInputId.StartsWith("DeviceIn.")) { throw new Exception("unrecognized track input string"); } trackInputId = trackInputId.Replace("DeviceIn.", ""); var parts = trackInputId.Split('.'); if (parts.Length != 2) { throw new Exception("unrecognized track device input string"); } if (parts[1] != "S1") { throw new Exception("unrecognized track device input channel"); } var deviceId = parts[0]; bool found = false; foreach (var device in sendTarget.Devices) { if (device.Id == deviceId) { found = true; break; } } if (!found) { throw new Exception("couldn't find target track device"); } sendTargetChannelIndex = 3; } kvp.Key.Sends.Add(new LiveProject.Send(sendTarget, sendTargetChannelIndex, 1.0, kvp.Key.IsSpeakerOn)); break; } } catch (Exception e) { throw new Exception("Unrecognized AudioOutputRouting: " + kvp.Value + " (" + e.Message + ")"); } } foreach (var kvp in returnSendInfos) { foreach (var returnSendInfo in kvp.Value) { // Cull sends whose value is -inf if (returnSendInfo.Volume > returnSendInfo.MinVolume) { kvp.Key.Sends.Add(new LiveProject.Send(project.ReturnTracks[kvp.Value.IndexOf(returnSendInfo)], 1, returnSendInfo.Volume, returnSendInfo.IsActive)); } } } return(project); }