Example #1
0
        private void PlayNote(ChannelNote dstNote)
        {
            if (dstNote != null &&
                (_lastNote == null || _lastNote.Octave != dstNote.Octave || _lastNote.Note != dstNote.Note ||
                 _lastNote.Seminote != dstNote.Seminote || _lastNote.Instrument != dstNote.Instrument))
            {
                player.Stop();

                Song tempSong = SerializationUtils.Clone(ApplicationState.Instance.CurrentSong);
                tempSong.PlayOrder.Clear();
                tempSong.Patterns.Clear();
                tempSong.Looped = true;
                tempSong.Patterns.Add(new Pattern()
                {
                    Length = 256, Channels = tempSong.Channels
                });
                tempSong.PlayOrder.Add(0);
                ChannelNote tmpNote = tempSong.Patterns[0].Lines[0].Notes[0];
                tmpNote.EnvData     = dstNote.EnvData;
                tmpNote.Instrument  = this.CurrentInstrument.ID;
                tmpNote.Note        = dstNote.Note;
                tmpNote.Octave      = dstNote.Octave;
                tmpNote.Seminote    = dstNote.Seminote;
                tmpNote.VolModifier = dstNote.VolModifier;

                player.CurrentSong  = tempSong;
                player.CurrentTempo = tempSong.Tempo;
                player.Play();

                _lastNote = dstNote;
            }
        }
Example #2
0
        private ChannelNote GetNoteFromKey(Keys key)
        {
            ChannelNote dstNote = null;

            if (virtPianoNotes.ContainsKey(key))
            {
                ChannelNote pressedNote = virtPianoNotes[key];
                dstNote = new ChannelNote();

                if (pressedNote.HasOctave)
                {
                    dstNote.Octave = pressedNote.Octave + ApplicationState.Instance.BaseOctave;
                }
                else
                {
                    dstNote.Octave = pressedNote.Octave;
                }

                dstNote.Note     = pressedNote.Note;
                dstNote.Seminote = pressedNote.Seminote;

                dstNote.EnvData.ActiveFrequencies = ApplicationState.Instance.CurrentEnvData.ActiveFrequencies;
                dstNote.EnvData.FrequencyRatio    = ApplicationState.Instance.CurrentEnvData.FrequencyRatio;
                dstNote.EnvData.Style             = ApplicationState.Instance.CurrentEnvData.Style;
            }
            return(dstNote);
        }
Example #3
0
 public void CopyFrom(ChannelNote newValues)
 {
     this.octave      = newValues.octave;
     this.note        = newValues.note;
     this.seminote    = newValues.seminote;
     this.instrument  = newValues.instrument;
     this.envData     = newValues.EnvData.Clone();
     this.volModifier = newValues.volModifier;
 }
Example #4
0
        protected virtual void OnNoteOrFxPressed(ChannelNote note, int fx)
        {
            EventHandler <NoteFXEventArgs> tmp = this.NoteFxPressed;

            if (tmp != null)
            {
                NoteFXEventArgs e = new NoteFXEventArgs(note, fx);
                tmp(this, e);
            }
        }
Example #5
0
 private void StopNote(ChannelNote note)
 {
     if (note != null && _lastNote != null &&
         _lastNote.Octave == note.Octave && _lastNote.Note == note.Note &&
         _lastNote.Seminote == note.Seminote && _lastNote.Instrument == note.Instrument)
     {
         this.player.Stop();
         this._lastNote = null;
     }
 }
Example #6
0
        private static void addNoteToDictionary(int octave, char note, char semiNote, Keys key)
        {
            ChannelNote tmp;

            tmp          = new ChannelNote();
            tmp.Octave   = octave;
            tmp.Note     = note;
            tmp.Seminote = semiNote;
            virtPianoNotes.Add(key, tmp);
        }
