Exemplo n.º 1
0
                public DeviceDiff(Song.Device a, Song.Device b, int index)
                {
                    this.a     = a;
                    this.b     = b;
                    this.index = index;

                    id    = a.Id != b.Id;
                    chunk = !a.Chunk.SequenceEqual(b.Chunk);
                }
Exemplo n.º 2
0
        private void GetInstruments()
        {
            instruments = new List <RnsIns>();
            int insId = 0;

            foreach (var instrument in project.Instruments.Instrument)
            {
                var rnsins = new RnsIns();
                rnsins.Name         = instrument.Name;
                rnsins.InstrumentId = insId;

                AudioPluginDevice plug = null;
                if (instrument.PluginGenerator != null)
                {
                    plug = instrument.PluginGenerator.PluginDevice;
                }
                else if (instrument.PluginProperties != null)
                {
                    plug = instrument.PluginProperties.PluginDevice;
                }

                if (plug != null)
                {
                    //var plug = instrument.PluginGenerator.PluginDevice;

                    Song.Device device = null;

                    Song.DeviceId deviceId;
                    if (Enum.TryParse <Song.DeviceId>(plug.PluginIdentifier, out deviceId))
                    {
                        device        = new Song.Device();
                        device.Id     = deviceId;
                        device.Chunk  = Convert.FromBase64String(FixBase64(plug.ParameterChunk));
                        rnsins.Device = device;
                    }
                    if (device == null)
                    {
                        logger.WriteLine(string.Format("WARNING: Instrument {0}[{2}] skipped (unsupported plugin): {1}",
                                                       instrument.Name, plug.PluginIdentifier, insId));
                    }
                }
                else
                {
                    logger.WriteLine(string.Format("WARNING: Instrument {0}[{1}] skipped (not a vst plugin)",
                                                   instrument.Name, insId));
                }

                instruments.Add(rnsins);
                insId++;
            }
        }
Exemplo n.º 3
0
        private AudioPluginDevice CreateDevice(Song.Device device)
        {
            var rnsDevice = (AudioPluginDevice)Utils.Deserializer(fxTemplate, typeof(AudioPluginDevice));

            var deviceName = device.Id.ToString();

            rnsDevice.Parameters.Parameter   = null;
            rnsDevice.ParameterChunk         = Convert.ToBase64String(device.Chunk);
            rnsDevice.PluginIdentifier       = deviceName;
            rnsDevice.PluginDisplayName      = string.Format("VST: Logicoma: {0}", deviceName);
            rnsDevice.PluginShortDisplayName = deviceName;

            return(rnsDevice);
        }
Exemplo n.º 4
0
        private Song.Device PlugToDevice(AudioPluginDevice plug)
        {
            Song.Device device = null;

            Song.DeviceId deviceId;
            if (Enum.TryParse <Song.DeviceId>(plug.PluginIdentifier, out deviceId))
            {
                device       = new Song.Device();
                device.Id    = deviceId;
                device.Chunk = Convert.FromBase64String(FixBase64(plug.ParameterChunk));
            }

            return(device);
        }
Exemplo n.º 5
0
        private Song.Device PlugToDevice(Plugin plug)
        {
            if (plug.Name == null)
            {
                return(null);
            }
            var name = plug.Name.Replace("WaveSabre - ", "");

            Song.Device device = null;

            Song.DeviceId deviceId;
            if (Enum.TryParse <Song.DeviceId>(name, out deviceId))
            {
                device       = new Song.Device();
                device.Id    = deviceId;
                device.Chunk = plug.State.Skip(21).ToArray();
            }

            return(device);
        }
