OSDN Git Service

リセット
[momiji/momiji_main.git] / Test / Momiji.Test.Sequencer.Midi / Form1.h
1 #pragma once
2 #using <Momiji.Core.dll>
3 namespace MomijiTestSequencerMidi {
4
5         using namespace System;
6         using namespace System::ComponentModel;
7         using namespace System::Collections;
8         using namespace System::Windows::Forms;
9         using namespace System::Data;
10         using namespace System::Drawing;
11
12         /// <summary>
13         /// Form1 \82Ì\8aT\97v
14         /// </summary>
15         public ref class Form1 : public System::Windows::Forms::Form
16         {
17         public:
18                 Form1(void)
19                 {
20                         InitializeComponent();
21                         //
22                         //TODO: \82±\82±\82É\83R\83\93\83X\83g\83\89\83N\83^\81\83R\81[\83h\82ð\92Ç\89Á\82µ\82Ü\82·
23                         //
24                 }
25
26         protected:
27                 /// <summary>
28                 /// \8eg\97p\92\86\82Ì\83\8a\83\\81[\83X\82ð\82·\82×\82Ä\83N\83\8a\81[\83\93\83A\83b\83v\82µ\82Ü\82·\81B
29                 /// </summary>
30                 ~Form1()
31                 {
32                         if (components)
33                         {
34                                 delete components;
35                         }
36                 }
37         private: System::Windows::Forms::ComboBox^  comboBox1;
38         private: System::Windows::Forms::Button^  button1;
39         private: Momiji::Core::ITimer^ t;
40         private: Momiji::Core::IStream^ s;
41         private: Momiji::Core::Midi::Out::Devices^ o;
42         private: Momiji::Controler::Player^ p;
43         private: System::Windows::Forms::Button^  button2;
44         protected: 
45
46         private:
47                 /// <summary>
48                 /// \95K\97v\82È\83f\83U\83C\83i\81[\95Ï\90\94\82Å\82·\81B
49                 /// </summary>
50                 System::ComponentModel::Container ^components;
51
52 #pragma region Windows Form Designer generated code
53                 /// <summary>
54                 /// \83f\83U\83C\83i\81\83T\83|\81[\83g\82É\95K\97v\82È\83\81\83\\83b\83h\82Å\82·\81B\82±\82Ì\83\81\83\\83b\83h\82Ì\93à\97e\82ð
55                 /// \83R\81[\83\83G\83f\83B\83^\81[\82Å\95Ï\8dX\82µ\82È\82¢\82Å\82­\82¾\82³\82¢\81B
56                 /// </summary>
57                 void InitializeComponent(void)
58                 {
59                         this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
60                         this->button1 = (gcnew System::Windows::Forms::Button());
61                         this->button2 = (gcnew System::Windows::Forms::Button());
62                         this->SuspendLayout();
63                         // 
64                         // comboBox1
65                         // 
66                         this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
67                         this->comboBox1->FormattingEnabled = true;
68                         this->comboBox1->Location = System::Drawing::Point(12, 12);
69                         this->comboBox1->Name = L"comboBox1";
70                         this->comboBox1->Size = System::Drawing::Size(513, 20);
71                         this->comboBox1->TabIndex = 0;
72                         // 
73                         // button1
74                         // 
75                         this->button1->Location = System::Drawing::Point(13, 39);
76                         this->button1->Name = L"button1";
77                         this->button1->Size = System::Drawing::Size(75, 23);
78                         this->button1->TabIndex = 1;
79                         this->button1->Text = L"START";
80                         this->button1->UseVisualStyleBackColor = true;
81                         this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
82                         // 
83                         // button2
84                         // 
85                         this->button2->Location = System::Drawing::Point(95, 39);
86                         this->button2->Name = L"button2";
87                         this->button2->Size = System::Drawing::Size(75, 23);
88                         this->button2->TabIndex = 2;
89                         this->button2->Text = L"STOP";
90                         this->button2->UseVisualStyleBackColor = true;
91                         this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
92                         // 
93                         // Form1
94                         // 
95                         this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
96                         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
97                         this->ClientSize = System::Drawing::Size(537, 73);
98                         this->Controls->Add(this->button2);
99                         this->Controls->Add(this->button1);
100                         this->Controls->Add(this->comboBox1);
101                         this->Name = L"Form1";
102                         this->Text = L"Form1";
103                         this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
104                         this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
105                         this->ResumeLayout(false);
106
107                 }
108 #pragma endregion
109         private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
110
111                                 auto list = 
112                                         gcnew System::Collections::Generic::List<System::Collections::Generic::KeyValuePair<System::String^, Momiji::Interop::Winmm::MidiOutCapabilities^>>();
113                                 System::UInt32 nums = Momiji::Core::Midi::Out::Device::GetNumDevices();
114                                 
115                                 for (System::UInt32 idx = 0; idx < nums; idx++) {
116
117                                         try
118                                         {
119                                                 auto cap = Momiji::Core::Midi::Out::Device::GetCapabilities(idx);
120                                                 auto pair = System::Collections::Generic::KeyValuePair<System::String^, Momiji::Interop::Winmm::MidiOutCapabilities^>(cap->productName, cap);
121                                                 list->Add(pair);
122                                         }
123                                         catch(Exception^ e)
124                                         {
125                                                 Console::WriteLine(e->ToString());
126                                         }
127                                 }
128
129                                 this->comboBox1->DisplayMember = "Key";
130                                 this->comboBox1->DataSource = list;
131
132                          }
133
134         private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
135                                 System::String^ fileName;
136                                 System::Windows::Forms::OpenFileDialog^ dialog = gcnew System::Windows::Forms::OpenFileDialog();
137                                 try
138                                 {
139                                         dialog->InitialDirectory = System::IO::Directory::GetCurrentDirectory();
140                                         dialog->Filter = "midi|*.mid";
141                                         if (dialog->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
142                                         {
143                                                 Console::WriteLine("============ \8eæ\82è\8fÁ\82µ");
144                                                 return;
145                                         }
146
147                                         fileName = dialog->FileName;
148                                 }
149                                 finally
150                                 {
151                                         delete dialog;
152                                 }
153
154                                 this->button2_Click(this, e);
155
156                                 t = gcnew Momiji::Core::Timer::MMTimer();
157                                 s = gcnew Momiji::Sequencer::Midi::Smf::SmfStream(fileName);
158                                 o = gcnew Momiji::Core::Midi::Out::Devices();
159                                 o->AddPort(this->comboBox1->SelectedIndex);
160
161                                 p = gcnew Momiji::Controler::Player();
162                                 p->Assign(t);
163                                 p->Assign(s);
164                                 p->Assign(o);
165
166                                 p->Start();
167                          }
168         private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
169                                 if (p != nullptr) {
170                                         delete p;
171                                         p = nullptr;
172                                 }
173
174                                 if (t != nullptr) {
175                                         delete t;
176                                         t = nullptr;
177                                 }
178
179                                 if (s != nullptr) {
180                                         delete s;
181                                         s = nullptr;
182                                 }
183
184                                 if (o != nullptr) {
185                                         delete o;
186                                         o = nullptr;
187                                 }
188                          }
189 private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
190                          this->button2_Click(this, e);
191                  }
192 };
193 }
194