Example #7
0
        private ChannelNote GetNoteFromPiano(int note)
        {
            ChannelNote pressedNote = virtTemplateNotes[note % virtTemplateNotes.Count];
            ChannelNote dstNote     = new ChannelNote();

            dstNote.Octave   = note / virtTemplateNotes.Count;
            dstNote.Note     = pressedNote.Note;
            dstNote.Seminote = pressedNote.Seminote;

            dstNote.EnvData.ActiveFrequencies = ApplicationState.Instance.CurrentEnvData.ActiveFrequencies;
            dstNote.EnvData.FrequencyRatio    = ApplicationState.Instance.CurrentEnvData.FrequencyRatio;
            dstNote.EnvData.Style             = ApplicationState.Instance.CurrentEnvData.Style;
            return(dstNote);
        }
Example #8
0
 public ArpeggioDefinition()
 {
     baseNote = new ChannelNote()
     {
         Note   = 'C',
         Octave = 3
     };
     targetPatternIdx       = -1;
     highlightByScale       = -1;
     targetChannelIdx       = 0;
     this.Length            = 16;
     this.NewPatternLength  = 32;
     this.OctavesInArpeggio = 2;
 }
 public ArpeggioDefinition()
 {
     baseNote = new ChannelNote()
     {
         Note = 'C',
         Octave = 3
     };
     targetPatternIdx = -1;
     highlightByScale = -1;
     targetChannelIdx = 0;
     this.Length = 16;
     this.NewPatternLength = 32;
     this.OctavesInArpeggio = 2;
 }
        private void buildTestPattern()
        {
            if (testSong != null && currentArpeggioDefinition != null && !loadingControls)
            {
                initializeTestPattern();
                int     patternIdx    = 0;
                Pattern current       = testSong.Patterns[0];
                int     targetChannel = currentArpeggioDefinition.TargetChannelIdx;

                if (currentArpeggioDefinition.Length > 0)
                {
                    bool noteActive = false;

                    current.PopulateInstruments(targetChannel);

                    int i = 0;
                    while (patternIdx < current.Length)
                    {
                        ChannelNote oldNote = current.Lines[patternIdx].Notes[targetChannel];

                        if (currentArpeggioDefinition.ActiveNotes[i])
                        {
                            ChannelNote note = SerializationUtils.Clone(currentArpeggioDefinition.BaseNote);
                            note.Transpose(currentArpeggioDefinition.Intervals[i], currentArpeggioDefinition.BaseNote.Octave);
                            current.Lines[patternIdx].Notes[targetChannel] = note;
                            noteActive = true;
                        }
                        else if (currentArpeggioDefinition.SilencedNotes[i])
                        {
                            noteActive = false;
                            if (!oldNote.HasValue)
                            {
                                current.Lines[patternIdx].Notes[targetChannel] = ChannelNote.SilenceNote;
                            }
                        }
                        else if (noteActive)
                        {
                            current.Lines[patternIdx].Notes[targetChannel] = ChannelNote.EmptyNote;
                        }

                        patternIdx++;
                        i = (i + 1) % currentArpeggioDefinition.Length;
                    }

                    current.OptimizeInstrumentUsage(targetChannel);
                }
            }
        }
        private static byte getSawtoothParamsByte(ChannelNote note)
        {
            byte result = 0x0;

            result |= (note.EnvData.ActiveFrequencies) ? (byte)0x1 : (byte)0x0;

            switch (note.EnvData.FrequencyRatio)
            {
            case 2:
                break;

            case 4:
                result |= (byte)(0x1) << 1;
                break;

            case 8:
                result |= (byte)(0x2) << 1;
                break;

            case 16:
                result |= (byte)(0x3) << 1;
                break;
            }

            switch (note.EnvData.Style)
            {
            case 8:
                break;

            case 10:
                result |= (byte)(0x1) << 3;
                break;

            case 12:
                result |= (byte)(0x2) << 3;
                break;

            case 14:
                result |= (byte)(0x3) << 3;
                break;
            }


            return(result);
        }
