Advertisement
stumm

Mtrk to Microbrute .mbseq

Dec 12th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement