[ create a new paste ] login | about

Link: http://codepad.org/HGuVeUjJ    [ raw code | fork ]

b2ox - C, pasted on Sep 27:
// TransposeEx.cs for Cadencii
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using Boare.Lib.Vsq;
using Boare.Cadencii;
using Boare.Lib.Media;
using bocoree;

public class TransposeEx : Form {
  private Button btnExec;
  private NumericUpDown numUpDown;

  public TransposeEx() {
    InitializeComponent();
  }

  private System.ComponentModel.IContainer components = null;
  protected override void Dispose( bool disposing ) {
    if ( disposing && (components != null) ) {
      components.Dispose();
    }
    base.Dispose( disposing );
  }

  private void InitializeComponent() {
    this.btnExec = new Button();
    this.numUpDown = new NumericUpDown();
    ((System.ComponentModel.ISupportInitialize)(this.numUpDown)).BeginInit();
    this.SuspendLayout();
    //
    // btnExec
    //
    this.btnExec.Location = new System.Drawing.Point(142, 6);
    this.btnExec.Name = "btnExec";
    this.btnExec.Size = new System.Drawing.Size(66, 20);
    this.btnExec.TabIndex = 1;
    this.btnExec.Text = "Execute";
    this.btnExec.UseVisualStyleBackColor = true;
    this.btnExec.Click += new System.EventHandler(this.btnExec_Click);
    //
    // numUpDown
    //
    this.numUpDown.Location = new System.Drawing.Point(12, 6);
    this.numUpDown.Maximum = 2;
    this.numUpDown.Minimum = -2;
    this.numUpDown.Name = "numUpDown";
    this.numUpDown.Size = new System.Drawing.Size(77, 19);
    this.numUpDown.TabIndex = 2;
    this.numUpDown.Value = 1;
    //
    // mainForm
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    this.AutoScaleMode = AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(220, 31);
    this.Controls.Add(this.numUpDown);
    this.Controls.Add(this.btnExec);
    this.Name = "mainForm";
    this.Text = "Transpose";
    ((System.ComponentModel.ISupportInitialize)(this.numUpDown)).EndInit();
    this.ResumeLayout(false);
  }

  private void btnExec_Click(object sender, EventArgs e) {
    this.DialogResult = DialogResult.OK;
    this.Close();
  }

  //---------------------------------------------
  public static bool Edit( VsqFile vsq ) {
    using ( TransposeEx d = new TransposeEx() ) {
      if ( d.ShowDialog() != DialogResult.OK ) {
        return false;
      } else {
        int step = (int)d.numUpDown.Value;
        if (step != 0) transpose( vsq, step );
        return true;
      }
    }
  }

  private static void transpose( VsqFile vsq, int step ) {
    int note;
    Dictionary<int, int> target_ids = new Dictionary<int, int>();
    foreach( SelectedEventEntry see in AppManager.SelectedEvent.GetEnumerator()) {
        target_ids.Add( see.Original.InternalID, 0 );
    }
    int track = AppManager.Selected;
    for ( int j = 0; j < vsq.Track[track].getEventCount(); j++ ) {
      VsqEvent item = vsq.Track[track].getEvent(j);
      if ( item.ID.type == VsqIDType.Anote && target_ids.ContainsKey( item.InternalID ) ) {
        note = item.ID.Note + step;
        if ( note < 0 ) note = 0;
        if ( 127 < note ) note = 127;
        item.ID.Note = note;
      }
    }
  }
}


Create a new paste based on this one


Comments: