Wednesday, September 21, 2011

Music 'n' Coding C#

Its a very long time but am back to share some of my learnings/things that i like with my blog~~~~~ again. This time i came up with some of the codings that i worked for my pleasure.  I have joined guitar class in my local area few weeks back and last week my master taught me thaattu varisaigal (meaning jumping notes), well its tough to practice but it is a very important basic lesson as he told.

I loved the arrangements of this notes so thought to write a code then, so here is the code.

Logic is : Print 1st character jump two chars, then print 4th and print back from it, now print the striaght ones, for example  C, D, E, F is straight and jumped one is C, F, E, D. You can find the output in the end of the code.



private static void generateJumpingNotesEasily()
{
string[] notes = new string[] { "C", "D", "E", "F", "G", "A", "B", "~C" };
//string[] notes = new string[] { "Sa", "Re", "Ga", "Ma", "Pa", "Tha", "Ne", "~Sa" };
StringBuilder jumpingResultNotes = new StringBuilder();
StringBuilder reverseJumpingResultNotes = new StringBuilder();
Console.WriteLine("Jumping Notes aka Thaattu Varisaigal");
Console.WriteLine("------------------------------------");
Console.WriteLine();

for (int j = 0; j <= notes.Length - 1; j++)
{
Console.Write(notes[j]);
Console.Write(" ");
}
Console.WriteLine();
Console.WriteLine("-----------------------------------");
for (int i = 0; i <= 4; i++)
{
jumpingResultNotes.Append(notes[i]);
jumpingResultNotes.Append(notes[i + 3]);
jumpingResultNotes.Append(notes[i + 2]);
jumpingResultNotes.Append(notes[i + 1]);
jumpingResultNotes.Append(" | ");
jumpingResultNotes.Append(notes[i]);
jumpingResultNotes.Append(notes[i + 1]);
jumpingResultNotes.Append(notes[i + 2]);
jumpingResultNotes.Append(notes[i + 3]);
jumpingResultNotes.Append(" | ");
}

Console.WriteLine(jumpingResultNotes);
Console.WriteLine();

//this is from the end of the string array (reverse )
for (int k = notes.Length - 1; k >= 3; k--)
{
reverseJumpingResultNotes.Append(notes[k]);
reverseJumpingResultNotes.Append(notes[k - 3]);
reverseJumpingResultNotes.Append(notes[k - 2]);
reverseJumpingResultNotes.Append(notes[k - 1]);
reverseJumpingResultNotes.Append(" | ");
reverseJumpingResultNotes.Append(notes[k]);
reverseJumpingResultNotes.Append(notes[k - 1]);
reverseJumpingResultNotes.Append(notes[k - 2]);
reverseJumpingResultNotes.Append(notes[k - 3]);
reverseJumpingResultNotes.Append(" | ");
}
Console.WriteLine(reverseJumpingResultNotes);
Console.WriteLine();
}
}
}
Output
Jumping Notes aka Thaattu Varisaigal
------------------------------------

Sa Re Ga Ma Pa Tha Ne ~Sa
-----------------------------------
SaMaGaRe | SaReGaMa | RePaMaGa | ReGaMaPa | GaThaPaMa | GaMaPaTha | MaNeThaPa |
MaPaThaNe | Pa~SaNeTha | PaThaNe~Sa |

~SaPaThaNe | ~SaNeThaPa | NeMaPaTha | NeThaPaMa | ThaGaMaPa | ThaPaMaGa | PaReGa
Ma | PaMaGaRe | MaSaReGa | MaGaReSa |



If input is C D E F G A B ~C
-----------------------------------
CFED | CDEF | DGFE | DEFG | EAGF | EFGA | FBAG | FGAB | G~CBA | GAB~C |

~CGAB | ~CBAG | BFGA | BAGF | AEFG | AGFE | GDEF | GFED | FCDE | FEDC |

I think this can be used in some encryption algorithms with some more tweaks.

Next time i will share something more interesting which is also generous. Happy MusiCoding

No comments: