-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51eb728
Showing
14 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
.vscode/ | ||
test** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# MeloNote | ||
|
||
> 开发中... | ||
轻量的旋律灵感记录器。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(MeloNote VERSION 0.1 LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) | ||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) | ||
|
||
set(PROJECT_SOURCES | ||
core.cpp | ||
core.h | ||
main.cpp | ||
mainwindow.cpp | ||
mainwindow.h | ||
mainwindow.ui | ||
) | ||
|
||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) | ||
qt_add_executable(MeloNote | ||
MANUAL_FINALIZATION | ||
${PROJECT_SOURCES} | ||
) | ||
# Define target properties for Android with Qt 6 as: | ||
# set_property(TARGET MeloNote APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR | ||
# ${CMAKE_CURRENT_SOURCE_DIR}/android) | ||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation | ||
else() | ||
if(ANDROID) | ||
add_library(MeloNote SHARED | ||
${PROJECT_SOURCES} | ||
) | ||
# Define properties for Android with Qt 5 after find_package() calls as: | ||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") | ||
else() | ||
add_executable(MeloNote | ||
${PROJECT_SOURCES} | ||
) | ||
endif() | ||
endif() | ||
|
||
target_link_libraries(MeloNote PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) | ||
|
||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. | ||
# If you are developing for iOS or macOS you should consider setting an | ||
# explicit, fixed bundle identifier manually though. | ||
if(${QT_VERSION} VERSION_LESS 6.1.0) | ||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.MeloNote) | ||
endif() | ||
set_target_properties(MeloNote PROPERTIES | ||
${BUNDLE_ID_OPTION} | ||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} | ||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} | ||
MACOSX_BUNDLE TRUE | ||
WIN32_EXECUTABLE TRUE | ||
) | ||
|
||
include(GNUInstallDirs) | ||
install(TARGETS MeloNote | ||
BUNDLE DESTINATION . | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
|
||
if(QT_VERSION_MAJOR EQUAL 6) | ||
qt_finalize_executable(MeloNote) | ||
endif() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "core.h" | ||
#include <iostream> | ||
using namespace std; | ||
void NoteList::calc_dtime() | ||
{ | ||
for (int i = 1; i < list.size(); i++) | ||
{ | ||
auto dt = list[i].time - list[i - 1].time; | ||
dtime.push_back(dt); | ||
} | ||
dtime_ready = 1; | ||
} | ||
double time_try(const ull &dt) | ||
{ | ||
// TODO | ||
} | ||
double NoteList::calc_bpm() | ||
{ | ||
// 若开头存在4个以上0则使用其计算bpm | ||
unsigned cnt; | ||
for (cnt = 0; cnt < list.size(); cnt++) | ||
{ | ||
if (list[cnt].name != "0") | ||
break; | ||
} | ||
if (cnt >= 4) | ||
{ | ||
auto t1 = list[cnt - 4].time; | ||
auto t2 = list[cnt - 1].time; | ||
// TODO: 计算 | ||
bpm_ready = 1; | ||
return bpm; | ||
} | ||
// 否则使用后续的操作猜测bpm | ||
if (dtime_ready) | ||
calc_dtime(); | ||
// TODO: sort(dtime) | ||
} | ||
void NoteList::key_log(const string &s, const ull &t) | ||
{ | ||
push_back(NoteEvent(s, t)); | ||
} | ||
|
||
void NoteEvent::show() const | ||
{ | ||
cout << name << " " << time << endl; | ||
} | ||
void NoteList::show() const | ||
{ | ||
for (auto &i : list) | ||
{ | ||
i.show(); | ||
} | ||
} | ||
void NoteList::clear() { list.clear(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#define ull unsigned long long | ||
using namespace std; | ||
class NoteEvent | ||
{ | ||
string name; | ||
int prefix; | ||
string suffix; | ||
ull time; | ||
friend class NoteList; | ||
|
||
public: | ||
NoteEvent(const string &str, const ull &t) | ||
: name(str), time(t){}; | ||
void show() const; | ||
}; | ||
class NoteList | ||
{ | ||
vector<NoteEvent> list; | ||
bool dtime_ready; | ||
vector<ull> dtime; | ||
double time_try(const ull &); | ||
void calc_dtime(); | ||
bool bpm_ready; | ||
double bpm; | ||
double calc_bpm(); | ||
|
||
public: | ||
void push_back(const NoteEvent &e) { list.push_back(e); } | ||
double get_bpm(); | ||
double set_bpm(); | ||
void key_log(const string &s, const ull &t); | ||
void show() const; | ||
void clear(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "keyrecorderwindow.h" | ||
#include "./ui_keyrecorderwindow.h" | ||
|
||
KeyRecorderWindow::KeyRecorderWindow(QWidget *parent) | ||
: QWidget(parent) | ||
, ui(new Ui::KeyRecorderWindow) | ||
{ | ||
ui->setupUi(this); | ||
} | ||
|
||
KeyRecorderWindow::~KeyRecorderWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void KeyRecorderWindow::on_pushButton_clicked() | ||
{ | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef KEYRECORDERWINDOW_H | ||
#define KEYRECORDERWINDOW_H | ||
|
||
#include <QWidget> | ||
|
||
QT_BEGIN_NAMESPACE | ||
namespace Ui { | ||
class KeyRecorderWindow; | ||
} | ||
QT_END_NAMESPACE | ||
|
||
class KeyRecorderWindow : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
KeyRecorderWindow(QWidget *parent = nullptr); | ||
~KeyRecorderWindow(); | ||
|
||
private: | ||
Ui::KeyRecorderWindow *ui; | ||
}; | ||
#endif // KEYRECORDERWINDOW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>KeyRecorderWindow</class> | ||
<widget class="QWidget" name="KeyRecorderWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>228</width> | ||
<height>123</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>KeyRecorderWindow</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="text"> | ||
<string>Start</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "mainwindow.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "mainwindow.h" | ||
#include "./ui_mainwindow.h" | ||
#include "core.h" | ||
#include <iostream> | ||
using namespace std; | ||
MainWindow::MainWindow(QWidget *parent) | ||
: QMainWindow(parent), ui(new Ui::MainWindow) | ||
{ | ||
ui->setupUi(this); | ||
start_time = 0; | ||
is_Recording = 0; | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void MainWindow::on_start_stop_button_clicked() | ||
{ | ||
cout << "Called!" << endl; | ||
if (!is_Recording) | ||
{ | ||
is_Recording = 1; | ||
current_list.clear(); | ||
start_time = QDateTime::currentMSecsSinceEpoch(); | ||
} | ||
else | ||
{ | ||
is_Recording = 0; | ||
current_list.show(); | ||
} | ||
} | ||
|
||
void MainWindow::keyPressEvent(QKeyEvent *event) | ||
{ | ||
if (is_Recording && !event->isAutoRepeat()) | ||
{ // 判定是否在记录,忽略长按时的自动重复 | ||
qint64 timestamp = QDateTime::currentMSecsSinceEpoch() - start_time; // 获取当前时间戳 | ||
current_list.key_log(QString(event->text().at(0)).toStdString(), timestamp); | ||
} | ||
QWidget::keyPressEvent(event); // 保证正常的按键事件处理 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include <QWidget> | ||
#include <QPushButton> | ||
#include <QKeyEvent> | ||
#include <QDateTime> | ||
#include "core.h" | ||
QT_BEGIN_NAMESPACE | ||
namespace Ui { | ||
class MainWindow; | ||
} | ||
QT_END_NAMESPACE | ||
|
||
class MainWindow : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
MainWindow(QWidget *parent = nullptr); | ||
~MainWindow(); | ||
protected: | ||
void keyPressEvent(QKeyEvent *event) override; | ||
private slots: | ||
void on_start_stop_button_clicked(); | ||
|
||
private: | ||
Ui::MainWindow *ui; | ||
bool is_Recording; | ||
qint64 start_time; | ||
NoteList current_list; | ||
}; | ||
#endif // MAINWINDOW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>236</width> | ||
<height>212</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QPushButton" name="start_stop_button"> | ||
<property name="text"> | ||
<string>PushButton</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>236</width> | ||
<height>24</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE TS> | ||
<TS version="2.1" language="zh_CN"></TS> |