Esempio n. 1
0
        //set cur pos in sequence to a specific tick, only if stoppped
        public void setCurrentPos(int _ticknum)
        {
            if (!isPlaying)
            {
                tickNum = _ticknum;
                Tempo tempo = tempoMap.findTempo(tickNum, out tempoPos);
                setTempo(tempo);

                int tickOfs = _ticknum - curTempo.tick;                 //num of ticks from prev tempo msg to now
                tickTime = (curTempo.time * 10L) + (tickOfs * tickLen); //prev tempo's time (in usec/10) + time of ticks to now

                startOffset = tickTime;                                 //the elapsed time since seq start
                startTime   = DateTime.Now.Ticks - startOffset;         //start time is when we would have started playing up to now

                Meter meter = meterMap.findMeter(tickNum, out meterPos);
                setMeter(meter);

                //set cur pos in each track
                //find and send most recent patch change message for each track
                for (int trackNum = 0; trackNum < trackCount; trackNum++)
                {
                    Track        track  = seq.tracks[trackNum];
                    List <Event> events = seq.tracks[trackNum].events;
                    trackPos[trackNum] = 0;
                    PatchChangeMessage patchmsg = null;
                    for (int i = 0; i < events.Count; i++)
                    {
                        Event evt = events[i];
                        if (evt is MessageEvent && (((MessageEvent)evt).msg is PatchChangeMessage))
                        {
                            patchmsg = (PatchChangeMessage)((MessageEvent)evt).msg;
                        }
                        if (events[i].tick >= _ticknum)
                        {
                            break;
                        }
                        trackPos[trackNum]++;
                    }
                    if (patchmsg != null)
                    {
                        track.sendMessage(patchmsg);
                    }
                }
            }
        }