Attending Tech ED Berlin 2009

TechED

“All my bags are packed, I’m ready to go……”

I’m am very exited to get to Tech ED Berlin 2009 (which is now sold out!). I’ve been trying to wrap my head around what track and sessions I should attend, because there are MANY! to chose from. As a person I believe it’s importent to focus on the fact that this is a unique opportunity to evolve your knowledge. Therefore I have chosen to expand my choice of sessions to not just include areas of immediate focus, but to also include areas of common interest.

I spend a few hours on the track & sessions page, figuring out pros and cons on sessions that unfortunately collided on day and hours. But I think I hit an amazing agenda for the entire week:

TechEd Europe Keynote - Welcome to the New Efficiency
Enabling Rich Business Clients with Windows Presentation Foundation
Top 10 Design Mistakes Made By Web Developers and How to Avoid Them
Windows 7 Demo Mania
Embedding Windows 7 into Devices
Tips and Tricks for Building High Performance Web Applications and Sites
Pumping Iron: Dynamic Languages on the Microsoft .NET Framework
F# for Parallel and Asynchronous Programming
Microsoft Visual Studio Team System 2010 Team Foundation Server: Become Productive in 30 Minutes
Unit Testing Best Practices
The Windows API Code Pack: How Managed Code Developers Can Easily Access Exciting New Windows Vista and Windows 7 Features
Windows 7 and Windows Server 2008 R2 Kernel Changes (*PDC at TechEd)
Windows 7: The Power Management Workout!
Building High Performance Parallel Software
Windows Embedded: "Demos Only"
Parallel Computing for Managed Developers
Achieve new levels of desktop optimization with Intel Core™ 2 processors with vPro™ technology and Windows* 7
Case of the Unexplained... Windows Troubleshooting with Mark Russinovich

The one session that I look really forward to is Windows 7 and Windows Server 2008 R2 Kernel Changes!! I’ve been following the discussion on the internet, and following the videos from Channel 9 on Windows 7.

The official note on the session leaves me with the impression that this is going to be really good:

“This session goes beneath the hood of Windows 7 and Windows Server 2008 R2 to describe and demonstrate the key changes in the kernel. Topics include: scalability improvements such as removal of the global scheduler lock, support for more than 64 logical processors, and user mode scheduling, virtual service accounts, core parking and timer coalescing for power efficiency, trigger-started services, core architecture changes to modularize Windows ("Minwin") and more.”

And the embedded part with demo’s are also something to be looking forward to:

“This demo-packed session presents all sorts of devices, tools, and technologies used in today's and tomorrow's embedded projects. If you want to learn how Windows Embedded can be used to build stunning devices or if you are just a geek, you can't miss this session.”

And yes, I’m a geek!

I’m really looking forward to this mix of Desktop, embedded, web technology and architechture sessions. And not forgetting all the demo presentations that makes this Tech ED a must-see event.

Appart from all of these sessions, I will be on the lookout for the expo areas, where I will get a chance to have a look at what all other developers are doing right now.

I’m also loking forward to meeting all the other Microsoft Student Partners from all over the world. And this will ofcourse introduce them to my network, and me to theirs.

If you find the subjects listet above interesting, then I will attempt to blog on every single one of them, and hopefully provide you with awesome pictures from the whole event. If you find subjects of interests missing in my list, I will suggest that you have a look at some of the other Microsoft Student Partner blogs. We are well represented at the Tech ED event, and maybe they will attend more convenient subjects. You can find links to there blogs on the left column.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 10/31/2009 at 5:14 PM
Tags:
Categories: C# | Embedded | F# | FMOD | IronPython | OS | Programming | Tech ED | Velkommen | Windows 7
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Win a book on IronPython or F#

Here is a little contest that will run for 14 days (until the 29-09-2009), where every developer should have a chance of winning!

The Contest has ended, and the winner was Yoni Holman! Congratulations!

I?ve created 7 questions, in different programming languages such as C#, F#, Ironpython, C++, Java and off course the well known and liked true or false. The questions are designed to give a number of points, where the maximum number of points given can be read in the text of the assignment. The rules are simple, the one with the highest score on points, will win. Points will be given for correctness and effort. An assignment might give 6 point, but if not entirely correct, it will be given some points for effort.

