Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using dxvblib;
Play music in namespace
{
/// <Summary>
/// Summary of form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. Container components = NULL;
Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
DirectX = new directx7class ();
Performance = DirectX. directmusic1_cecreate ();
Composer = DirectX. directmusiccomposercreate ();
Loader = DirectX. directmusicloadercreate ();
Performance. INIT (null, 0 );
Performance. setport (-1, 4 );
Performance. setmasterautodownload (true );
// Chordmap = loader. loadchordmap (@ "F:/game music (MID)/game01fm. Mid ");
Try
{
Chordmap = loader. loadchordmap ("chordmap. CDM ");
}
Catch (exception)
{
MessageBox. Show ("cocould not load chordmap." + "please ensure that chordmap. CDM is" + "in the directory of this exectutable .");
}
//
// Todo: add Any constructor code after initializecomponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. button1 = new system. Windows. Forms. Button ();
This. suspendlayout ();
//
// Button1
//
This. button1.location = new system. Drawing. Point (96,192 );
This. button1.name = "button1 ";
This. button1.tabindex = 0;
This. button1.text = "button1 ";
This. button1.click + = new system. eventhandler (this. button#click );
//
// Form1
//
This. autoscalebasesize = new system. Drawing. Size (6, 14 );
This. clientsize = new system. Drawing. Size (292,266 );
This. Controls. Add (this. button1 );
This. Name = "form1 ";
This. Text = "form1 ";
This. resumelayout (false );
}
# Endregion
/// <Summary>
/// Main entry point of the application.
/// </Summary>
Private directx7 DirectX;
Private directmusicchordmap chordmap;
Private directmusiccomposer composer;
Private directmusicperformance performance;
Private directmusicsegment segment;
Private directmusicloader;
Private system. Windows. Forms. Button button1;
Private directmusicstyle style;
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
Private void button#click (Object sender, system. eventargs E)
{
Try
{
Style = loader. loadstyle (@ "F:/game music (MID)/game01fm. Mid ");
Segment = composer. composegmentfromshape (style, 64, 0, 2, false, false, chordmap );
Composer. autotransition (performance, segment, (INT) const_dmus_commandt_types.dmus_commandt_fill, (INT) const_dmus_composef_flags.dmus_composef_immediate, chordmap );
}
Catch (exception)
{
MessageBox. Show ("cannot play music ");
}
}
}
}