Example #1
0
        private string TransformSequence()
        {
            var sequence    = new ChannelMapperSequence(_sourceSequence.FileName);
            var numOfEvents = sequence.GetEventCount();

            var oldNumOfChannels = _sourceProfile.GetChannelCount();
            var newNumOfChannels = _destinationProfile.GetChannelCount();
            var newEventValues   = new byte[newNumOfChannels, numOfEvents];
            var oldEventValues   = new byte[oldNumOfChannels, numOfEvents];


            var oldEventData   = Convert.FromBase64String(sequence.EventData);
            var oldEventLength = oldEventData.Length;

            var currentEvent = 0;

            for (var chan = 0; chan < oldNumOfChannels; chan++)
            {
                for (var thisEvent = 0; currentEvent < oldEventLength && thisEvent < numOfEvents; thisEvent++)
                {
                    oldEventValues[chan, thisEvent] = oldEventData[currentEvent++];
                }
            }

            //writeChannels("oldChannels.txt", oldEventValues, oldNumOfChannels, numOfEvents);

            var mapSplit     = new[] { ';' };
            var channelSplit = new[] { ':' };
            var elementSplit = new[] { ' ' };

            var channels = GetMap().Split(mapSplit, StringSplitOptions.RemoveEmptyEntries);

            foreach (var channel in channels)
            {
                var elements = channel.Split(channelSplit, StringSplitOptions.RemoveEmptyEntries);

                if (elements.Length <= 1)
                {
                    continue;
                }

                var from       = int.Parse(elements[0]);
                var toChannels = elements[1].Split(elementSplit, StringSplitOptions.RemoveEmptyEntries);
                foreach (var toChannel in toChannels)
                {
                    var to = int.Parse(toChannel);
                    for (var i = 0; i < numOfEvents; i++)
                    {
                        var destinationChannel = _destinationProfile.GetChannelLocation(to);
                        var sourceChannel      = _sourceProfile.GetChannelLocation(from);
                        var oldEventValue      = oldEventValues[sourceChannel, i];
                        newEventValues[destinationChannel, i] = oldEventValue;
                    }
                }
            }

            //writeChannels("newChannels.txt", newEventValues, newNumOfChannels, numOfEvents);

            var newEventData = new byte[newNumOfChannels * numOfEvents];
            var index        = 0;

            for (var i = 0; i < newNumOfChannels; i++)
            {
                for (var j = 0; j < numOfEvents; j++)
                {
                    newEventData[index++] = newEventValues[i, j];
                }
            }

            sequence.EventData = Convert.ToBase64String(newEventData);

            return(sequence.SaveNewData(_destinationProfile.GetFileName()));
        }
Example #2
0
        private string TransformSequence()
        {
            var sequence = new ChannelMapperSequence(_sourceSequence.FileName);
            var numOfEvents = sequence.GetEventCount();

            var oldNumOfChannels = _sourceProfile.GetChannelCount();
            var newNumOfChannels = _destinationProfile.GetChannelCount();
            var newEventValues = new byte[newNumOfChannels, numOfEvents];
            var oldEventValues = new byte[oldNumOfChannels, numOfEvents];

            var oldEventData = Convert.FromBase64String(sequence.EventData);
            var oldEventLength = oldEventData.Length;

            var currentEvent = 0;

            for (var chan = 0; chan < oldNumOfChannels; chan++) {
                for (var thisEvent = 0; currentEvent < oldEventLength && thisEvent < numOfEvents; thisEvent++) {
                    oldEventValues[chan, thisEvent] = oldEventData[currentEvent++];
                }
            }

            //writeChannels("oldChannels.txt", oldEventValues, oldNumOfChannels, numOfEvents);

            var mapSplit = new[] { ';' };
            var channelSplit = new[] { ':' };
            var elementSplit = new[] { ' ' };

            var channels = GetMap().Split(mapSplit, StringSplitOptions.RemoveEmptyEntries);
            foreach (var channel in channels) {
                var elements = channel.Split(channelSplit, StringSplitOptions.RemoveEmptyEntries);

                if (elements.Length <= 1) continue;

                var from = int.Parse(elements[0]);
                var toChannels = elements[1].Split(elementSplit, StringSplitOptions.RemoveEmptyEntries);
                foreach (var toChannel in toChannels) {
                    var to = int.Parse(toChannel);
                    for (var i = 0; i < numOfEvents; i++) {
                        var destinationChannel = _destinationProfile.GetChannelLocation(to);
                        var sourceChannel = _sourceProfile.GetChannelLocation(from);
                        var oldEventValue = oldEventValues[sourceChannel, i];
                        newEventValues[destinationChannel, i] = oldEventValue;
                    }
                }
            }

            //writeChannels("newChannels.txt", newEventValues, newNumOfChannels, numOfEvents);

            var newEventData = new byte[newNumOfChannels * numOfEvents];
            var index = 0;
            for (var i = 0; i < newNumOfChannels; i++) {
                for (var j = 0; j < numOfEvents; j++) {
                    newEventData[index++] = newEventValues[i, j];
                }
            }

            sequence.EventData = Convert.ToBase64String(newEventData);

            return sequence.SaveNewData(_destinationProfile.GetFileName());
        }