Example #12
0
        private bool updateEnvelopeForChannel(int channel, int noise, bool[] noteChanged, ref int vol, ref int envStyle, ref int envFreq, ref bool activeFreqs)
        {
            bool useEnv = false;

            if (this.currentSong.FxChannel == channel && this.areEffectsActive())
            {
                if ((noise & 0x80) == 0x80)
                {
                    envStyle = this.currentEffect.EnvTypes[this.effectPosition];
                    if (envStyle == 0x01)
                    {
                        envStyle = 0xFF;
                    }
                    envFreq        = this.currentEffect.EnvFreqs[this.effectPosition];
                    vol           |= 0x10;
                    useEnv         = true;
                    lastCycleHadFx = true;
                    activeFreqs    = false;
                }
            }
            else
            {
                int         tone        = getFrequencyForChannel(channel);
                ChannelNote currentNote = this.CurrentLine.Notes[channel];
                useEnv = (this.currentInstruments[channel] != null && this.currentInstruments[channel].ID == "R");
                if (useEnv)
                {
                    envFreq     = tone / lastEnvData[channel].FrequencyRatio;
                    activeFreqs = lastEnvData[channel].ActiveFrequencies;
                    if (noteChanged[channel] || lastCycleHadFx)
                    {
                        lastCycleHadFx = false;
                        envStyle       = lastEnvData[channel].Style;
                    }
                    else
                    {
                        envStyle = 0xFF;
                    }
                }
            }
            return(useEnv);
        }
Example #13
0
        public void OptimizeInstrumentUsage(int channel)
        {
            string runningInstrumentId = string.Empty;
            int    patternIdx          = 0;

            while (patternIdx < this.Length)
            {
                ChannelNote currentNote = this.Lines[patternIdx].Notes[channel];
                if (currentNote.HasInstrument)
                {
                    if (runningInstrumentId == currentNote.Instrument)
                    {
                        currentNote.Instrument = string.Empty;
                    }
                    else
                    {
                        runningInstrumentId = currentNote.Instrument;
                    }
                }
                patternIdx++;
            }
        }
Example #14
0
        public void PopulateInstruments(int channel)
        {
            string runningInstrumentId = string.Empty;
            int    patternIdx          = 0;

            while (patternIdx < this.Length)
            {
                ChannelNote currentNote = this.Lines[patternIdx].Notes[channel];
                if (currentNote.HasValue)
                {
                    if (currentNote.HasInstrument)
                    {
                        runningInstrumentId = currentNote.Instrument;
                    }
                    else
                    {
                        currentNote.Instrument = runningInstrumentId;
                    }
                }
                patternIdx++;
            }
        }
Example #15
0
        void handleKeyDown(object sender, KeyEventArgs e)
        {
            ChannelNote note = GetNoteFromKey(e.KeyCode);
            int         fx   = IsFx(e.KeyCode) ? virtPianoFx[e.KeyCode] : int.MinValue;

            if (this.Enabled)
            {
                switch (this.Mode)
                {
                case PianoMode.Fx:
                    this.PlayEffect(fx);
                    break;

                case PianoMode.Instrument:
                    this.PlayNote(note);
                    break;
                }
            }
            if (note != null || fx != int.MinValue)
            {
                this.OnNoteOrFxPressed(note, fx);
            }
        }
Example #16
0
        private int getVolFromNote(ChannelNote note, ref Instrument currentInstrument, ref long instrPos)
        {
            int vol;

            if ((note.HasInstrument) && (periodCount == 0))
            {
                currentInstrument = this.currentSong.GetInstrument(note.Instrument);
            }
            if (currentInstrument != null && currentInstrument.ID != "R")
            {
                if (instrPos >= currentInstrument.Volumes.Length)
                {
                    vol = 0;
                }
                else
                {
                    vol = currentInstrument.Volumes[instrPos];
                    instrPos++;
                    if (instrPos >= currentInstrument.Volumes.Length)
                    {
                        if (currentInstrument.Looped)
                        {
                            instrPos = currentInstrument.LoopStart;
                        }
                    }
                }
            }
            else if (currentInstrument == null)
            {
                vol = 0;
            }
            else
            {
                vol = 0x10;
            }
            return(vol);
        }
