SHARE
TWEET

Mtrk to Microbrute .mbseq

stumm Dec 12th, 2014 234 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7.  
  8. namespace Mtrk2Mbseq
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.  
  20.             //only reads first track
  21.             string inputFile = @"c:\temp\mtrkbassline.csv";
  22.             int lineCount = File.ReadLines(inputFile).Count();
  23.             string notesAgain = string.Empty;
  24.             List<string> noteCollection = new List<string>();
  25.  
  26.             foreach (string line in File.ReadLines(inputFile))
  27.             {
  28.                if (line.Substring(0,1) == ";"){
  29.                    string[] rowData = line.Split(';');
  30.                    string note = rowData[5].Trim();
  31.  
  32.                    if ((note.Length > 0) && (note != "off"))
  33.                    {
  34.                        string octave = note.Substring(2, 1);
  35.                        note = note.Substring(0, 2).Replace("-", string.Empty);
  36.                        string midiNote = getNoteValue(note, octave);
  37.                        noteCollection.Add(midiNote);
  38.                    }
  39.                    else
  40.                    {
  41.                        note = "x";
  42.                        noteCollection.Add(note);
  43.                    }
  44.                    notesAgain = string.Join(" ", noteCollection.ToArray());
  45.                    
  46.                }
  47.             }
  48.  
  49.             Console.WriteLine("1:" + notesAgain.ToString());
  50.         }
  51.  
  52.         private string getNoteValue(string note, string octave)
  53.         {
  54.             Dictionary<string, int> midiNoteValues = new Dictionary<string, int>()
  55.             {
  56.                     //midi note, octave 0 values
  57.                     {"C", 0},{"C#", 1},{"D", 2},{"D#", 3},{"E", 4},{"F", 5},{"F#", 6},{"G", 7},
  58.                     {"G#", 8},{"A", 9},{"A#", 10},{"B", 11},
  59.             };
  60.  
  61.             int octavevalue = Convert.ToInt32(octave) * 12 -12; //drop 1 oct after convert .. buzz is higher
  62.             string midiNote = (midiNoteValues[note] + octavevalue).ToString();
  63.             return midiNote;
  64.  
  65.         }
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top