Exemplo n.º 6
0
        public Song.Track CreateMaster()
        {
            var master = new Song.Track();

            master.Name   = "Master";
            master.Volume = project.MasterVolume.Volume;

            foreach (var f in project.MasterEffectsChain)
            {
                Song.Device device = null;

                Song.DeviceId deviceId;
                if (Enum.TryParse <Song.DeviceId>(f.Vst.VstFile.Replace(".dll", "").Replace(".64", ""), out deviceId))
                {
                    device       = new Song.Device();
                    device.Id    = deviceId;
                    device.Chunk = f.Vst.VstChunkData;
                }
                if (device == null)
                {
                    logger.WriteLine("WARNING: Device skipped (unsupported plugin): " + f.Vst.VstFile);
                }

                /*else if (f.Vst.Bypass)
                 * {
                 *  logger.WriteLine("WARNING: Device skipped (bypass enabled): " + projectDevice.PluginDll);
                 * }*/

                master.Devices.Add(device);
                var deviceIndex = master.Devices.IndexOf(device);
                foreach (var a in f.Automations)
                {
                    master.Automations.Add(ConvertAutomation(a, deviceIndex, "Master"));
                }
            }

            return(master);
        }
Exemplo n.º 7
0
        public Song.Track CreateTrack(ReaperTrack reaperTrack)
        {
            var track = new Song.Track();

            track.Name   = reaperTrack.TrackName;
            track.Volume = reaperTrack.VolumePanning.Volume;

            if (reaperTrack.VolumePanning.Pan != 0)
            {
                logger.WriteLine("WARNING: Pan value {0} on track {1} unsupported", reaperTrack.VolumePanning.Pan, reaperTrack.TrackName);
            }

            // add receives
            foreach (var r in reaperTrack.Receives)
            {
                if (r.ReceiveFader != ReaperFader.PostFader)
                {
                    logger.WriteLine("WARNING: Receive fader type of {0} on track {1} unsupported", r.ReceiveFader, reaperTrack.TrackName);
                }

                var receive = new Song.Receive();
                receive.SendingTrackIndex     = r.ReceiveTrackId + 1;   // master always zero, so tracks are out by one
                receive.ReceivingChannelIndex = r.DestinationChannelIndex;
                receive.Volume = r.Volume;
                track.Receives.Add(receive);
            }

            foreach (var f in reaperTrack.EffectsChain)
            {
                if (f.Wet != 0)
                {
                    logger.WriteLine("WARNING: Wet value for effect {0} on track {1} unsupported", f.Vst.VstFile, reaperTrack.TrackName);
                }

                Song.Device device = null;

                Song.DeviceId deviceId;
                if (Enum.TryParse <Song.DeviceId>(f.Vst.VstFile.Replace(".dll", "").Replace(".64", ""), out deviceId))
                {
                    device       = new Song.Device();
                    device.Id    = deviceId;
                    device.Chunk = f.Vst.VstChunkData;
                }
                if (device == null)
                {
                    logger.WriteLine("WARNING: Device skipped (unsupported plugin): " + f.Vst.VstFile);
                }

                /*else if (f.Vst.Bypass)  // TODO: Parse out Bypass
                 * {
                 *  logger.WriteLine("WARNING: Device skipped (bypass enabled): " + projectDevice.PluginDll);
                 * }*/

                track.Devices.Add(device);
                var deviceIndex = track.Devices.IndexOf(device);
                foreach (var a in f.Automations)
                {
                    track.Automations.Add(ConvertAutomation(a, deviceIndex, reaperTrack.TrackName));
                }

                track.Events = ConvertMidi(reaperTrack.MediaItems);
            }

            return(track);
        }