Example #17
0
 private ChannelNote cloneNote(ChannelNote note)
 {
     ChannelNote newNote = new ChannelNote();
     newNote.Instrument = note.Instrument;
     newNote.Note = note.Note;
     newNote.Octave = note.Octave;
     newNote.Seminote = note.Seminote;
     newNote.EnvData = new EnvelopeData()
     {
         ActiveFrequencies = note.EnvData.ActiveFrequencies,
         FrequencyRatio = note.EnvData.FrequencyRatio,
         Style = note.EnvData.Style
     };
     newNote.VolModifier = note.VolModifier;
     return newNote;
 }
        private void pbWave_Paint(object sender, PaintEventArgs e)
        {
            float steps = ((2.0f * MaxArpeggioInterval) + 1);

            RectangleF rectInterval =
                new RectangleF(0, 0, STEP_WIDTH, STEP_HEIGHT);

            Brush currentBrush;
            Point brushPt1 = Point.Empty, brushPt2 = Point.Empty;

            List <int> intervals = getIntervalsForScale();

            float y = 0;

            ChannelNote noteToPaint = SerializationUtils.Clone(this.currentArpeggioDefinition.BaseNote);

            noteToPaint.Transpose(MaxArpeggioInterval, noteToPaint.Octave);

            for (int i = 0; i < steps; i++)
            {
                int remainder = (int)(MaxArpeggioInterval - i) % 12;
                if (remainder < 0)
                {
                    remainder += 12;
                }

                if (intervals.Contains(remainder))
                {
                    e.Graphics.FillRectangle(Brushes.DarkGreen, 0, y, pbWave.ClientRectangle.Width, STEP_HEIGHT);
                }

                e.Graphics.DrawLine(Pens.LimeGreen, 0, y, pbWave.ClientRectangle.Width, y);

                string noteText = string.Format("{0}{1}{2}", noteToPaint.Octave, noteToPaint.Note, noteToPaint.HasSeminote ? "#" : "");
                e.Graphics.DrawString(noteText, this.Font, Brushes.LimeGreen, 0, y);

                y += STEP_HEIGHT;
                noteToPaint.Transpose(-1, noteToPaint.Octave);
            }
            e.Graphics.DrawLine(Pens.LimeGreen, 0, y, pbWave.ClientRectangle.Width, y);

            e.Graphics.DrawLine(Pens.LimeGreen, 0, 0, 0, pbWave.ClientRectangle.Height);

            rectInterval.X = rectInterval.Width;
            for (int i = 0; i < this.currentArpeggioDefinition.Length; i++)
            {
                e.Graphics.DrawLine(Pens.LimeGreen, rectInterval.X, 0, rectInterval.X, pbWave.ClientRectangle.Height);

                if (this.currentArpeggioDefinition.ActiveNotes[i] || this.currentArpeggioDefinition.SilencedNotes[i])
                {
                    int interval = this.currentArpeggioDefinition.Intervals[i];
                    rectInterval.Y = (MaxArpeggioInterval - interval) * STEP_HEIGHT;

                    brushPt1.X = (int)Math.Round(rectInterval.Left + 1);
                    brushPt2.X = (int)Math.Round(rectInterval.Right - 1);

                    if (this.currentArpeggioDefinition.ActiveNotes[i])
                    {
                        currentBrush = new LinearGradientBrush(brushPt1, brushPt2,
                                                               Color.DarkRed, Color.Red);// Brushes.Aqua;

                        e.Graphics.FillRectangle(currentBrush,
                                                 rectInterval.X + 1, rectInterval.Y + 1,
                                                 rectInterval.Width - 2, rectInterval.Height - 2);

                        currentBrush.Dispose();
                    }
                    else
                    {
                        currentBrush = new LinearGradientBrush(brushPt1, brushPt2,
                                                               Color.FromArgb(192, 64, 0), Color.Orange);// Brushes.Aqua;

                        e.Graphics.FillRectangle(currentBrush,
                                                 rectInterval.X + 1, rectInterval.Y + 1,
                                                 rectInterval.Width - 2, rectInterval.Height - 2);

                        currentBrush.Dispose();
                    }
                }
                rectInterval.X += rectInterval.Width;
            }
            e.Graphics.DrawLine(Pens.LimeGreen, rectInterval.X, 0, rectInterval.X, pbWave.ClientRectangle.Height);
        }
