ReplyRecord () ; onStopRecord ();
};
# endif//PIANOBUTTON_H
Main.cpp
# include lt; QApplication gt;
# include mainwindow.h main (int argc, char * argv [])
{a (argc, argv); * win32=new MainWindow;-gt;show();-gt;move(QApplication::desktop()-gt;width()/2-win32-gt;width()/2,::desktop()-gt;height()/2-win32-gt;height()/2);a.exec();
}
Mainwindow.cpp
# include mainwindow.h :: MainWindow (QWidget * parent): (parent), timer (QTime :: currentTime ()), record (false)
{notes= Q1W2ER4T5Y6UI8O9P [-] =, K.ZAXSCVFBGNHM raquo ;;=new QMenuBar; gt; setFixedHeight (25); * menu_file=new QMenu ( amp; Файл ); _ file- gt; addAction ( amp; Відкрити записьraquo;,this,SLOT(openFile()),Qt::CTRL+Qt::Key_O);_file-gt;addAction(laquo;amp;Сохранить записьraquo;,this,SLOT(saveFile()),Qt::CTRL+Qt::Key_S);_file-gt;addSeparator();_file-gt;addAction(laquo;amp;Выходraquo;,qApp,SLOT(quit()),Qt::CTRL+Qt::Key_Q);gt;addMenu(menu_file);gt;addAction(laquo;amp;Разработчикraquo;,this,SLOT(about_dev()));_piano =New QList lt; PianoButton * gt ;; * temp; (int i=0; i lt; 2; ++ i)
{= new PianoButton (0, notes.mid (i * 12 + 0,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 1,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 2,1)); _ piano- gt; append (temp);=new PianoButton ( 0, notes.mid (i * 12 + 3,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 4,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 5,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 6,1 )); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 7,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 8,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 9,1)); _ piano- gt; append (temp);= new PianoButton (0, notes.mid (i * 12 + 10,1)); _ piano- gt; append (temp);=new PianoButton (0, notes.mid (i * 12 + 11,1)); _ piano- gt; append (temp);
} * btn; (int i=0; i lt; list_piano- gt; count (); ++ i)
{= list_piano-gt;at(i);(this,SIGNAL(press(QKeyEvent*)),btn,SLOT(onPress(QKeyEvent*)));(this,SIGNAL(press(QKeyEvent*,QTime)),btn,SLOT(onPress(QKeyEvent*,QTime)));(this,amp;MainWindow::release,btn,amp;PianoButton::onRelease);(this,amp;MainWindow::restart,btn,amp;PianoButton::onRestart);(this,amp;MainWindow::play,btn,amp;PianoButton::onReplyRecord);(this,amp;MainWindow::stop,btn,amp;PianoButton::onStopRecord);_piano-gt;at(i)-gt;effect-gt;setSource(QUrl::fromLocalFile(laquo;:/sounds/raquo;+QString::number(i)+laquo;.wavraquo;));
}=new QToolBar;gt;addAction(laquo;Записьraquo;,this,SLOT(onRecord()));gt;addAction(laquo;Стоп записьraquo;,this,SLOT(onStopRecord()));gt;addAction(laquo;Проигратьraquo;,this,SIGNAL(play()));* grid=new QGridLayout; gt; setMargin (5); gt; setSpacing (5); (int i=0; i lt; 2; ++ i)
{gt;addWidget(list_piano-gt;at(i*12+0),1,i*7+0,1,1);gt;addWidget(list_piano-gt;at(i*12+1),0,i*7+0,1,2,Qt::AlignHCenter);gt;addWidget(list_piano-gt;at(i*12+2),1,i*7+1,1,1);gt;addWidget(list_piano-gt;at(i*12+3),0,i*7+1,1,2,Qt::AlignHCenter);gt;addWidget(list_piano-gt;at(i*12+4),1,i*7+2,1,1);gt;addWidget(list_piano-gt;at(i*12+5),1,i*7+3,1,1);gt;addWidget(list_piano-gt;at(i*12+6),0,i*7+3,1,2,Qt::AlignHCenter);gt;addWidget(list_piano-gt;at(i*12+7),1,i*7+4,1,1);gt;addWidget(list_piano-gt;at(i*12+8),0,i*7+4,1,2,Qt::AlignHCenter);gt;addWidget(list_piano-gt;at(i*12+9),1,i*7+5,1,1);gt;addWidget(list_piano-gt;at(i*12+10),0,i*7+5,1,2,Qt::AlignHCenter);gt;addWidget(list_piano-gt;at(i*12+11),1,i*7+6,1,1);
} * vlayo=new QVBoxLayout;gt;setMargin(5);gt;setSpacing(5);gt;addWidget(bar);gt;addWidget(tools);gt;addLayout(grid);gt;setLayout(vlayo);
} MainWindow :: keyPressEvent (QKeyEvent * event)
{(record)
{press (event, QTime :: currentTime ());
} else
{press (event);
}
} MainWindow :: keyReleaseEvent (QKeyEvent * event)
{release (event);
} MainWindow :: onRecord ()
{= QTime :: currentTime (); restart (timer);=true;
} MainWindow :: onStopRecord ()
{= false; stop ();
} MainWindow :: openFile ()
{str=QFileDialog :: getOpenFileName (this, Відкрити запис , QString (), My melody files (* .mym) ); (! str.isEmpty ())
{file (str); stream ( amp; file); (file.op...