What can you win?

The winner gets Office 2007 Student version, and gets to choose one of two books ? Foundation of F# or IronPython in Action - and the runner-up gets the book that the winner did not choose.

FSharp ironpythoninaction OFF2007STUKEY

What to do now?

If you want to try out for the books, all you have to do is:

  • Leave a comment on this blog-post (in case that when you submit, and your assignment gets in my spam-mail-box, I?ll know to look for it here if its not in my usual mailbox.
  • Submit your answers (as a txt file) to my mail address (ajp at clug.dk)
  • Everyone is allowed to solve all the questions (if you can), or just some of them.
  • When mailing me, please leave ? if you have ? your Twitter name, and I will also post the winner and runner-up on twitter (if the winner and runner-up has a Twitter name).

Here are the questions

Question number 1.

6 point

The following code compiles and runs without problems, but everything is not as it should be. When a user enters the input as shown below, what is the output? And more important, why is the output as it is?

#include <iostream>

using namespace std;

char string1[2]; char string2[2]; char string3[7]; char string4[7];  char string5[8];

int main (){
    cout<< "\n Read 1. text (length 2)";
    cin>> string1;
    cout<< "\n Read 2. text (length 2)";
    cin>> string2;
    cout<< "\n Read 3. text (length 7)";
    cin>> string3;
    cout<< "\n Read 4. text (length 7)";
    cin>> string4;
    cout<< "\n Read 5. text (length 8)";
    cin>> string5;
    cout << "\n 1.: "<< string1;
    cout << "\n 2.: "<< string2;
    cout << "\n 3.: "<< string3;
    cout << "\n 4.: "<< string4;
    cout << "\n 5.: "<< string5;
    return 0;
}

Read 1. text (length 2) - F#
Read 2. text (length 2) - C#
Read 3. text (length 7) - ASP.NET
Read 4. text (length 7) - IronRuby
Read 5. text (length 8) ? IronPython

Answer:

1. F#C#ASP.NETIronRubIronPython
2. C#ASP.NETIronRubIronPython
3. ASP.NETIronRubIronPython
4. IronRubIronPython
5. IronPython

In C++ the strings are null terminated. This means that space must be preserved for null termination character. In the assignment above, the null character is overwritten, and therefor the output is as shown.

This example does have some issues regarding compiler dependencies, and yes this was also part of the assignment ;-)

Question number 2.

9 point.

The following is an application made with the .NET Micro Framework, but the code is missing two lines! The missing parts are an Output port, and an Input port. Implement these two line to complete the code.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace MicroFramework
{
   public class Light
   {
     public static void Main()
     {
       Cpu.Pin pin = Cpu.Pin.GPIO_Pin1;
       Cpu.Pin switch = Cpu.Pin.GPIO_Pin2;
       //missing line
       //missing line

       while (true)
       {
         YourOutputPort.Write(YourInputPort.Read());
       }
      }
     }
}

Answer:

OutputPort YourOutputPort = new OutputPort(pin, false);
InputPort YourInputPort = new InputPort(switch, false);

Question number 3.

3 point.

The following code is F#, and it represents an array. Finish the code, so that every item in the array is printed out to the screen.

#light
let colors = [| "Blue"; "Green"; "Yellow"; "Black"; "White"; "Red"; |]

//iterate over the array, and print out the items within the array.

Answer (There are multiple ways of doing this) :

for color in colors do
    print_endline color

Question number 4.

4 point.

The following code is an array written in C#. create a LINQ query that selects the items that are less than 15 and do this:

  1. Using standard LINQ query
  2. Without the use of keyword "var" (without implicit typing).

int[] numbers = {5, 2, 10, 12, 16, 35, 20, 100};

//Create query

//iterate and print out items

Answer:

1.
var query = from i in numbers where i < 15 select i;

foreach(var i in query)
  Console.WriteLine("Number: {0}", i);

2.  
IEnumerable<int> query = from i in numbers where i < 15 select i;
foreach(int i in query)
  Console.WriteLine("Number: {0}", i);

Question number 5.