Exemplo n.º 8
0
        public Song Process(LiveProject project, ILog logger)
        {
            this.logger = logger;

            var song = new Song();

            song.Tempo      = (int)project.Tempo;
            song.SampleRate = 44100;

            var projectLoopEnd = project.LoopStart + project.LoopLength;

            trackReceives = new Dictionary <LiveProject.Track, List <Receive> >();
            foreach (var projectTrack in project.Tracks)
            {
                trackReceives.Add(projectTrack, new List <Receive>());
            }
            foreach (var projectTrack in project.Tracks)
            {
                foreach (var send in projectTrack.Sends)
                {
                    if (send.IsActive)
                    {
                        trackReceives[send.ReceivingTrack].Add(new Receive(projectTrack, send.ReceivingChannelIndex - 1, send.Volume));
                    }
                }
            }

            project.MasterTrack.Name = project.MasterTrack.Name == "" ? "Master" : project.MasterTrack.Name;

            visitedTracks = new List <LiveProject.Track>();
            orderedTracks = new List <LiveProject.Track>();

            visitTrack(project.MasterTrack);

            var projectTracksToSongTracks = new Dictionary <LiveProject.Track, Song.Track>();
            var songTrackEvents           = new Dictionary <Song.Track, List <Event> >();

            double?minEventTime = null;
            double?maxEventTime = null;

            foreach (var projectTrack in orderedTracks)
            {
                var track = new Song.Track();
                track.Name   = projectTrack.Name;
                track.Volume = (float)projectTrack.Volume;

                foreach (var projectDevice in projectTrack.Devices)
                {
                    Song.Device device = null;

                    Song.DeviceId deviceId;
                    if (Enum.TryParse <Song.DeviceId>(projectDevice.PluginDll.Replace(".dll", "").Replace(".64", ""), out deviceId))
                    {
                        device       = new Song.Device();
                        device.Id    = deviceId;
                        device.Chunk = projectDevice.RawData != null ? (byte[])projectDevice.RawData.Clone() : new byte[0];
                    }
                    if (device == null)
                    {
                        logger.WriteLine("WARNING: Device skipped (unsupported plugin): " + projectDevice.PluginDll);
                    }
                    else if (projectDevice.Bypass)
                    {
                        logger.WriteLine("WARNING: Device skipped (bypass enabled): " + projectDevice.PluginDll);
                    }
                    else
                    {
                        track.Devices.Add(device);

                        foreach (var floatParameter in projectDevice.FloatParameters)
                        {
                            if (floatParameter.Id >= 0)
                            {
                                var automation = new Song.Automation();
                                automation.DeviceIndex = track.Devices.IndexOf(device);
                                automation.ParamId     = floatParameter.Id;
                                foreach (var e in floatParameter.Events)
                                {
                                    if (e.Time >= 0.0)
                                    {
                                        var point = new Song.Point();
                                        point.TimeStamp = secondsToSamples(e.Time, (double)song.Tempo, (double)song.SampleRate);
                                        point.Value     = e.Value;
                                        automation.Points.Add(point);
                                    }
                                }
                                if (automation.Points.Count > 0)
                                {
                                    track.Automations.Add(automation);
                                }
                            }
                        }
                    }
                }

                var events = new List <Event>();
                foreach (var midiClip in projectTrack.MidiClips)
                {
                    if (!midiClip.IsDisabled)
                    {
                        var loopLength = midiClip.LoopEnd - midiClip.LoopStart;
                        for (var currentTime = midiClip.CurrentStart; currentTime < midiClip.CurrentEnd; currentTime += loopLength)
                        {
                            foreach (var keyTrack in midiClip.KeyTracks)
                            {
                                foreach (var note in keyTrack.Notes)
                                {
                                    if (note.IsEnabled)
                                    {
                                        var startTime = note.Time - (currentTime - midiClip.CurrentStart) - midiClip.LoopStartRelative;
                                        while (startTime < 0.0)
                                        {
                                            startTime += loopLength;
                                        }
                                        startTime = currentTime + startTime - midiClip.LoopStart;
                                        var endTime = startTime + note.Duration;

                                        if ((startTime >= midiClip.CurrentStart && startTime < midiClip.CurrentEnd) &&
                                            (!project.IsLoopOn || (
                                                 startTime >= project.LoopStart && startTime < projectLoopEnd)))
                                        {
                                            endTime = Math.Min(endTime, midiClip.CurrentEnd);
                                            if (project.IsLoopOn)
                                            {
                                                endTime = Math.Min(endTime, projectLoopEnd);
                                            }
                                            if (endTime > startTime)
                                            {
                                                var startEvent = new Event();
                                                startEvent.Time     = startTime;
                                                startEvent.Type     = Song.EventType.NoteOn;
                                                startEvent.Note     = (byte)keyTrack.MidiKey;
                                                startEvent.Velocity = (byte)note.Velocity;
                                                events.Add(startEvent);

                                                var endEvent = new Event();
                                                endEvent.Time = endTime;
                                                endEvent.Type = Song.EventType.NoteOff;
                                                endEvent.Note = (byte)keyTrack.MidiKey;
                                                events.Add(endEvent);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                events.Sort((a, b) =>
                {
                    if (a.Time > b.Time)
                    {
                        return(1);
                    }
                    if (a.Time < b.Time)
                    {
                        return(-1);
                    }
                    if (a.Type == Song.EventType.NoteOn && b.Type == Song.EventType.NoteOff)
                    {
                        return(1);
                    }
                    if (a.Type == Song.EventType.NoteOff && b.Type == Song.EventType.NoteOn)
                    {
                        return(-1);
                    }
                    return(0);
                });
                foreach (var e in events)
                {
                    if (!minEventTime.HasValue || e.Time < minEventTime.Value)
                    {
                        minEventTime = e.Time;
                    }
                    if (!maxEventTime.HasValue || e.Time > maxEventTime.Value)
                    {
                        maxEventTime = e.Time;
                    }
                }

                projectTracksToSongTracks.Add(projectTrack, track);
                songTrackEvents.Add(track, events);
                song.Tracks.Add(track);
            }

            double songStartTime, songEndTime;

            if (project.IsLoopOn)
            {
                songStartTime = project.LoopStart;
                songEndTime   = projectLoopEnd;
            }
            else if (minEventTime.HasValue && maxEventTime.HasValue)
            {
                songStartTime = minEventTime.Value;
                songEndTime   = maxEventTime.Value;
            }
            else
            {
                throw new Exception("Couldn't find song start/end times");
            }
            song.Length = (songEndTime - songStartTime) * 60.0 / (double)song.Tempo;

            foreach (var kvp in songTrackEvents)
            {
                var track  = kvp.Key;
                var events = kvp.Value;

                int lastTimeStamp = 0;
                foreach (var e in events)
                {
                    var songEvent = new Song.Event();
                    var time      = e.Time - songStartTime;
                    int timeStamp = Math.Max(secondsToSamples(time, (double)song.Tempo, (double)song.SampleRate), lastTimeStamp);

                    songEvent.TimeStamp = secondsToSamples(time, (double)song.Tempo, (double)song.SampleRate);
                    songEvent.Type      = e.Type;
                    songEvent.Note      = e.Note;
                    songEvent.Velocity  = e.Velocity;
                    track.Events.Add(songEvent);
                    lastTimeStamp = timeStamp;
                }
            }

            // TODO: Clip all of this instead of just offsetting
            // adjust automation start times based on song start
            foreach (var track in song.Tracks)
            {
                foreach (var automation in track.Automations)
                {
                    foreach (var point in automation.Points)
                    {
                        point.TimeStamp -= secondsToSamples(songStartTime, (double)song.Tempo, (double)song.SampleRate);
                    }
                }
            }

            foreach (var kvp in projectTracksToSongTracks)
            {
                foreach (var projectReceive in trackReceives[kvp.Key])
                {
                    if (projectTracksToSongTracks.ContainsKey(projectReceive.SendingTrack))
                    {
                        var receive = new Song.Receive();
                        receive.SendingTrackIndex     = song.Tracks.IndexOf(projectTracksToSongTracks[projectReceive.SendingTrack]);
                        receive.ReceivingChannelIndex = projectReceive.ReceivingChannelIndex;
                        receive.Volume = (float)projectReceive.Volume;
                        kvp.Value.Receives.Add(receive);
                    }
                }
            }

            return(song);
        }