Ejemplo n.º 1
0
        private void btnN6_Click(object sender, EventArgs e)
        {
            MyComposition comp1 = new MyComposition(formTempo);

            comp1.addNote(generatedNotes.ElementAt(5));
            comp1.play(outputDevice);
        }
Ejemplo n.º 2
0
        public static void play(List <MyNote> lista, int t, OutputDevice outputDevice)
        {
            MyComposition newComp = new MyComposition(t);

            foreach (MyNote n in lista)
            {
                newComp.addNote(n);
            }

            int positionStatic      = 0;
            int totalDurationStatic = 0;
            int beatLengthStatic    = 60000 / t;


            Clock clock = new Clock(t);

            foreach (MyNote n in lista)
            {
                totalDurationStatic += n.myDurationInBeats * beatLengthStatic;
                clock.Schedule(n.noteStart(outputDevice, positionStatic));
                positionStatic += n.myDurationInBeats;
                clock.Schedule(n.noteEnd(outputDevice, positionStatic));
            }
            clock.Start();
            Thread.Sleep(totalDurationStatic + 1000); // 1 additional second
            clock.Stop();
        }
Ejemplo n.º 3
0
        private void openFile()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Composed music files (*.cmf)|*.cmf";
            openFileDialog.Title  = "Open composed music file";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileName = openFileDialog.FileName;
                try
                {
                    using (FileStream fileStream = new FileStream(FileName, FileMode.Open))
                    {
                        IFormatter formater = new BinaryFormatter();
                        composition = (MyComposition)formater.Deserialize(fileStream);
                        generateNotes();
                        rbMedium.Checked   = true;
                        compositionHistory = new List <Components>();
                        fillPanel();
                        radioButton3.Checked = true;
                        picGraph.Invalidate(true);
                        clearGeneratedChecked();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not read file: " + FileName);
                    FileName = null;
                    return;
                }
                Invalidate(true);
            }
        }
Ejemplo n.º 4
0
        private void button16_Click(object sender, EventArgs e)
        {
            List <MyNote> posledni   = composition.getLastSix();
            MyComposition singleNote = new MyComposition(formTempo);

            singleNote.addNote(posledni.ElementAt(5));
            singleNote.play(outputDevice);
        }
Ejemplo n.º 5
0
 public Form1()
 {
     InitializeComponent();
     octave    = 60;
     formTempo = 200;
     openOutputDevice();
     generatedNotes = new List <MyNote>();
     generateNotes();
     composition          = new MyComposition(formTempo);
     compositionHistory   = new List <Components>();
     radioButton3.Checked = true;
     //disableButtons();
     comboBox1.SelectedIndex = comboBox1.Items.IndexOf("Generate 6 notes");
 }
Ejemplo n.º 6
0
        private void PlayLastSix_Click(object sender, EventArgs e)
        {
            int compositionLength = composition.getLength();

            if (compositionLength > 6)
            {
                List <MyNote> lastSix = composition.getLastSix();
                MyComposition.play(lastSix, formTempo, outputDevice);
            }
            else
            {
                composition.setTempo(formTempo);
                composition.play(outputDevice);
            }
        }
Ejemplo n.º 7
0
        //----------------------------------- PANEL -------------------------------------------------------------------


        private void fillPanel()
        {
            panel1.Controls.Clear();
            int radioY        = 53;
            int buttonY       = 10;
            int counter       = 0;
            int currentButton = 10;
            int currentRadio  = 37;
            int increment     = 80;

            foreach (MyNote n in composition.getListNotes())
            {
                panel1.HorizontalScroll.Value = 0;

                Button      button      = new Button();
                RadioButton radioButton = new RadioButton();

                button.Height     = 40;
                button.Width      = 70;
                radioButton.Width = 35;

                //button.Tag = counter;
                radioButton.Tag = counter;


                button.Location      = new Point(currentButton, buttonY);
                radioButton.Location = new Point(currentRadio, radioY);

                compositionHistory.Add(new Components(button, radioButton));

                currentRadio  += increment;
                currentButton += increment;

                button.Text = n.ToString();

                button.Click += (s, e) => {
                    MyComposition comp = new MyComposition(formTempo);
                    comp.addNote(n);
                    comp.play(outputDevice);
                };

                panel1.Controls.Add(button);
                panel1.Controls.Add(radioButton);

                panel1.ScrollControlIntoView(button);
                counter++;
            }
        }
Ejemplo n.º 8
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     octave      = 60;
     formTempo   = 200;
     composition = new MyComposition(200); //medium tempo is 200
     generateNotes();
     rbMedium.Checked   = true;
     compositionHistory = new List <Components>();
     panel1.Controls.Clear();
     radioButton3.Checked = true;
     picGraph.Invalidate(true);
     comboBox1.SelectedIndex = comboBox1.Items.IndexOf("Generate 6 notes");
     clearGeneratedChecked();
     radioButton1.Enabled = true;
     radioButton2.Enabled = true;
     radioButton3.Enabled = true;
 }
Ejemplo n.º 9
0
        private void PlaySample_Click(object sender, EventArgs e)
        {
            MyComposition comp = new MyComposition(formTempo);

            comp.addNote(new MyNote(64, 1));
            comp.addNote(new MyNote(64, 1));
            comp.addNote(new MyNote(65, 1));
            comp.addNote(new MyNote(67, 1));
            comp.addNote(new MyNote(67, 1));
            comp.addNote(new MyNote(65, 1));
            comp.addNote(new MyNote(64, 1));
            comp.addNote(new MyNote(62, 1));
            comp.addNote(new MyNote(60, 1));
            comp.addNote(new MyNote(60, 1));
            comp.addNote(new MyNote(62, 1));
            comp.addNote(new MyNote(64, 1));
            comp.addNote(new MyNote(64, 2));
            comp.addNote(new MyNote(62, 1));
            comp.addNote(new MyNote(62, 1));
            comp.play(outputDevice);
        }