/// <summary> /// Converts the notes of a specified staff collection into an array /// of 8 channels containing their designated command collections. /// </summary> /// <param name="staffs">The staff collection.</param> /// <param name="spc">The owning SPC of the channels.</param> /// <returns></returns> public static List <Command>[] StaffsToChannels(List <Staff> staffs, SPC spc) { var channels = new List <Command> [8]; for (int c = 0; c < 8 && c < staffs.Count; c++) { int thisOctave = -1; channels[c] = new List <Command>(); foreach (object item in staffs[c].Notes) { var note = item as Note; if (note.Octave == thisOctave + 1) { channels[c].Add(new Command(new byte[] { 0xC4 }, spc, c)); thisOctave++; } else if (note.Octave == thisOctave - 1) { channels[c].Add(new Command(new byte[] { 0xC5 }, spc, c)); thisOctave--; } else if (note.Octave != thisOctave) { channels[c].Add(new Command(new byte[] { 0xC6, (byte)note.Octave }, spc, c)); thisOctave = note.Octave; } channels[c].Add(note.Command); } } return(channels); }
// Initialization public void LoadProperties() { if (Index != 0 || Type != ElementType.SPCTrack) { SPC.CreateNotes(); } MouseDownSSC = null; ReadFromCommand(); SetHScrollBar(); }
private void duplicate_Click(object sender, EventArgs e) { if (MouseDownSSC == null) { return; } Command copiedSSC = MouseDownSSC.Copy(); List <Command> channel = SPC.Channels[MouseDownSSC.Channel]; channel.Insert(MouseDownSSC.Index + 1, copiedSSC); MouseDownSSC = copiedSSC; SPC.CreateNotes(); ReadFromCommand(); picture.Invalidate(); scoreViewerPicture.Invalidate(); }
private void moveRight_Click(object sender, EventArgs e) { if (MouseDownSSC == null) { return; } List <Command> channel = SPC.Channels[MouseDownSSC.Channel]; int index = MouseDownSSC.Index; if (index < channel.Count - 1) { channel.Reverse(index, 2); } SPC.CreateNotes(); WriteToCommand(); picture.Invalidate(); scoreViewerPicture.Invalidate(); }
private void delete_Click(object sender, EventArgs e) { if (MouseDownSSC == null) { return; } int index = MouseDownSSC.Index; SPC.Channels[MouseDownSSC.Channel].Remove(MouseDownSSC); if (index >= 0 && SPC.Channels[MouseDownSSC.Channel].Count > 0) { index = Math.Min(SPC.Channels[MouseDownSSC.Channel].Count - 1, index); MouseDownSSC = SPC.Channels[MouseDownSSC.Channel][index]; } else { MouseDownSSC = null; } SPC.CreateNotes(); ReadFromCommand(); WriteToCommand(); picture.Invalidate(); scoreViewerPicture.Invalidate(); }
// Constructor public Command(byte[] data, SPC spc, int channel) { this.spc = spc; this.Data = data; this.Channel = channel; }
private void newNote_Click(object sender, EventArgs e) { int index = -1; int channelIndex = -1; if (MouseDownSSC != null) { index = MouseDownSSC.Index; channelIndex = MouseDownSSC.Channel; } else { // look for 1st active channel and insert the command at the beginning for (int i = 0; i < SPC.ActiveChannels.Length; i++) { if (SPC.ActiveChannels[i]) { channelIndex = i; break; } } } if (channelIndex == -1) { return; } if (newCommands.SelectedIndex == -1) { return; } int opcode; if (newCommands.SelectedIndex == 0) { opcode = 0; } else if (newCommands.SelectedIndex == 1) { opcode = 0xB6; } else { opcode = newCommands.SelectedIndex + 0xC2; } int length = ScriptEnums.CommandLengths[opcode]; Command ssc; if (Type == ElementType.SPCTrack) { ssc = new Command(new byte[length], (SPCTrack)SPC, channelIndex); } else { ssc = new Command(new byte[length], (SPCSound)SPC, channelIndex); } ssc.Opcode = (byte)opcode; List <Command> channel = SPC.Channels[channelIndex]; channel.Insert(index + 1, ssc); MouseDownSSC = ssc; SPC.CreateNotes(); ReadFromCommand(); WriteToCommand(); picture.Invalidate(); scoreViewerPicture.Invalidate(); }
/// <summary> /// Writes the values in the command editing controls to the command data of MouseDownSSC. /// </summary> private void WriteToCommand() { if (MouseDownSSC == null) { return; } switch (MouseDownSSC.Opcode) { case 0xCD: case 0xCE: case 0xDE: MouseDownSSC.Opcode = (byte)opcodeByte1.Value; MouseDownSSC.Param1 = (byte)parameterName1.SelectedIndex; break; case 0xDF: MouseDownSSC.Opcode = (byte)opcodeByte1.Value; if (parameterByte1.Value < 0) { MouseDownSSC.Param1 = (byte)(0x20 + parameterByte1.Value); } else { MouseDownSSC.Param1 = (byte)parameterByte1.Value; } MouseDownSSC.Param1 |= (byte)((byte)parameterByte2.Value << 5); break; case 0xCF: case 0xE3: case 0xEC: case 0xED: case 0xF2: MouseDownSSC.Opcode = (byte)opcodeByte1.Value; MouseDownSSC.Param1 = (byte)((sbyte)parameterByte1.Value); break; case 0xE4: case 0xE5: MouseDownSSC.Opcode = (byte)opcodeByte1.Value; MouseDownSSC.Param1 = (byte)parameterByte1.Value; MouseDownSSC.Param2 = (byte)((sbyte)parameterByte2.Value); break; default: if (MouseDownSSC.Opcode < 0xC4) { if (MouseDownSSC.Opcode < 0xB6) { MouseDownSSC.Opcode = (byte)(noteLengthName.SelectedIndex * 14); } else { MouseDownSSC.Opcode = 0xB6; MouseDownSSC.Param1 = (byte)noteLengthByte.Value; } MouseDownSSC.Opcode += (byte)noteNames.SelectedIndex; } else { if (MouseDownSSC.Length > 0) { MouseDownSSC.Opcode = (byte)opcodeByte1.Value; } if (MouseDownSSC.Length > 1) { MouseDownSSC.Param1 = (byte)parameterByte1.Value; } if (MouseDownSSC.Length > 2) { MouseDownSSC.Param2 = (byte)parameterByte2.Value; } if (MouseDownSSC.Length > 3) { MouseDownSSC.Param3 = (byte)parameterByte3.Value; } } break; } if (Type == ElementType.SPCTrack) { (SPC as SPCTrack).WriteToBuffer(); } // if changed octave, recreate notes if (MouseDownSSC.Opcode == 0xC4 || MouseDownSSC.Opcode == 0xC5 || MouseDownSSC.Opcode == 0xC6) { SPC.CreateNotes(); } ownerForm.SetFreeBytesLabel(); }