6 point.

Implement a function in IronPython that takes one parameter, and calculates and returns the Fibonacci series. Then call your function with the number 200.
shown here in pseudocode:

FibonacciFunction(aNumber)

calculate fibonacci

return number

call function
print output

Answer:

def fibonacci(number):
        result = []
        a, b = 0, 1
        while b < number:
             result.append(b)
             a, b = b, a+b
        return result

fib = fibonacci(200)   
fib

Question number 6.

8 point.

The following code is in Java, and it is a sorting algorithm. Two lines are missing, and you are to implement the missing lines.

public class HeapSort
{

    public void heapSort (int [] A)
    {
        printArray(A);
        makeHeap(A);
        printArray(A);
        for (int i = A.length-1;i >0 ;i--)
        {           
            int temp =0;
            temp = A[i];
            //Line missing
            A[0] = temp;
            reheap(A,0, i-1);
            printArray(A);
        }
    }
    public void makeHeap(int [] A)
    {
        for (int j = ((A.length / 2)-1);j>=0;j--)
        {
            reheap(A, j, A.length-1);
        }
    }
    public void reheap(int [] A, int current, int last)
    {
        int leftChild = 2* current +1;
        int rightChild = 2* current +2;
        int largest;
        int tempA=0;
        if (leftChild <= last && A[leftChild] > A[current])
        {
            largest = leftChild;
        }
        else
        {
            //Line missing
        }
        if (rightChild <= last && A[rightChild] > A[largest])
        {
            largest = rightChild;
        }
        if (largest != current)
        {
            tempA = A[current];
            A[current] = A[largest];
            A[largest] = tempA;
            reheap (A , largest, last);
        }
    }
    public void printArray(int [] A)
    {
        System.out.print("Array: ");
        for (int i = 0; i < A.length ; i++)
        {
            System.out.print( A[i] + ", ");
        }
        System.out.println("\n");
    }
    public static void main(String[] args)
    {
        int A [] = {10,23,75,24,98,87,27,11,34,28,17,13,31,37};
        HeapSort heap = new HeapSort();
        heap.heapSort(A);

    }

}

Answer:

A[i] = A[0];
largest = current;

Question 7.

Each correct answer will give 1 point each. (max point is 21).

In this assignment you should answer "true" or "false" to the following questions:

  1. IronPython is the .NET version of Python.
  2. IronPython is a functional programming language.
  3. There is nothing called IronRuby from Microsoft.
  4. IronPython does not work in a web browser.
  5. IronPython is a dynamic programming language.
  6. IronPython can interact with the C# programming language.
  7. IronPython is an OpenSource language.
  8. F# is a dynamic programming language.
  9. F# does not work with WPF (Windows Presentation Foundation).
  10. F# only works with math and formulas.
  11. F# works with Windows Forms.
  12. F# only runs on Windows Computers.
  13. F# is an OpenSource language.
  14. C# is the only programming language in .NET family.
  15. C# can only be used on Windows computers.
  16. The .NET MicroFramework is used for embedded systems.
  17. ASP.NET is a Java version of PHP.
  18. ASP.NET can only be used on Windows computers.
  19. ASP.NET, C#, F# and Silverlight all run on Linux.
  20. Moonlight on Linux is the same as C# on Windows.
  21. Mono is the same as F# on Windows.
Answer:

1. true
2. false
3. false
4. false
5. true
6. true
7. true
8. true
9. false
10. false
11. true
12. false
13. true
14. false
15. false
16. true
17. false
18. false
19. true
20. false
21. false

The text in small print

Everyone from every country is allowed to participate in this contest. The winner and runner-up will be notified by me personally, and I will personally send the books to their home address. If the winner and runner-up will allow it, their names will be posted on this website after I have talked to them.

All I can say now is good luck, and I hope you find this fun :-)

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 9/15/2009 at 6:48 AM
Categories: C# | IronPython | Programming | F# | Contest
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (8) | Post RSSRSS comment feed

P/Invoke, InteropServices, C# and FMOD

Making music with C#, P/Invoke, InteropServices and FMOD