Example #19
0
 public NoteFXEventArgs(ChannelNote note, int fx)
     : base()
 {
     this.Note = note;
     this.Fx   = fx;
 }
Example #20
0
        private static byte getSawtoothParamsByte(ChannelNote note)
        {
            byte result = 0x0;

            result |= (note.EnvData.ActiveFrequencies) ? (byte)0x1 : (byte)0x0;

            switch (note.EnvData.FrequencyRatio)
            {
                case 2:
                    break;
                case 4:
                    result |= (byte)(0x1) << 1;
                    break;
                case 8:
                    result |= (byte)(0x2) << 1;
                    break;
                case 16:
                    result |= (byte)(0x3) << 1;
                    break;
            }

            switch (note.EnvData.Style)
            {
                case 8:
                    break;
                case 10:
                    result |= (byte)(0x1) << 3;
                    break;
                case 12:
                    result |= (byte)(0x2) << 3;
                    break;
                case 14:
                    result |= (byte)(0x3) << 3;
                    break;
            }

            return result;
        }
Example #21
0
 public NoteFXEventArgs(ChannelNote note, int fx)
     : base()
 {
     this.Note = note;
     this.Fx = fx;
 }
Example #22
0
        private void StopNote(int pianoNote)
        {
            ChannelNote note = this.GetNoteFromPiano(pianoNote);

            this.StopNote(note);
        }
Example #23
0
        private void PlayNote(ChannelNote dstNote)
        {
            if (dstNote != null &&
                (_lastNote == null || _lastNote.Octave != dstNote.Octave || _lastNote.Note != dstNote.Note ||
                _lastNote.Seminote != dstNote.Seminote || _lastNote.Instrument != dstNote.Instrument))
            {
                player.Stop();

                Song tempSong = SerializationUtils.Clone(ApplicationState.Instance.CurrentSong);
                tempSong.PlayOrder.Clear();
                tempSong.Patterns.Clear();
                tempSong.Looped = true;
                tempSong.Patterns.Add(new Pattern() { Length = 256, Channels = tempSong.Channels });
                tempSong.PlayOrder.Add(0);
                ChannelNote tmpNote = tempSong.Patterns[0].Lines[0].Notes[0];
                tmpNote.EnvData = dstNote.EnvData;
                tmpNote.Instrument = this.CurrentInstrument.ID;
                tmpNote.Note = dstNote.Note;
                tmpNote.Octave = dstNote.Octave;
                tmpNote.Seminote = dstNote.Seminote;
                tmpNote.VolModifier = dstNote.VolModifier;

                player.CurrentSong = tempSong;
                player.CurrentTempo = tempSong.Tempo;
                player.Play();

                _lastNote = dstNote;
            }
        }
Example #24
0
        private ChannelNote GetNoteFromPiano(int note)
        {
            ChannelNote pressedNote = virtTemplateNotes[note % virtTemplateNotes.Count];
            ChannelNote dstNote = new ChannelNote();

            dstNote.Octave = note / virtTemplateNotes.Count;
            dstNote.Note = pressedNote.Note;
            dstNote.Seminote = pressedNote.Seminote;

            dstNote.EnvData.ActiveFrequencies = ApplicationState.Instance.CurrentEnvData.ActiveFrequencies;
            dstNote.EnvData.FrequencyRatio = ApplicationState.Instance.CurrentEnvData.FrequencyRatio;
            dstNote.EnvData.Style = ApplicationState.Instance.CurrentEnvData.Style;
            return dstNote;
        }