I've been trying to give a glimse of how one could make a media player, but I'm not the kind of person who gives the whole answer until the absolute end. This post will be no different from the others. I'm going to present an outline as to making a media player using the FMOD library. The beaty of this library is that you can use it cross-platform so this code will also work for Linux in Mono (Linux version of C#)

Download the FMOD Library for Win32, for Windows CE, Windows CE small, Linux or MacOS

And inside you will find the reference manual, which is the place to start to get familiar with the functionallity of the library. In this little post I will focus on using C#, but as you might have guessed one can utilize every known language to programme against the FMOD library. On a quick notice; the FMOD library is primarily used in game development, but works just fine as a mediaplayer library. It is legal to use the FMOD library, without paying anything, just as long as you don't start selling your code as a product.

Now, the FMOD library is written in C++, and this means that it is written in unmanaged code contra the C# language which is a mannaged language. Therefore we need to have a look at the C# - System.Runtime.InteropServices; where we will find the DllImport attribute, which will call the unmanaged code from the C++ FMOD library (There is very much more going on in the CLI to call unmanaged code, but I will leave this for later post). As far as managed code is concerned, unmanaged code is invoked merely by invoking a method with an associated DllImport attribute.

[DllImport("My_CPP_Library.dll", EntryPoint="Function_in_CPP_Library", CallingConvention=CallingConvention.Winapi)]
public static extern Boolean Self_chosen_function_name(The parameters from the Function_in_CPP_Library);

Here's what I did to get the functionallity up and running:

[DllImport("fmod.dll", EntryPoint="FSOUND_Init",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_Init(int mixRate, int maxSoftwareChannel, int flags);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Open",
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr fmod_Open(string data, int mode, int offset, int lenght);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Play",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_Play(int channel, IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_SetVolume",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_Setvolume(IntPtr fstream, int volume);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_GetLength",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_getLenght(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_GetPosition",
CallingConvention=CallingConvention.Winapi)]
public static extern UInt32 fmod_getPos(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_SetPosition",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_setPos(IntPtr fstream, UInt32 pos);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Stop",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_stop(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Close",
CallingConvention=CallingConvention.Winapi)]
public static extern void fmod_close();


Function (and therefore names) defined in the FMOD library.

The function names that I define, and the names that I will use in my C# code.

And now off to test if it works!

public static void Main()
{
//initialize
fmod_Init(44100, 16, 0);
//load the mp3 into a soundhandle that we can use
IntPtr soundHandle = fmod_Open("C:\\Path\\To\\Song\\gone.mp3", 0 , 0, 0);
//Set the volume on the song fmod_Setvolume(soundHandle, 255);
//Play the song
fmod_Play(0, soundHandle);

Application.Init();
//Create the Window
Window myWin = new Window("My Player");
myWin.Resize(200,200);
Button playButton = new Button("Play");
myWin.Add(playButton);
//Show Everything
myWin.ShowAll();
myWin.DeleteEvent += new DeleteEventHandler(myWin_DeleteEvent);
Application.Run();
//Stop the song
fmod_stop(soundHandle);
//Close the stream
fmod_close();
}
public static void myWin_DeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}

And that's actually about it! In this example I've tried to use GTK+ so that the GUI part will work for both Windows and Linux.

I'll let you fiddle around with it a while before showing the full code including the ID3Tag etc. You're more than welcome to send me a mail or comment and I will respond as soon as possible.

Currently rated 3.0 by 4 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 8/16/2009 at 6:25 AM
Categories: C# | FMOD
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Touching the Surface

surface

In Denmark we've got three of these Surface tables, but only one is currently up and running.

A couple of weeks ago me and my fellow Microsoft Student Partners where given the opportunity to play with a Windows Surface table. Now by playing I don't just mean that we could look and feel, but we could also make our own software and run it on the Surface table... Now that was cool!! We divided ourselves in small groups and started developing some applications for the Surface table.

IMG_1280

As can be seen from the pictures one of the MSP's made an XNA game for the Surface table, which wad an asteroid game where multiple players had to touch the asteroid before they hide the spacestation in the center of the Surface table.. We had lots of fun with that...

IMG_1279