Example #25
0
        private ChannelNote GetNoteFromKey(Keys key)
        {
            ChannelNote dstNote = null;
            if (virtPianoNotes.ContainsKey(key))
            {
                ChannelNote pressedNote = virtPianoNotes[key];
                dstNote = new ChannelNote();

                if (pressedNote.HasOctave)
                    dstNote.Octave = pressedNote.Octave + ApplicationState.Instance.BaseOctave;
                else
                    dstNote.Octave = pressedNote.Octave;

                dstNote.Note = pressedNote.Note;
                dstNote.Seminote = pressedNote.Seminote;

                dstNote.EnvData.ActiveFrequencies = ApplicationState.Instance.CurrentEnvData.ActiveFrequencies;
                dstNote.EnvData.FrequencyRatio = ApplicationState.Instance.CurrentEnvData.FrequencyRatio;
                dstNote.EnvData.Style = ApplicationState.Instance.CurrentEnvData.Style;
            }
            return dstNote;
        }
Example #26
0
        private static void addNoteToDictionary(int octave, char note, char semiNote, Keys key)
        {
            ChannelNote tmp;

            tmp = new ChannelNote();
            tmp.Octave = octave;
            tmp.Note = note;
            tmp.Seminote = semiNote;
            virtPianoNotes.Add(key, tmp);
        }
Example #27
0
 protected virtual void OnNoteOrFxPressed(ChannelNote note, int fx)
 {
     EventHandler<NoteFXEventArgs> tmp = this.NoteFxPressed;
     if (tmp != null)
     {
         NoteFXEventArgs e = new NoteFXEventArgs(note, fx);
         tmp(this, e);
     }
 }
Example #28
0
        private void StopNote(Keys keyCode)
        {
            ChannelNote note = this.GetNoteFromKey(keyCode);

            this.StopNote(note);
        }
Example #29
0
        private void setNote(ChannelNote pressedNote)
        {
            ChannelNote dstNote = this.currentPattern.Lines[this.SelectedIndex].Notes[this.currentChannel];
            ChannelNote lastNoteWithInstrument = null;

            dstNote.Octave = pressedNote.Octave;
            dstNote.Note = pressedNote.Note;
            dstNote.Seminote = pressedNote.Seminote;

            if ((pressedNote.HasNote || pressedNote.HasSeminote || pressedNote.HasOctave) && (pressedNote.Note != 'P'))
            {
                string previousInstr = string.Empty;

                lastNoteWithInstrument = this.getLastNoteWithInstrument(this.SelectedIndex, this.currentChannel);
                if (lastNoteWithInstrument != null)
                {
                    previousInstr = lastNoteWithInstrument.Instrument;
                }
                if (this.CurrentInstrument.ID.ToString() != previousInstr)
                {
                    dstNote.Instrument = this.currentInstrument.ID.ToString();
                }
                else
                {
                    dstNote.Instrument = string.Empty;
                }

                if (this.currentInstrument.ID == "R")
                {
                    if (lastNoteWithInstrument != null && lastNoteWithInstrument.Instrument == "R")
                    {
                        if (!EnvelopeData.Compare(ApplicationState.Instance.CurrentEnvData, lastNoteWithInstrument.EnvData))
                        {
                            dstNote.Instrument = "R";
                        }
                    }

                    dstNote.EnvData.ActiveFrequencies = ApplicationState.Instance.CurrentEnvData.ActiveFrequencies;
                    dstNote.EnvData.FrequencyRatio = ApplicationState.Instance.CurrentEnvData.FrequencyRatio;
                    dstNote.EnvData.Style = ApplicationState.Instance.CurrentEnvData.Style;
                }
            }
            else
            {
                dstNote.Instrument = string.Empty;
            }
            increasePosition();
            this.Invalidate();
        }
Example #30
0
 private void StopNote(ChannelNote note)
 {
     if (note != null && _lastNote != null &&
         _lastNote.Octave == note.Octave && _lastNote.Note == note.Note &&
         _lastNote.Seminote == note.Seminote && _lastNote.Instrument == note.Instrument)
     {
         this.player.Stop();
         this._lastNote = null;
     }
 }
Example #31
0
        private void PlayNote(int note)
        {
            ChannelNote dstNote = GetNoteFromPiano(note);

            this.PlayNote(dstNote);
        }