The cool thing about Windows Surface is that you are able to program it using WPF and/or XNA, which is unleashing a lot of power. As of writing I don't belive that there is a SurfaceSDK available for download just yet, but it is on the way :-) and therefore I am not going to show you any of the code we made for the Surface table just yet, but when the SDK is released, I will put up some example code..

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 3/31/2009 at 2:45 PM
Tags: , ,
Categories: C# | Surface
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

ID3 Tag version 2.3.0

Now I've tried to make a simple version of how too get the tags out of ID3v2.3.0 tags, but I think I failed..... 

It's was not easy to do.... On purpose I haven't gotten into the part about flags, and extended headers (allthough its not too hard to implement now), because it would cloud the bigger picture... So without further delay, here is the code... (please mail me if it simply dosn't make any sense, I've rewritten the code a few times, so a couple of mistakes can be present, but the code works though Wink )

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Drawing;

 

namespace Id3

{

    class test

    {        

        private long startPosition = 0;

        private byte[] byteArray = new byte[6];             

        private string path;

        public Bitmap bmp;

        // Method to do the bute parsing so we can calculate the size of the header

        private static int GetLengthOfTag(byte[] calcByteArray)

        {   // now this is kind of long haired so just take it as it is 

            /* Basically, every 8th bit is filled with a 0 (zero) which means that the bits look like this:

                0xxxxxxx 0xxxxxxx 0xxxxxxx 0xxxxxxx

               which again means that a bit pattern (2 bytes) looking like this:

                00100011 10110011 (35 and 179)

               will look like this:

                01000111 00110011 (71 and 51)

               So a need for bit crunching......

             * if calByteArray[3] = 25 and calcByteArray[2] = 30, then its going look like this:

             * bytes[3] = 25 + (30 << 7), which is 25 + 3840 and in bits:

             * bytes[3] = 11001 + (11110 << 7)

             * bytes[3] = 11001 +  111100000000 and the final number is:

             * bytes[3] = 111100011001 (3865)..... Now taking a closer look at this number...

             * bytes[3] = 11110 (30) 0011001 (25), its pure magic, don't forget, every 8th bit is zero'ed and therefore ignored....

             */

            int lenght = 0; 

            int[] bytes = new int[4];

            bytes[3] =   calcByteArray[3]             + ((calcByteArray[2] * 1) << 7);

            bytes[2] = ((calcByteArray[2] >> 1) * 63) + ((calcByteArray[1] * 3) << 6);

            bytes[1] = ((calcByteArray[1] >> 2) * 31) + ((calcByteArray[0] * 7) << 5);

            bytes[0] = ((calcByteArray[0] >> 3) * 15);            

 

            lenght = (10 + bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));            

            return lenght;

        }

 

        public void RecurseDirectories(string myPath)

        {

            path = myPath;

            string[] dirs = Directory.GetDirectories(myPath);

 

            if (dirs.Length > 0)

            {

 

                foreach (string subDir in dirs)

                {                    

                    RecurseDirectories(subDir);

                }

            }            

 

            //This point will be reached after the current directory has been checked for other directories... 

            string[] fileNames = Directory.GetFiles(myPath);

            

            foreach (string fileName in fileNames)

            {

                using (System.IO.FileStream fs = System.IO.File.OpenRead(fileName))

                {

                    fs.Read(byteArray, 0, 6); // read the first 6 bytes of "main" header

                    // Read in the first three bytes to check for ID3, if its there we have a tag, otherwise we don't

                    string startOfID3 = ((char)byteArray[0]).ToString() + ((char)byteArray[1]).ToString() + ((char)byteArray[2]).ToString();

                    if (startOfID3.Equals("ID3"))

                    {

                        int versionMajor = byteArray[3]; //The version of the IDTAG is placed at the fourth byte

                        int versionMinor = byteArray[4]; //Not used right now, but will be used later

                        Console.WriteLine("MajorVersion = {0}", versionMajor);

                        Console.WriteLine("MinorVersion = {0}", versionMinor);

                        if (versionMajor == 2)

                        {   // at present time, only ID3v2.3 is supported

                            Console.WriteLine("ID3v2.2 not supported yet");

                        }

 

                        int frameIdSize; //ID3v2.2 uses 3 charecters xx xx xx while ID3v2.3 uses 4 charecters xx xx xx xx 

                        int flagSize; 

 

                        frameIdSize = (versionMajor > 2) ? 4 : 3;

                        Console.WriteLine("frameIdSize = {0}", frameIdSize);

                        flagSize = (versionMajor > 2) ? 2 : 0;

                        Console.WriteLine("flagSize = {0}", flagSize);

 

                        // parse the header

                        fs.Read(byteArray, 0, 4); // read the last 4 bytes of "main" header which containes the size

                        // of the header (header total = 10 bytes)                        

                        int lenghtOfHeader = GetLengthOfTag(byteArray); // Going on to calculate the length of the header 

                        

                        byteArray = new byte[lenghtOfHeader];

                        fs.Read(byteArray, 0, lenghtOfHeader); /* read the main header into our byteArray*/

                        startPosition = fs.Position;

 

                        int currentPosition = 0;

                        byte[] tag = new byte[frameIdSize];

                        byte[] lenghtArray = new byte[frameIdSize];

                        byte[] stringFrameContent;

                        string frameID;

                        int lengthOfTag = 0;

                        // Now looping through the tags

                        do

                        {

                            if ((currentPosition + 10) > lenghtOfHeader)

                            {

                                Console.WriteLine("Ups!");

                                break;

                            }

 

                            frameID = "";

                            // Copy contents of byteArray to tag

                            Array.Copy(byteArray, currentPosition, tag, 0, frameIdSize);

                            currentPosition += frameIdSize; // keep track of position

                            // Copy contents of byteArray to lenghtArray

                            Array.Copy(byteArray, currentPosition, lenghtArray, 0, frameIdSize);

                            currentPosition += frameIdSize; // keep track of position

 

                            

                            if (flagSize > 0)

                            {

                                

                                currentPosition += 2; 

                            }

 

                            lengthOfTag = 0;

 

                            

                            for (int i = frameIdSize - 1; i >= 0; i--)

                            {

                                int ml = 1;

                                for (int j = i; j < frameIdSize - 1; j++)

                                {

                                    ml *= 256;

                                }

                                lengthOfTag += lenghtArray[i] * ml;

                            }

 

                            stringFrameContent = new byte[lengthOfTag];

                            // Copy contents of byteArray to stringContent

                            Array.Copy(byteArray, currentPosition, stringFrameContent, 0, lengthOfTag);

                            currentPosition += lengthOfTag;

 

 

                            frameID = System.Text.Encoding.ASCII.GetString(tag);

 

                            string contentOfFrame = "";

 

                            if (frameID.Equals("TPE1"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Artist: {0}", contentOfFrame);

 

                            }

                            if (frameID.Equals("TIT2"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Song Title: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TALB"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Album: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TRCK"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Tracknumber: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TYER"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Year: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TCON"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Genre: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("APIC"))

                            {

                                Console.WriteLine("PICTURE");                                                   

 

                            }

                        }

                        while (lengthOfTag > 0);

                    }

                    else 

                    { 

                        Console.WriteLine("No tags present"); 

                    }

                }//end using

 

                Console.ReadLine();

            }//end foreach

        }//end method RecurseDirectories

    }

 

 

I've tried to comment the code as good as possible, but hey, I'm only human... Send me a mail if something is wrong, or not understanderble.... 

This code may be revisited a few times to make modifications....... 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 2/4/2009 at 1:21 PM
Tags: ,
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Free C# Teaching Materials

Rob Miles, aprofessor at the University of Hull, (and co-author to Embedded Programming With The Microsoft .NET Micro Framework) has released his C# teaching materials for free. It is available from here..

The book contains 185 pagesand covers everything from how to start with C# (like the basic languageconstructs) to how to create user interfaces, components and even how toencapsulate the logic of your application into business objects.

 

Currently rated 3.0 by 4 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 12/27/2008 at 3:29 PM
Tags: , ,
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Id3TAG and C#

The other day one of my friends told me that he was tired of all the programs on the marked claiming that they were perfect for keeping track of his music collection. When I asked what he was looking for, he told me that he needed a program that could read in his collection of mp3’s and keep track of these music files. Thay should be loaded into the program, and listed by their Tag id (title, artist, album and so on). You should also be able to edit the tags, mark all mp3’s and select ”remove all comments”. He also wanted the program to able to get titles, album names and so on for the files in his collection which doesn’t have a tag. Now this last part is properly the hardest thing (not impossible) to accomplish, I decided to write a blog on how to make such a program.

In this first part, I started out with trying to retrieve the information, and putting the output on the console (This will be in version ID3v1, but later on it will also be in version ID3v2). I mean, test the functionality before deciding on GUI layout and all. This meant that I have to somehow search through my ”music” directory and list all files, and subdirectories files. And what better way to do that than with a recursive method. Now here is what I did.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace Id3

{

    class test

    {

        public byte[] TAGID = new byte[3];     

        public byte[] Title = new byte[30];     

        public byte[] Artist = new byte[30];    

        public byte[] Album = new byte[30];     

        public byte[] Year = new byte[4];       

        public byte[] Comment = new byte[30];   

        public byte[] Genre = new byte[1];      

        //Search through directories and sub directories to find mp3's

        //and I do this by a recursive method..

        public void SearchDirectories(string StartPath)

        {

            string[] dirs = Directory.GetDirectories(StartPath);

            if (dirs.Length > 0)

            {

                foreach (string subDirectories in dirs)

                {

                    SearchDirectories(subDirectories);

                }                           

            }

          

            //Will reach here after the current directory has been checked for other directories..

            string[] fileNames = Directory.GetFiles(StartPath);

            foreach (string fileName in fileNames)

            {   // When utilizing "using" we get the benefit of not having to close the FileStream ourselves, this is done for us. (there is more, but I will elaborate on this later).

                using (System.IO.FileStream fs = System.IO.File.OpenRead(fileName))

                {   // The tag information is the last 128 bit of an mp3...

                    if (fs.Length >= 128)

                    {

                        test tag = new test();

                        fs.Seek(-128, System.IO.SeekOrigin.End);

                        fs.Read(tag.TAGID, 0, tag.TAGID.Length);

                        fs.Read(tag.Title, 0, tag.Title.Length);

                        fs.Read(tag.Artist, 0, tag.Artist.Length);

                        fs.Read(tag.Album, 0, tag.Album.Length);

                        fs.Read(tag.Year, 0, tag.Year.Length);

                        fs.Read(tag.Comment, 0, tag.Comment.Length);

                        fs.Read(tag.Genre, 0, tag.Genre.Length);

                        string theTAGID = Encoding.Default.GetString(tag.TAGID);

                        if (theTAGID.Equals("TAG"))

                        {

                            string Title = Encoding.Default.GetString(tag.Title);

                            string Artist = Encoding.Default.GetString(tag.Artist);

                            string Album = Encoding.Default.GetString(tag.Album);

                            string Year = Encoding.Default.GetString(tag.Year);

                            string Comment = Encoding.Default.GetString(tag.Comment);

                            string Genre = Encoding.Default.GetString(tag.Genre);

                            Console.WriteLine("Title: {0}", Title);

                            Console.WriteLine("Artist: {0}", Artist);

                            Console.WriteLine("Album: {0}", Album);

                            Console.WriteLine("Year: {0}", Year);

                            Console.WriteLine(Comment);

                            Console.WriteLine("Genre: {0}", Genre);

                            Console.WriteLine();

                        }

                    }

                }

            } Console.ReadLine();

        }

    }

}

This is actually pretty strait forward, there is nothing difficult about this piece of code. I did not have to use a recursive method in order to achieve this functionality, I did this because I recently finished a course in algorithms, and I’m simply testing my abilities.

I will continue in the next part, I have not decided what functionality to implement next (I think it will be focused to getting tag information out of the ID3v2 tags, which are quite different!), but I will return. If you find that I don’t explain my code enough, please email me, and I will make it better. I’m trying to find out who my audience is, and at what level of experience you are, so that I can make it just right. So don’t hesitate to comment.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 11/4/2008 at 1:55 AM
Tags: ,
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (5) | Post RSSRSS comment feed