La Transformée de Fourier et la Musique

Programme en C++ Qt6 basé directement sur la transformée de Fourier rapide. Retrouve les notes de musique (et leur code midi) à partir d'un fichier audio (fichier.wav)
Ce fichier source doit être stéréo échantillonné à 48kb/s, ce qui peut être facilement obtenu avec le soft avidemux (par exemple), éventuellement après extraction de la piste audio d'une vidéo .mp4.

1 Vue d'ensemble



Les notes obtenues peuvent être rejouées, les durées et le rythme sont pris en compte

2 Scan en cours (Transformée de fourier d'un échantillon de signal)

3 Aperçu en vidéo


A voir directement sur Youtube en 1080p pour voir les détails !!!

4 Le code source 'wav to midi' en C++ Qt6: fichier mainwindow.cpp



CODE SOURCE en C++
  1. /* top
  2.   Calcul de la transformée de Fourier rapide d'un signal audio au format PCM enregistré dans un fichier .wav
  3.   Format WAVE, RIFF, fmt échantilloné à 48000Hz
  4.  
  5.   Format : Wave
  6.   File size : 2.39 MiB
  7.   Duration : 13 s 54 ms
  8.   Overall bit rate mode : Constant
  9.   Overall bit rate : 1 536 kb/s
  10.  
  11.   Audio
  12.   Format : PCM
  13.   Format settings : Little / Signed
  14.   Codec ID : 1
  15.   Duration : 13 s 54 ms
  16.   Bit rate mode : Constant
  17.   Bit rate : 1 536 kb/s
  18.   Channel(s) : 2 channels
  19.   Sampling rate : 48.0 kHz
  20.   Bit depth : 16 bits
  21.   Stream size : 2.39 MiB (100%)
  22.  
  23.   Programme écrit par Silicium628
  24.   ce logiciel est libre et open source
  25. */
  26. /*
  27. ***** RAPPEL**** (source: https://helpx.adobe.com/fr/audition/using/digitizing-audio.html) **
  28. Taux d’échantillonnage Niveau de qualité Plage de fréquences
  29.  
  30. 11,025 Hz Faible qualité radio AM (multimédia bas de gamme) 0- 5 512 Hz
  31. 22,050 Hz Comparable à la qualité radio FM (multimédia haut de gamme) 0-11 025 Hz
  32. 32 000 Hz Meilleur que la qualité radio FM (taux de diffusion standard) 0-16 000 Hz
  33. 44 100 Hz CD 0-22 050 Hz
  34. 48 000 Hz DVD standard 0-24 000 Hz
  35. 96 000 Hz DVD Blu-ray 0-48 000 Hz
  36. *********************************************************************************************/
  37. /*
  38. Le présent logiciel est paramétré pour traiter les fichiers audio ECHANTILLONES à 48000Hz (qualité DVD)
  39. ET PAS 44.1 !!
  40. Je le rendrai compatible avec les autres taux, mais pour l'instant il faut enregistrer
  41. au préalable l'audio à traiter avec un taux de 48kHz
  42. (par exemple avec Audacity, c'est facile voir en bas à gauche de sa fenêtre).
  43. */
  44.  
  45.  
  46. #include "mainwindow.h"
  47. #include "ui_mainwindow.h"
  48. #include "math.h"
  49. #include "complexe.cpp"
  50.  
  51. #include <QMessageBox>
  52. #include <QFileDialog>
  53. #include <QFile>
  54. //#include <QImage>
  55.  
  56. #include <QtMultimedia/QMediaPlayer>
  57. #include <QAudioOutput>
  58.  
  59. #include <QMouseEvent>
  60. #include <QDate>
  61. #include <QDateTime>
  62. #include <QScrollBar>
  63.  
  64. /* FFT_wav */
  65. //=============================================================================================
  66. // nouvelle numérotation par (date de compilation + 1 lettre si plusieurs compils le même jour)
  67. // toute version antérieure à la plus récente doit être jetée dans la poubelle jaune.
  68. QString version = "2025-03-21 a";
  69. //=============================================================================================
  70.  
  71. int write_mode =0;
  72.  
  73. QString couleur_ecran = "#141414";
  74. QString couleur_ligne = "#878787";
  75. QString couleur_trace1 = "#0EA004";
  76. QString couleur_trace2 = "#00FFFF";
  77. QString couleur_curseur = "#FFFF00";
  78. QString couleur_texte = "#FFFF00"; // JAUNE
  79. QString couleur_encadrement = "#FF0000"; // ROUGE
  80.  
  81. QPen pen_ligne(QColor(couleur_ligne), 1, Qt::SolidLine);
  82. QPen pen_trace1(QColor(couleur_trace1), 1, Qt::SolidLine);
  83. QPen pen_trace2(QColor(couleur_trace2), 1, Qt::SolidLine);
  84. QPen pen_curseur(QColor(couleur_curseur), 1, Qt::SolidLine);
  85. QPen pen_reticule(QColor(couleur_ligne), 1, Qt::SolidLine);
  86. QPen pen_encadrement(QColor(couleur_encadrement), 1, Qt::SolidLine);
  87.  
  88. char temp_entete[100]; // signal entete lu dans le fichier .wav
  89. char temp_data[2000000]; // signal audio lu dans le fichier .wav (max 2MB)
  90. int pas_echantillonage = 24;
  91.  
  92. Complexe ech[2048]; // nb_ech echantillons
  93. Complexe tab_X[2048]; // nb_ech valeurs traitées
  94. Complexe tab_W[2048];
  95. bool tableau_w_plein = false;
  96.  
  97. uint8_t table_FREQ_midi[2000][1]; // [t][num_raie]
  98. double table_integration_amplitudes[83];// [code midi]
  99.  
  100. uint16_t table_histogramme_durees[35]; // [valeur_duree] = nb d'occurences
  101. uint16_t table_histogramme_midi[42]; // [num_midi] = nb d'occurences
  102. uint16_t table_histogramme_degre[12]; //[n°degre = 1..12] = nb d'occurences
  103.  
  104. double facteur_compression=1.0;
  105.  
  106. //double frequence1=400; // Hz
  107. //double frequence2=400; // Hz
  108. //double frequence3=100; // Hz
  109.  
  110. uint nb_etapes=10; // 10
  111. uint nb_ech = pow (2, nb_etapes); // nombre d'échantillons = 2 puissance(nb_etapes) ->2^10 = 1024
  112.  
  113. double table_modules_FFT[1024]; // = 2^10
  114.  
  115. double x_clic_ecran, y_clic_ecran;
  116.  
  117. int nb_tics;
  118. int nb_tics2=0;
  119. int d_barre2=1;
  120. int num_barre_en_cours=0; // permet de tracer l'avancement de l'exécution des notes du morceau
  121. long T_i=0; // variable GLOBALE
  122. int n_player=1;
  123. double seuil;
  124. double gain =1.0;
  125. int num_note_depart;
  126. int num_note_cliquee=0;
  127. int num_note_jouee=0;
  128. int nb_acc=0;
  129. int num_note_max=0;
  130. double memo_scroll_x=0;
  131. QDateTime temps_0; // départ du jeu des notes
  132. bool hamming = true;
  133. bool bourrage_de_zeros = true;
  134. bool second_Frq = false;
  135. bool bz = true;
  136. bool modul = false;
  137.  
  138. // type de mesure noté Ta/Tb (4/4, 3/2 ...)
  139. int8_t Ta = 4;
  140. int8_t Tb = 4;
  141.  
  142.  
  143. //QList<int> index_midi; // position x des notes midi sur le graphe FFT (à partir de midi=40)
  144. QList<QString> liste_couleurs;
  145. QList<ENR_FFT> liste_ENR_FFT; // liste de "notes" détectées (maximums de FFT)
  146. QList<NOTE> liste_NOTES;
  147. //QList<QString> noms_notes;
  148. QList<QString> gamme_chromatique;
  149. QList<QString> gamme_chromatique_GB;
  150.  
  151.  
  152. QFile file_wav; // fichier à analyser
  153. QFile file_dat; // datas du TAB_FRQ
  154.  
  155. QDir currentDir;
  156. QString base_Dir;
  157. QString default_Dir = "/home/";
  158. QString string_currentDir = default_Dir; // à priori; sera mis à jour lors de la lecture du fichier 'params.ini'
  159. QString string_currentFile;
  160. QString nom_fichier_in="";
  161.  
  162. QDataStream binStream1;
  163.  
  164. double duree_totale; // calculée dans la fonction 'decode_entete'
  165. double data_size; // calculée dans la fonction 'decode_entete'
  166.  
  167. bool wav_ok = false;
  168. bool dossier_de_travail_ok = false;
  169. bool data_nts_ok = false;
  170. bool rapide = false;
  171. bool etendre = true;
  172.  
  173. //bool visu_T = true;
  174. //bool visu_notesM = false;
  175. //bool visu_M; // echelle temporelle sous forme de mesures (temps forts, temps faibles)
  176. //bool visu_T; // echelle temporelle simple en 1/40s
  177.  
  178. char mode = 'T'; // T ou M
  179.  
  180. bool visu_freq = true;
  181. bool visu_ech_tps;
  182. bool mode_select = false;
  183.  
  184. bool visu_duree_notes = true;
  185. bool visu_notes = true;
  186. bool visu_notes_auto = true;
  187. bool lecture_en_cours = false;
  188.  
  189. uint32_t offset_t;
  190. double zoom_x =1.0;
  191.  
  192.  
  193. MainWindow::MainWindow(QWidget *parent) :
  194. QMainWindow(parent)
  195. {
  196. setupUi(this);
  197. setWindowTitle("Transformée de Fourier Rapide FFT - version " + version);
  198.  
  199. //this->setGeometry(0,0, 1900, 1000);
  200. setWindowState(Qt::WindowMaximized);
  201. tabWidget_Global->setGeometry(0,0, 1920, 1280);
  202. tabWidget_Global->setCurrentIndex(0);
  203.  
  204. //-----------------------------------------------------
  205. // SCENE 1 - celle du haut ('Transformée de Fourier' ET 'partie échantillonée du signal')
  206.  
  207. scene1 = new QGraphicsScene(this);
  208. scene1->setBackgroundBrush(QColor(couleur_ecran));
  209. graphicsView1->setScene(scene1);
  210. graphicsView1->setGeometry(0, 0, 1900, 655); //( 0, 0, 1900, 700)
  211. graphicsView1->verticalScrollBar()->setValue(0);
  212.  
  213. calque_lignes_F_zero = new QGraphicsItemGroup();
  214. scene1->addItem(calque_lignes_F_zero);
  215.  
  216. calque_reticule1 = new QGraphicsItemGroup();
  217. scene1->addItem(calque_reticule1);
  218. afficher_titre_calque("Transformée de Fourier", 0, 0, calque_reticule1);
  219.  
  220. calque_trace_FFT = new QGraphicsItemGroup();
  221. scene1->addItem(calque_trace_FFT);
  222.  
  223. calque_trace_signal1 = new QGraphicsItemGroup();
  224. scene1->addItem(calque_trace_signal1);
  225.  
  226. calque_curseur = new QGraphicsItemGroup();
  227. scene1->addItem(calque_curseur);
  228.  
  229.  
  230. //-----------------------------------------------------
  231. // SCENE 2 - celle du bas ('Fichier Audio .wav')
  232.  
  233. scene2 = new QGraphicsScene(this);
  234. QBrush QB1("#222222");
  235. scene2->setBackgroundBrush(QB1); // couleur_ecran
  236.  
  237. graphicsView2->setScene(scene2);
  238. graphicsView2->setGeometry(0, 660, 1900, 200); // (0, 660, 1900, 200)
  239.  
  240. calque_trace_signal2 = new QGraphicsItemGroup();
  241. scene2->addItem(calque_trace_signal2);
  242.  
  243.  
  244. calque_reticule2 = new QGraphicsItemGroup();
  245. scene2->addItem(calque_reticule2);
  246. afficher_titre_calque("Fichier Audio .wav", 0, -80, calque_reticule2);
  247.  
  248. calque_encadrement1 = new QGraphicsItemGroup();
  249. scene2->addItem(calque_encadrement1);
  250.  
  251. calque_encadrement2 = new QGraphicsItemGroup();
  252. scene2->addItem(calque_encadrement2);
  253.  
  254. //-----------------------------------------------------
  255. // SCENE 3 - LISTE verticale NOTES sur l'onglet NOTES
  256. scene3 = new QGraphicsScene(this);
  257. scene3->setBackgroundBrush(QColor(couleur_ecran));
  258. graphicsView3->setScene(scene3);
  259.  
  260. calque_gradu_TAB_FRQ = new QGraphicsItemGroup();
  261. scene3->addItem(calque_gradu_TAB_FRQ);
  262.  
  263. //-----------------------------------------------------
  264. // SCENE 4 - ANALYSE sur l'onglet NOTES
  265.  
  266. scene4 = new QGraphicsScene(this);
  267. scene4->setBackgroundBrush(QColor(couleur_ecran));
  268. graphicsView4->setScene(scene4);
  269.  
  270. calque_grille_M = new QGraphicsItemGroup();
  271. scene4->addItem(calque_grille_M);
  272.  
  273. calque_grille_T = new QGraphicsItemGroup();
  274. scene4->addItem(calque_grille_T);
  275.  
  276. calque_TAB_FRQ = new QGraphicsItemGroup();
  277. scene4->addItem(calque_TAB_FRQ);
  278. afficher_titre_calque("Table Fréquences & notes", 200, 0, calque_TAB_FRQ);
  279.  
  280. calque_notes_manuelles = new QGraphicsItemGroup();
  281. scene4->addItem(calque_notes_manuelles);
  282.  
  283. calque_notes_auto = new QGraphicsItemGroup();
  284. scene4->addItem(calque_notes_auto);
  285.  
  286. calque_notes_jouee = new QGraphicsItemGroup();
  287. scene4->addItem(calque_notes_jouee);
  288.  
  289. calque_echelle_temporelle = new QGraphicsItemGroup();
  290. scene4->addItem(calque_echelle_temporelle);
  291.  
  292. //-----------------------------------------------------
  293. // SCENE 5 - Histogramme sur l'onglet NOTES
  294.  
  295. scene5 = new QGraphicsScene(this);
  296. scene5->setBackgroundBrush(QColor(couleur_ecran));
  297. graphicsView5->setScene(scene5);
  298. calque_histogramme = new QGraphicsItemGroup();
  299. scene5->addItem(calque_histogramme);
  300. //-----------------------------------------------------
  301.  
  302. Timer1 = new QTimer(this);
  303. connect(Timer1, SIGNAL(timeout()), this, SLOT(Tic1()));
  304.  
  305. Timer2 = new QTimer(this);
  306. connect(Timer2, SIGNAL(timeout()), this, SLOT(Tic2()));
  307.  
  308.  
  309. //noms_notes<<"La"<<"Si"<<"Do"<<"Ré"<<"Mi" <<"Fa"<<"Sol"<<"--"<<"--"; // <- A B C D E F G
  310. gamme_chromatique<<"Do"<<"Do#"<<"Ré"<<"Ré#"<<"Mi"<<"Fa"<<"Fa#"<<"Sol"<<"Sol#"<<"La"<<"La#"<<"Si";
  311.  
  312. //la gamme GB commence en principe par la lettre A (=La) mais pour simplifier ce programme
  313. //on la fait partir de C (=Do) comme la gamme FR...
  314. gamme_chromatique_GB<<"C"<<"C#"<<"D"<<"Eb"<<"E"<<"F"<<"F#"<<"G"<<"G#"<<"A"<<"A#"<<"B";
  315.  
  316. // dans la liste suivante, la première couleur (#0)->"#EF2929" est le rouge pour la note DO
  317. liste_couleurs <<"#EF2929"<<"#FF5C00"<<"#FCAF3E"<<"#FFE300"<<"#BFFF00"<<"#07F64F"
  318. <<"#16D298"<<"#16D2C4"<<"#00AEFF"<<"#1667D2"<<"#7C00FF"<<"#FF67EF"<<"#EEEEEC";
  319.  
  320. player1 = new QMediaPlayer;
  321. audioOutput1 = new QAudioOutput(this);
  322. player1->setAudioOutput(audioOutput1);
  323.  
  324. player2 = new QMediaPlayer;
  325. audioOutput2 = new QAudioOutput(this);
  326. player2->setAudioOutput(audioOutput2);
  327.  
  328. player3 = new QMediaPlayer;
  329. audioOutput3 = new QAudioOutput(this);
  330. player3->setAudioOutput(audioOutput3);
  331.  
  332. player4 = new QMediaPlayer;
  333. audioOutput4 = new QAudioOutput(this);
  334. player4->setAudioOutput(audioOutput4);
  335.  
  336. parametrages();
  337.  
  338. if(0)
  339. {
  340. //pour la phase de developpement
  341. afficher_titre_calque("Scene1", 100, 200, calque_trace_FFT);
  342. afficher_titre_calque("Scene2", 20, 20, calque_trace_signal2);
  343. afficher_titre_calque("Scene3", 10, 10, calque_gradu_TAB_FRQ);
  344. afficher_titre_calque("Scene4", 100, 100, calque_grille_T);
  345. afficher_titre_calque("Scene5", 20, 20, calque_histogramme);
  346. }
  347. }
  348.  
  349.  
  350. void MainWindow::parametrages()
  351. {
  352. load_fichier_ini();
  353.  
  354. calcul_tableau_W();
  355. tracer_graduations_signal();
  356. tracer_graduations_FFT();
  357.  
  358. init_TW_1();
  359. init_TAB_FRQ();
  360. init_TAB_lst_notes();
  361. init_TW_type_M();
  362. init_Autres();
  363.  
  364. seuil = doubleSpinBox_seuil->value();
  365.  
  366. spinBox_offset->setValue(-2124); // 2124; +/- 22 pour un décalage de +/-1/4 de ton
  367. spinBox_echx->setValue(499);
  368. write_mode=0;
  369. on_Bt_mode_R_clicked();
  370.  
  371. visu_notes_auto = false;
  372. on_Bt_toggle_visu_notes_auto_clicked();
  373.  
  374. visu_notes = false;
  375. on_Bt_toggle_visu_notes_clicked();
  376.  
  377. on_tableWidget_type_M_cellClicked(2, 0);
  378.  
  379. spinBox_zoom_2->setValue(2);
  380. // Bt_jouer_tout->setStyleSheet("background-color: rgb(200, 200, 200);");
  381.  
  382. progressBar_1->setValue(0);
  383.  
  384. effacer_calque(scene1,calque_trace_FFT );
  385.  
  386. effacer_calque(scene1,calque_lignes_F_zero );
  387. effacer_calque(scene1,calque_encadrement1 );
  388. effacer_calque(scene1,calque_trace_signal1 );
  389. effacer_calque(scene1,calque_trace_FFT );
  390. effacer_calque(scene1,calque_curseur );
  391.  
  392. effacer_calque(scene2,calque_encadrement2 );
  393. effacer_calque(scene2, calque_trace_signal2 );
  394.  
  395. effacer_calque(scene4,calque_TAB_FRQ );
  396. effacer_calque(scene4, calque_notes_manuelles );
  397. effacer_calque(scene4, calque_notes_auto );
  398. effacer_calque(scene4, calque_notes_jouee );
  399. effacer_calque(scene4, calque_echelle_temporelle);
  400.  
  401. for(int i=0; i<35; i++) { table_histogramme_durees[i]=0; }
  402. effacer_calque(scene5, calque_histogramme );
  403.  
  404. on_Bt_RAZ_clicked();
  405.  
  406. T_i=0; // T_i : variable GLOBALE
  407.  
  408. mode='M';
  409. on_Bt_toggle_grille_T_clicked();
  410. mode_grille_T();
  411. spinBox_nb_barres->setValue(40);
  412. effacer_calque(scene4, calque_grille_T);
  413. tracer_grille_T();
  414.  
  415.  
  416. }
  417.  
  418.  
  419. void MainWindow::init_TAB_FRQ()
  420. {
  421. frame_notes->setGeometry(0,0,1920,720);
  422.  
  423. graphicsView3->setGeometry(0, 30, 100, 730);
  424.  
  425. graphicsView4->setGeometry(100, 30, 2000, 730);
  426. graphicsView4->setEnabled(false); // empêche le recadrage auto par le contenu, mais disable le scroll manuel !
  427.  
  428. rectangle1 = new QGraphicsRectItem(0, 0, 2000, 670);
  429.  
  430. rectangle1->setPen(QColor(couleur_ligne));
  431. calque_TAB_FRQ->addToGroup(rectangle1);
  432. tracer_graduation_TAB_NOTES();
  433. tracer_grille_M();
  434. }
  435.  
  436.  
  437. void MainWindow::init_TAB_lst_notes()
  438. {
  439. tableWidget_lst_notes->setGeometry(1000, 30, 320, 201);
  440. QStringList liste_entetes1;
  441. liste_entetes1<<"num"<<"midi"<<"note"<<"n° barT"<< "n° barM)";
  442. tableWidget_lst_notes->setHorizontalHeaderLabels (liste_entetes1);
  443. tableWidget_lst_notes->setEditTriggers(QAbstractItemView::NoEditTriggers);
  444. }
  445.  
  446.  
  447.  
  448. void MainWindow::init_Autres()
  449. {
  450. // frame_1->setGeometry(1250, 865, 410, 131);
  451. // frame_1->setVisible(true);
  452. frame_2->setGeometry(10, 865, 970, 75);
  453. frame_3->setGeometry(1000, 865, 665, 121);
  454. frame_5->setGeometry(0, 760, 1920, 260);
  455. frame_6->setGeometry(10, 950, 901, 40);
  456.  
  457. graphicsView5->setGeometry(1460, 15, 440, 235); //225 histogrammes
  458. graphicsView5->setScene(scene5);
  459.  
  460. Bt_efface->setGeometry(915, 950, 60, 21);
  461. Bt_efface_2->setGeometry(1165, 0, 81, 26);
  462. pushButton_9->setGeometry(1290, 10, 31, 20);
  463. Bt_open_DIR_2->setGeometry(912, 40, 70, 26);
  464.  
  465. frame_8->setGeometry(1500, 740, 400, 30); // boutons "debut , < , > , fin"
  466. frame_9->setGeometry(1360, 789, 100, 70);
  467.  
  468. Bt_save_notes->setGeometry(831, 5, 151, 31);
  469. Bt_RAZ_general->setGeometry(1700, 900, 150, 50);
  470.  
  471. lineEdit_fichier_FREQ->setGeometry(1250, 0, 700, 22);
  472. progressBar_1->setGeometry(98, 4, 101, 18); //(1085, 3, 78, 18);
  473. lineEdit_fichier->setGeometry(380, 40, 530, 26);
  474. groupBox_2->setGeometry(380, 70, 241, 161);
  475. groupBox_3->setGeometry(630, 70, 351, 161);
  476.  
  477.  
  478. tracer_gradu_temporelle_signal_entree();
  479. tracer_graduations_signal();
  480. }
  481.  
  482.  
  483. void MainWindow::init_TW_type_M()
  484. {
  485. frame_4->setGeometry(210, 5, 140, 90);
  486. frame_7->setGeometry(210, 100, 140, 50);
  487.  
  488. tableWidget_type_M->setGeometry(5, 20, 40, 62);
  489. lineEdit_10->setGeometry(55, 30, 51, 26);
  490. lineEdit_11->setGeometry(55, 60, 51, 26);
  491. label_8->setGeometry(2, 2, 111, 20);
  492. label_39->setGeometry(108, 63, 40, 20);
  493.  
  494. //spinBox_barre_zero->setGeometry(5, 110, 61, 21);
  495. //spinBox_nb_barres->setGeometry(5, 130, 61, 21);
  496.  
  497.  
  498. QStringList liste_labels; // pour mettre directement dans la 1ere colonne (et pas en entêtes)
  499. liste_labels << "2/4" << "3/4" << "4/4";
  500. for(int n=0; n<3; n++) { tableWidget_type_M->setItem(0, n, new QTableWidgetItem (liste_labels[n])); }
  501. }
  502.  
  503.  
  504. void MainWindow::init_TW_1() // affi entete du fichier wav
  505. {
  506. tableWidget_1->setGeometry(700, 200, 600, 300);
  507. Bt_close_entete->setGeometry(1280, 200, 20, 20);
  508. tableWidget_1->setColumnCount(6);
  509. tableWidget_1->setColumnWidth(4, 120);
  510. tableWidget_1->setColumnWidth(5, 130);
  511.  
  512. tableWidget_1->setVisible(false);
  513. Bt_close_entete->setVisible(false);
  514.  
  515. QStringList liste_entetes;
  516. liste_entetes <<"FileTypeBlocID"
  517. <<"FileSize"
  518. <<"FileFormatID"
  519. <<"FormatBlocID"
  520. <<"BlocSize"
  521. <<"AudioFormat"
  522. <<"NbrCanaux"
  523. <<"Frequence"
  524. <<"ECH (BytePerSec)"
  525. <<"BytePerBloc"
  526. <<"BitsPerSample"
  527. <<"DataBlocID"
  528. <<"DataSize"
  529. <<"durée calculée";
  530.  
  531. tableWidget_1->setVerticalHeaderLabels(liste_entetes);
  532. }
  533.  
  534.  
  535. void MainWindow::load_fichier_ini()
  536. {
  537. QString line;
  538. int p1, p2, p3;
  539.  
  540. dossier_de_travail_ok = false; // à priori
  541. QFile file1(QDir::currentPath() + "/" + "params_FFT.ini"); // dans le dossier de l'exécutable (= QDir::currentPath() )
  542. if (file1.open(QIODevice::ReadOnly | QIODevice::Text))
  543. {
  544. QTextStream in(&file1);
  545. in.reset();
  546. while ( !in.atEnd() )
  547. {
  548. line = in.readLine();
  549. if (line.at(0) !='#')
  550. {
  551. if ((p1 = line.indexOf("<currentDir>")) != -1)
  552. {
  553. p2 = line.indexOf('>',p1);
  554. p3 = line.indexOf("</",p2);
  555. QString s1 = line.mid(p2+1, p3-p2-1);
  556. string_currentDir = s1;
  557. dossier_de_travail_ok = true;
  558. }
  559.  
  560. if ((p1 = line.indexOf("<currentFile>")) != -1)
  561. {
  562. p2 = line.indexOf('>',p1);
  563. p3 = line.indexOf("</",p2);
  564. QString s1 = line.mid(p2+1, p3-p2-1);
  565. string_currentFile = s1;
  566. }
  567. }
  568. }
  569. file1.close();
  570. }
  571. else
  572. {
  573. QString s1 = "fichier .ini non trouvé, je le crée (dans le dossier de l'executable)";
  574. QMessageBox msgBox; msgBox.setText(s1); msgBox.exec();
  575. base_Dir=QDir::currentPath() + "/";
  576. save_fichier_ini();
  577. dossier_de_travail_ok = false;
  578. }
  579. lineEdit_current_dir->setText(string_currentDir);
  580. lineEdit_fichier->setText(string_currentDir);
  581. }
  582.  
  583.  
  584.  
  585. QString calcul_couleur(double x) // x = 0.0 à 1.0 ; return: rouge->jaune->vert
  586. {
  587. QString coul_str ="#000000";
  588. QString coul_R_str="#000000";
  589. QString coul_V_str="#000000";
  590. int R, V; // rouge, vert
  591.  
  592. V= x * 255;
  593. R= 300 - (1.2 * V);
  594.  
  595. double coxh;
  596. // la formule suivante met le jaune en valeur (avec un cosinus hyperbolique)
  597. coxh = 3.2 - 1.5 * cosh(2.6*x - 1.5); // merci kmplot (testez la courbe f(x) = 3.2 −1.5 * cosh(2.6x − 1.5) )
  598.  
  599. R *= coxh/1.2;
  600. V *= coxh/1.2;
  601.  
  602. coul_R_str.setNum(R, 16); coul_R_str = "0" + coul_R_str; coul_R_str = coul_R_str.right(2);
  603. coul_V_str.setNum(V, 16); coul_V_str = "0" + coul_V_str; coul_V_str = coul_V_str.right(2);
  604. coul_str = coul_R_str + coul_V_str;
  605. coul_str = "#" + coul_str + "00";
  606. return coul_str; // de la forme "#AABB00" (rouge & vert en exa, (bleu à zéro, à traiter))
  607. }
  608.  
  609.  
  610.  
  611. int MainWindow::calcul_y_note(int midi) // en pixels sur la grille
  612. {
  613. int y =700 - ((midi-40) * 16); // voir 'tracer_graduation_TAB_NOTES()' pour l'espacement vertical
  614. return y;
  615. }
  616.  
  617.  
  618.  
  619. int MainWindow::calcul_hauteur_note(int mid) //'hauteur' au sens musical, gamme chromatique de 0 à 11
  620. {
  621. int h1 = mid;
  622.  
  623. while(h1>=12) {h1-=12;}
  624. while(h1<0) {h1+=12;}
  625. if (h1==12) {h1=0;}
  626. if ((h1<0) || (h1>(liste_couleurs.length()-1))) {h1 = 0;}
  627.  
  628. return h1; // h1 = 0..11
  629. }
  630.  
  631.  
  632.  
  633. QString MainWindow::nom_note(int mid)
  634. {
  635. QString s1;
  636.  
  637. int h1 = calcul_hauteur_note(mid);
  638. s1 = gamme_chromatique[h1];
  639. return s1;
  640. }
  641.  
  642.  
  643. QString MainWindow::nom_note_GB(int mid)
  644. {
  645. QString s1;
  646.  
  647. int h1 = calcul_hauteur_note(mid);
  648. s1 = gamme_chromatique_GB[h1];
  649. return s1;
  650. }
  651.  
  652.  
  653. QString MainWindow::nom_octave_GB(int mid)
  654. {
  655. QString octave;
  656. if((mid>=40)&&(mid < 48)) {octave = "2";}
  657. if((mid>=48)&&(mid < 60)) {octave = "3";}
  658. if((mid>=60)&&(mid < 72)) {octave = "4";}
  659. if((mid>=72)&&(mid < 90)) {octave = "5";}
  660. return octave;
  661. }
  662.  
  663.  
  664.  
  665. double freq_mid(int midi_i) // calcule la fréquence (en Hertz) d'une note à partir de son numéro midi
  666. {
  667. // https://fr.wikipedia.org/wiki/MIDI_Tuning_Standard
  668. double F, A;
  669. A=((double)midi_i-69.0)/12.0;
  670. F= 440 * powf(2,A);
  671. return F;
  672. }
  673.  
  674.  
  675. double calcul_id_midi(double freq_i) // complément de la fonction précédente ( double freq_mid(int midi_i) )
  676. {
  677. double id;
  678. id = 69.0 + 12.0 * log2(freq_i / 440.0);
  679. return id;
  680. }
  681.  
  682.  
  683. int MainWindow::calcul_num_midi(double x) // en fonction de la position horizontale dans le tableau d'affichage de la FFT
  684. {
  685. // on va détecter la note la plus proche de la position donnée
  686. // rappel : x=92 +(m-40) * 40.9 (voir la fonction : 'tracer_graduations_FFT()')
  687.  
  688. double dx;
  689. double xm;
  690.  
  691. for (int m=40; m<83; m++)
  692. {
  693. xm= 92.0 +(m-40) * 40.9;
  694. dx = xm-x;
  695. if (dx<0){dx=-dx;}
  696. if (dx < (40.9/2) )
  697. {
  698. encadrement_note(m);
  699. return m;
  700. }
  701. }
  702. return 0;
  703. }
  704.  
  705.  
  706. void MainWindow::play_note(int midi) // sortie audio
  707. {
  708. QString s1, freq_txt;
  709.  
  710. calcul_hauteur_note(midi);
  711. s1.setNum(midi);
  712.  
  713. s1="notes/"+s1+".wav"; // fichiers audio comprenant une seule note chacun, voir dans le dossier "notes" sur le HDD
  714.  
  715. if (n_player == 1) {player1->setSource(QUrl::fromLocalFile(s1)); player1->play();}
  716. if (n_player == 2) {player2->setSource(QUrl::fromLocalFile(s1)); player2->play();}
  717. if (n_player == 3) {player3->setSource(QUrl::fromLocalFile(s1)); player3->play();}
  718. if (n_player == 4) {player4->setSource(QUrl::fromLocalFile(s1)); player4->play();}
  719. if (n_player == 5) {player5->setSource(QUrl::fromLocalFile(s1)); player5->play();}
  720. n_player++;
  721. if (n_player >= 5) {n_player = 1;}
  722. }
  723.  
  724.  
  725.  
  726.  
  727. void MainWindow::effacer_calque(QGraphicsScene *scene_i, QGraphicsItemGroup *calque_i)
  728. {
  729. foreach( QGraphicsItem *item, scene_i->items( calque_i->boundingRect() ) )
  730. {if( item->group() == calque_i ) { delete item; }}
  731. }
  732.  
  733.  
  734. MainWindow::~MainWindow()
  735. {
  736.  
  737. }
  738.  
  739.  
  740.  
  741. void MainWindow::Etiquette(int x, int y, int dx, QString s, QString coul_txt, QString coul_fond, QString coul_bord, QGraphicsItemGroup *calque_i )
  742. {
  743. // si dx = 0 -> la largeur sera fonction du nb de caractères
  744.  
  745. if (dx==0)
  746. {
  747. dx = 8 * (s.length()+1 );
  748. }
  749. rect1 = new QGraphicsRectItem(x, y+4, dx, 18);
  750. rect1->setPen(QColor(coul_bord)); // bordure
  751. rect1->setBrush(QColor(coul_fond)); // fond
  752. calque_i->addToGroup(rect1);
  753.  
  754. //texte
  755. GraphicsTextItem = new QGraphicsTextItem(s);
  756. GraphicsTextItem->setPos(x, y);
  757. GraphicsTextItem->setDefaultTextColor(coul_txt);
  758. calque_i->addToGroup(GraphicsTextItem);
  759. }
  760.  
  761.  
  762.  
  763. void MainWindow::tracer_graduations_FFT() // sur onglet 'Source wav'
  764. {
  765. double x=0;
  766. QString s1;
  767. int y_bas =450; // 350
  768.  
  769. // cadre
  770. rectangle1 = new QGraphicsRectItem(0, 0, 1900, y_bas);
  771. QPen pen1("#12FF00");
  772. rectangle1->setPen(pen1);
  773.  
  774. calque_reticule1->addToGroup(rectangle1);
  775.  
  776. s1 = "midi :"; // numéro midi
  777. GraphicsTextItem = new QGraphicsTextItem(s1);
  778. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  779. GraphicsTextItem->setPos(30, 20);
  780. // if(x<1900)
  781. {
  782. calque_reticule1->addToGroup(GraphicsTextItem);
  783. }
  784.  
  785. // positions des notes midi
  786. x= 96;
  787. for(int m=40; m<=83; m++)
  788. {
  789. ligne1 = new QGraphicsLineItem(x, 70, x, y_bas);
  790. ligne1->setPen(pen_reticule);
  791. calque_reticule1->addToGroup(ligne1);
  792.  
  793. s1.setNum(m); // numéro midi
  794. GraphicsTextItem = new QGraphicsTextItem(s1);
  795. GraphicsTextItem->setDefaultTextColor("#D3D7CF");
  796. GraphicsTextItem->setPos(x-15, 20);
  797. if(x<1900) {calque_reticule1->addToGroup(GraphicsTextItem); }
  798.  
  799. int h1 = calcul_hauteur_note(m);
  800.  
  801. s1 = " " + gamme_chromatique[h1]; // nom de la note
  802. GraphicsTextItem = new QGraphicsTextItem(s1);
  803. GraphicsTextItem->setDefaultTextColor(liste_couleurs[h1]);
  804. GraphicsTextItem->setPos(x-18, 40);
  805. if(x<1900) {calque_reticule1->addToGroup(GraphicsTextItem); }
  806.  
  807. x+=40.9; // espacement des graduation
  808. }
  809. }
  810.  
  811.  
  812. // voir fonction "void MainWindow::tracer_echelle_temps_TAB_NOTES()"
  813. // dx = 1000.0 * pas_echantillonage/256.0; // = 1000 * 24 /256 = 93.75
  814.  
  815.  
  816. double MainWindow:: calcul_pas_grille()
  817. {
  818. double pas = 0;
  819. if (mode == 'T')
  820. {
  821. pas = 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x; // 1 barre toutes les 1/40 seconde
  822. }
  823. if (mode == 'M')
  824. {
  825. pas = (spinBox_dxa->value()+doubleSpinBox_dxb->value()) * 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x;
  826. }
  827.  
  828. return pas;
  829. }
  830.  
  831. /*
  832. double MainWindow::calcul_pas_grille_M()
  833. {
  834.   double pas_grille_M = (spinBox_dxa->value()+doubleSpinBox_dxb->value()) * 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x;
  835.   return pas_grille_M;
  836. }
  837. */
  838.  
  839. int MainWindow::calcul_tempo()
  840. {
  841. double dbar = spinBox_dxa->value()+doubleSpinBox_dxb->value(); // nb de barres de 1/40s séparant 2 barres de mesure
  842. double dt = (1.0/40.0) * dbar; // en s
  843. double nb_bpmn = 60.0 / dt; // nb de barres / mn
  844. double Tp = nb_bpmn / 2.0;
  845. return int(Tp);
  846. }
  847.  
  848.  
  849.  
  850. double MainWindow::calcul_x_barre(int n_barre)
  851. {
  852. // calcul de l'abscisse (en pixel) d'une barre de mesure
  853. double x =0;
  854. double x0;
  855.  
  856. int x0a = spinBox_x0a->value();
  857. double x0b = 80.0 + 10.0 * doubleSpinBox_x0b->value();
  858. x0b += 20.0 * x0a;
  859.  
  860. if (mode == 'T')
  861. {
  862. x0 = 80.0; // 100 à voir !
  863. x = x0 + double(n_barre) * calcul_pas_grille();
  864. }
  865. if (mode == 'M')
  866. {
  867. x = x0b + double(n_barre) * calcul_pas_grille();
  868. }
  869.  
  870. return x;
  871. }
  872.  
  873. /*
  874. double MainWindow::calcul_x_barre_M(int n_barre)
  875. {
  876.   double x = double(n_barre) * calcul_pas_grille_M();
  877.   return x;
  878. }
  879. */
  880.  
  881. void MainWindow::trace_1_barre_M(double x_i, QString couleur_i)
  882. {
  883. if(x_i<0) {return;} // pour ne pas décaler tout l'affichage
  884. QPen pen_i;
  885. pen_i.setColor(couleur_i);
  886. ligne1 = new QGraphicsLineItem(x_i, 0.0, x_i, 700.0);
  887. ligne1->setPen(pen_i);
  888. calque_grille_M->addToGroup(ligne1);
  889. }
  890.  
  891.  
  892. void MainWindow::tracer_grille_M()
  893. {
  894. effacer_calque(scene4, calque_echelle_temporelle);
  895. double x1;
  896. //int i;
  897. QString s1;
  898. // int nb = spinBox_nb_barres->value();
  899. // int n_zero = spinBox_barre_zero->value();
  900.  
  901. //int x0a = spinBox_x0a->value();
  902. //double x0b = 80.0 + 10.0 * doubleSpinBox_x0b->value();
  903. //x0b += 20.0 * x0a;
  904.  
  905. QString couleur1;
  906.  
  907. QString gris_clair = "#CCCCCC";
  908. QString gris_fonce = "#777777";
  909. QString gris_tres_fonce = "#444444";
  910. QString jaune = "#FFFF00";
  911. QString cyan = "#00FFFF";
  912.  
  913. int num_mesure=0;
  914. int usd=0; // une sur deux
  915. for(int n=-500; n<=500; n++)
  916. {
  917. // rappel : mesures type Ta/Tb
  918. // 3/4 -> Ta=3 & Tb=4
  919. // 4/4 -> Ta=4 & Tb=4
  920.  
  921. x1 = calcul_x_barre(n);
  922.  
  923. couleur1 = gris_clair; // à priori
  924. if (n%(2*Ta) == 0)
  925. {
  926. if(x1<0){num_mesure=-1;}
  927. num_mesure++;
  928. if(num_mesure>0)
  929. {
  930. couleur1 = cyan; usd =0;
  931.  
  932. s1.setNum(num_mesure);
  933. Etiquette(x1, 10, 0, s1, "#FFFFFF", "#000000", "#00FFFF", calque_echelle_temporelle );
  934. }
  935. }
  936. usd++;
  937. if ((usd %2)==0) { couleur1 = gris_fonce; }
  938. if(n==0){couleur1 = jaune;}
  939. trace_1_barre_M(x1, couleur1); // principale
  940. }
  941.  
  942. double Tempo = calcul_tempo();
  943. s1.setNum(Tempo);
  944. lineEdit_11->setText(s1);
  945.  
  946.  
  947.  
  948. // Etiquette(0, 0, 0, s1, "#FFFFFF", "#000000", "#FF00FF", calque_echelle_temporelle );
  949. // s1 = "BPM";
  950.  
  951.  
  952.  
  953. /*
  954.   GraphicsTextItem = new QGraphicsTextItem(s1);
  955.   GraphicsTextItem->setPos(45, 0);
  956.   GraphicsTextItem->setDefaultTextColor("#FF00FF");
  957.   calque_echelle_temporelle->addToGroup(GraphicsTextItem);
  958. */
  959.  
  960. }
  961.  
  962.  
  963. void MainWindow::tracer_grille_T()
  964. {
  965. //grille T sur l'onglet NOTES (barres verticales)
  966. QString s1;
  967. // QString bleu_clair = "#00AAFF";
  968. // QString jaune = "#FFFF00";
  969. QString gris_clair = "#CCCCCC";
  970. QString gris_fonce = "#777777";
  971. QString gris_tres_fonce = "#444444";
  972. QString couleur_i;
  973. QPen pen_i;
  974. double x_i1;
  975. int num_mesure;
  976. int nb = spinBox_nb_barres->value();
  977. int n_zero = spinBox_barre_zero->value();
  978.  
  979. for(int n=0; n<=120*16; n++)
  980. {
  981. if (Ta<2) {Ta=2;}
  982. x_i1 = calcul_x_barre(n);
  983.  
  984. couleur_i = gris_tres_fonce; // à priori
  985.  
  986. if (((n-n_zero)%nb) == 0) { couleur_i ="#00AAAA"; } //couleur_i = gris_fonce;
  987. /*
  988.   if ( n%(4*Ta) == 0) // 1er temps fort de la mmesure
  989.   {
  990. // numérotation des mesures, en bas, chiffres jaunes
  991.   num_mesure = n /Ta/4;
  992.   s1.setNum(num_mesure);
  993.   Etiquette(x_i1-0, 0, 650, s1, "#FFFF00", "#000000", "#0000FF", calque_grille_T);
  994.   }
  995. */
  996. //if ( n%(4*m)== 0) {couleur_i = jaune;}
  997.  
  998. pen_i.setColor(couleur_i);
  999. ligne1 = new QGraphicsLineItem(x_i1, 0.0, x_i1, 700.0); //100.0 pour test des 2 grilles ensemble
  1000. ligne1->setPen(pen_i);
  1001. calque_grille_T->addToGroup(ligne1);
  1002. }
  1003. }
  1004.  
  1005.  
  1006. void MainWindow::afficher_titre_calque(QString titre, int x, int y, QGraphicsItemGroup *calque_i)
  1007. {
  1008. GraphicsTextItem = new QGraphicsTextItem(titre);
  1009. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  1010. GraphicsTextItem->setPos(x, y);
  1011. calque_i->addToGroup(GraphicsTextItem);
  1012. }
  1013.  
  1014.  
  1015.  
  1016. void MainWindow::tracer_graduation_TAB_NOTES() // midi ; en colonne à gauche + noms des notes
  1017. {
  1018. // positions des notes midi
  1019. QString s1;
  1020. int y= 640; //640
  1021. for(int m=40; m<=82; m++)
  1022. {
  1023. //ligne1 = new QGraphicsLineItem(100, 0, 100, 350);
  1024. //ligne1->setPen(pen_reticule);
  1025. //calque_reticule1->addToGroup(ligne1);
  1026.  
  1027. s1.setNum(m); // numéro midi
  1028. GraphicsTextItem = new QGraphicsTextItem(s1);
  1029. GraphicsTextItem->setDefaultTextColor("#D3D7CF");
  1030. GraphicsTextItem->setPos(0, y);
  1031. if(y> -50) {calque_gradu_TAB_FRQ->addToGroup(GraphicsTextItem); }
  1032.  
  1033. int h1 = calcul_hauteur_note(m);
  1034. s1 = " " + gamme_chromatique[h1]; // nom de la note
  1035. GraphicsTextItem = new QGraphicsTextItem(s1);
  1036. GraphicsTextItem->setDefaultTextColor(liste_couleurs[h1]);
  1037. // GraphicsTextItem->setHtml("<div style='background-color:#666666;'>" + s1 + "</div>");
  1038.  
  1039. if (m==69) // La 440
  1040. {
  1041. rect3 = new QGraphicsRectItem(30, y+6, 40, 15);
  1042. QBrush br2;
  1043. QPen pen_i;
  1044. pen_i.setColor("#AAAAAA");
  1045. rect3->setPen(pen_i);
  1046. calque_gradu_TAB_FRQ->addToGroup(rect3);
  1047.  
  1048. }
  1049.  
  1050. GraphicsTextItem->setPos(30, y);
  1051. if(y > -50) {calque_gradu_TAB_FRQ->addToGroup(GraphicsTextItem); }
  1052.  
  1053. y-=16; // espacement des graduations
  1054. }
  1055. }
  1056.  
  1057.  
  1058.  
  1059. void MainWindow::tracer_graduations_signal() // sur le 1er onglet (Source.wav)
  1060. {
  1061. /*
  1062.   midi57 = 110Hz
  1063.   1/110Hz = 9ms -> delta x = 142-46 = 96px
  1064.   echelle x = 96/9 = 10.6 px/ms
  1065.   soit:
  1066.   10ms -> 106px
  1067. */
  1068. double x;
  1069. double nb_grad_max;
  1070. double intervalle; // séparant les graduations
  1071. QPen pen1;
  1072. // int num_x;
  1073. //QString sti;
  1074. // uint decal = 3; // leger decallage vertical pour ne pas masquer la trace
  1075.  
  1076. /*
  1077.   rectangle1 = new QGraphicsRectItem(5, 452, 1900, 200);
  1078.   pen1.setColor("#0073FF");
  1079.   rectangle1->setPen(pen1);
  1080.   calque_reticule1->addToGroup(rectangle1);
  1081.  
  1082.   ligne1 = new QGraphicsLineItem(10, 475, 1900, 475); // ligne horizontale
  1083.   pen1.setColor("#0073FF");
  1084.   ligne1->setPen(pen1);
  1085.   calque_reticule1->addToGroup(ligne1);
  1086. */
  1087. afficher_titre_calque("Partie échantillonée du signal", 0, 452, calque_reticule1);
  1088.  
  1089. // lignes verticales
  1090.  
  1091. intervalle = 106;
  1092. nb_grad_max = 18;
  1093.  
  1094. for (int i=0; i<=nb_grad_max; i++)
  1095. {
  1096. x = intervalle * i;
  1097.  
  1098. ligne1 = new QGraphicsLineItem(x, 452, x, 780);
  1099. ligne1->setPen(pen_reticule);
  1100. }
  1101.  
  1102. /*
  1103. // lignes horizontales
  1104.   intervalle = 55;
  1105.   nb_grad_max = 3;
  1106.   for (i=0; i<=nb_grad_max; i++)
  1107.   {
  1108.   y = 300 - intervalle * i;
  1109.  
  1110.   ligne1 = new QGraphicsLineItem(0, y, 1350, y);
  1111.   ligne1->setPen(pen_reticule);
  1112.   calque_reticule1->addToGroup(ligne1);
  1113.   }
  1114.   texte_mid = new QGraphicsTextItem("Silicium628");
  1115.   texte_mid->setDefaultTextColor(couleur_signature);
  1116.   texte_mid->setPos(5,5);
  1117.   calque_reticule1->addToGroup(texte_mid);
  1118.  */
  1119.  
  1120. scene1->addItem(calque_reticule1);
  1121. }
  1122.  
  1123.  
  1124.  
  1125. void MainWindow::tracer_gradu_temporelle_signal_entree()
  1126. {
  1127. // GRADUATION TEMPORELLE sur le signal d'entrée, en secondes; (scene2 sur onglet 'Source wav')
  1128.  
  1129. QString s1, s2;
  1130. int x=0;
  1131. int dy = 75;
  1132. int nb_s, nb_mn;
  1133. double pas =8;
  1134.  
  1135. for(int n=0; n<2400; n++) // 1200
  1136. {
  1137.  
  1138. if (n%10 == 0) { dy = 75; }
  1139. else if (n%5 == 0) {dy = 20; }
  1140. else {dy = 10;}
  1141.  
  1142. x = n *pas;
  1143. ligne1 = new QGraphicsLineItem(x, -dy, x, dy);
  1144. QPen P1("#AAAAAA");
  1145. ligne1->setPen(P1);
  1146. calque_reticule2->addToGroup(ligne1);
  1147.  
  1148. if (n%10 == 0)
  1149. {
  1150. nb_s = n/10;
  1151. s1.setNum(nb_s);
  1152. s1+="s";
  1153.  
  1154. if (nb_s>60)
  1155. {
  1156. nb_mn = nb_s/60;
  1157. nb_s -= nb_mn * 60;
  1158. s1.setNum(nb_s);
  1159. if (nb_s<10) {s1 = "0" +s1;}
  1160. s2.setNum(nb_mn);
  1161. s1 = s2 + ":" + s1;
  1162. }
  1163. GraphicsTextItem = new QGraphicsTextItem(s1);
  1164. GraphicsTextItem->setDefaultTextColor(couleur_texte);
  1165. GraphicsTextItem->setPos(x,55);
  1166. if(x<20000) {calque_reticule2->addToGroup(GraphicsTextItem); }//6000
  1167. }
  1168. }
  1169. }
  1170.  
  1171.  
  1172.  
  1173. void MainWindow::tracer_signal_complet() // totalité du fichier wav (dans le cadre du bas du 1er onglet)
  1174. {
  1175. uint8_t octet_n;
  1176. double R;
  1177.  
  1178. double offset_y = 0.0;
  1179. double echelle_y =doubleSpinBox_gain->value();
  1180. double echelle_x =0.2;
  1181.  
  1182. int x, y, memo_x, memo_y;
  1183. double min= 1000000.0;
  1184. double max=-1000000.0;
  1185.  
  1186. int pas = 10 * pas_echantillonage; // 240;
  1187.  
  1188. //rappel : duree_totale = data_size / 96000;
  1189.  
  1190. // le signal wav est échantillonné à l'origine à 96000 Bps (séréo 2*fois 48000 Bps)
  1191. // en ne prenant qu'un octet sur 24 on obtient 4000 Bps.
  1192. QString s1;
  1193.  
  1194. effacer_calque(scene2, calque_trace_signal2 );
  1195. segment_trace = new QGraphicsLineItem(0, offset_y, 512, offset_y);
  1196. QPen P1("#0000FF");
  1197. segment_trace->setPen(P1); //couleur_ligne
  1198. calque_trace_signal2->addToGroup(segment_trace);
  1199.  
  1200. x=0;
  1201. y=offset_y;
  1202.  
  1203. //qDebug() << "data_size" << data_size;
  1204. //qDebug() << "pas" << pas;
  1205.  
  1206. double n_max = data_size / pas;
  1207.  
  1208. long n;
  1209. long i=0;
  1210. // int j=0;
  1211.  
  1212. for(n=0; n<n_max; n+=10)
  1213. {
  1214. memo_x = x;
  1215. memo_y = y;
  1216. x = echelle_x * n;
  1217.  
  1218. octet_n = temp_data[i]; // canal 1
  1219. R = octet_n - 128; // pour ôter la composante continue propre au codage par des octets non signés
  1220. R *= echelle_y;
  1221. R *= doubleSpinBox_gain->value();
  1222. y=offset_y + R;
  1223.  
  1224. // recherche du mini-maxi:
  1225. if (y < min) {min = y;}
  1226. if (y > max) {max = y;}
  1227.  
  1228. //if (x<3000) //3000
  1229. {
  1230. segment_trace = new QGraphicsLineItem(memo_x ,memo_y, x, y);
  1231. QPen P1("#0055FF");
  1232. segment_trace->setPen(P1);
  1233. calque_trace_signal2->addToGroup(segment_trace);
  1234. }
  1235.  
  1236. i+= pas; // le nb de pas étant pair, on retombe toujours sur le même canal (droite ou gauche)
  1237. }
  1238. //scene1->addItem(calque_trace_signal);
  1239. s1.setNum(min);
  1240. //lineEdit_4->setText(s1);
  1241. s1.setNum(max);
  1242. // lineEdit_5->setText(s1);
  1243. }
  1244.  
  1245.  
  1246.  
  1247. void MainWindow::encadrement_signal(int x, int dx)
  1248. {
  1249. ligne1 = new QGraphicsLineItem(x, -80, x, 80);
  1250. ligne1->setPen(pen_encadrement);
  1251. calque_encadrement2->addToGroup(ligne1);
  1252.  
  1253. ligne1 = new QGraphicsLineItem(x+dx, -80, x+dx, 80);
  1254. ligne1->setPen(pen_encadrement);
  1255. calque_encadrement2->addToGroup(ligne1);
  1256.  
  1257. ligne1 = new QGraphicsLineItem(x, -80, x+dx, -80);
  1258. ligne1->setPen(pen_encadrement);
  1259. calque_encadrement2->addToGroup(ligne1);
  1260.  
  1261. ligne1 = new QGraphicsLineItem(x, 80, x+dx, 80);
  1262. ligne1->setPen(pen_encadrement);
  1263. calque_encadrement2->addToGroup(ligne1);
  1264. }
  1265.  
  1266.  
  1267.  
  1268. void MainWindow::encadrement_note(int n_midi) // par un rectangle
  1269. {
  1270. double x, dx, y, dy;
  1271.  
  1272. x=92 - 13 + ((double)n_midi-40.0) * 40.9;
  1273. dx=35;
  1274. y=16;
  1275. dy=50;
  1276.  
  1277. rectangle1 = new QGraphicsRectItem(x, y, dx, dy);
  1278. rectangle1->setPen(pen_encadrement);
  1279. calque_trace_FFT->addToGroup(rectangle1);
  1280. }
  1281.  
  1282.  
  1283.  
  1284. void MainWindow::tracer_signal_a_convertir() //partie à analyser s=f(t) (signal incident, pas le FFT); dans le cadre du haut
  1285. {
  1286. double offset_y = 575.0;
  1287. double echelle =5.0;
  1288. uint8_t octet_n;
  1289. double R;
  1290. double x, y, memo_x, memo_y;
  1291. double min= 1000000.0;
  1292. double max=-1000000.0;
  1293. QString s1;
  1294.  
  1295. effacer_calque(scene1,calque_trace_signal1 );
  1296. segment_trace = new QGraphicsLineItem(0, offset_y, 512, offset_y);
  1297. segment_trace->setPen(QColor(couleur_ligne));
  1298. calque_trace_signal1->addToGroup(segment_trace);
  1299.  
  1300. long n;
  1301. long i=0;
  1302. x=0;
  1303. y=offset_y;
  1304. int pas = 64;
  1305. for(n=0; n<nb_ech/2; n++)
  1306. {
  1307. memo_x = x;
  1308. memo_y = y;
  1309. x = echelle * n;
  1310.  
  1311. octet_n = temp_data[i]; // canal 1
  1312. R = octet_n - 128; // pour oter la composante continue propre au codage par des octets non signés
  1313. // R /= 10.0;
  1314. y=offset_y + R;
  1315.  
  1316. if (y < min) {min = y;}
  1317. if (y > max) {max = y;}
  1318.  
  1319. if (x<1800)
  1320. {
  1321. segment_trace = new QGraphicsLineItem(memo_x ,memo_y, x, y);
  1322. segment_trace->setPen(pen_trace1);
  1323. calque_trace_signal1->addToGroup(segment_trace);
  1324. }
  1325.  
  1326. i++; // pour sauter le canal B (le signal dans le fichier .wav est stéréo)
  1327. i+= pas;
  1328. }
  1329. //scene1->addItem(calque_trace_signal);
  1330. s1.setNum(min);
  1331. //lineEdit_4->setText(s1);
  1332. s1.setNum(max);
  1333. // lineEdit_5->setText(s1);
  1334. }
  1335.  
  1336.  
  1337.  
  1338.  
  1339. void MainWindow::tracer_segments_FFT() //scene1 sur le 1er onglet (Source wav)
  1340. {
  1341. double offset_x= spinBox_offset->value(); // ref -2146 ; +/- 22 pour un décalage de +/-1/4 de ton
  1342. double echelle_x =spinBox_echx->value(); // 498
  1343. double offset_y = 350.0;
  1344.  
  1345. uint n;
  1346. double module_FFT;
  1347. double x, y;
  1348. double memo_x[5]={0,0,0,0,0};
  1349. double memo_y[5]={0,0,0,0,0};
  1350. double x0, y0; // fréquence centrale trouvée comme résultat (points d'inflexions de la courbe)
  1351.  
  1352. double z=1.6;
  1353. //int x1=0;
  1354. //int x2=0;
  1355. int num_raie=0;
  1356. //bool note_validee = false;
  1357.  
  1358. QPen pen1("#12FF00");
  1359.  
  1360. if(!rapide)
  1361. {
  1362. effacer_calque(scene1,calque_trace_FFT );
  1363. effacer_calque(scene1,calque_lignes_F_zero );
  1364. }
  1365.  
  1366. x=0;
  1367. y = offset_y;
  1368. ENR_FFT enr_i;
  1369. for(n=0; n<nb_ech; n++)
  1370. {
  1371. //qDebug() << "n" << n;
  1372. //note_validee = false;
  1373. memo_x[0] = x;
  1374. memo_y[0] = y;
  1375. // x = offset_x + echelle_x * n; // echelle linéaire -> pas top
  1376. x = offset_x + echelle_x * log2((double)(n+1)); // échelle logarithmique afin que les tons soient équi-espacés
  1377.  
  1378. // ci-dessous 'a' est la partie réelle du complexe, et 'b' la partie imaginaire
  1379. // on calcule le module :
  1380. module_FFT = z * sqrt( tab_X[n].a * tab_X[n].a + tab_X[n].b * tab_X[n].b ); // z * racine(a²+b²)
  1381.  
  1382. y = module_FFT*10.0; // amplitude
  1383. y = offset_y - y; // offset et inversion du sens d'affichage because à l'écran les y croissent de haut en bas
  1384.  
  1385.  
  1386. // décale la pile memo_x
  1387. // puis mise en mémoire (empile) le dernier point
  1388. memo_x[4] = memo_x[3]; memo_y[4] = memo_y[3];
  1389. memo_x[3] = memo_x[2]; memo_y[3] = memo_y[2];
  1390. memo_x[2] = memo_x[1]; memo_y[2] = memo_y[1];
  1391. memo_x[1] = memo_x[0]; memo_y[1] = memo_y[0];
  1392. memo_x[0] = x;
  1393. memo_y[0] = y;
  1394.  
  1395. if((x>20) && (x<1900))
  1396. {
  1397. //y *=1.0;
  1398. if (x > -100)
  1399. {
  1400. if (!rapide)
  1401. {
  1402. segment_trace = new QGraphicsLineItem(memo_x[1] ,memo_y[1], x, y);
  1403. segment_trace->setPen(pen_trace2);
  1404. calque_trace_FFT->addToGroup(segment_trace);
  1405. }
  1406. }
  1407.  
  1408. // DETECTION DES NOTES primaires
  1409.  
  1410. //----------------------------------------------------------------------------------
  1411. // détection direct des points hauts (points d'inflexion de la courbe)
  1412. // on pourrait calculer la dérivée de la courbe, et détecter les valeurs pour lesquelles elle s'annule
  1413. // problème : peut ne pas détecter si le sommet est un pic (discontinuité)
  1414. //----------------------------------------------------------------------------------
  1415.  
  1416. // Autre méthode :
  1417. // détection de 2 doublets de points de part et d'autre, montants puis descendant
  1418. // le sommet se situe donc entre les 2 doublets
  1419.  
  1420. // la DETECTION s'effectue ICI
  1421.  
  1422. // ATTENTION : la ligne qui suit détermine la stratégie utilisée et son paramétrage influe grandement
  1423. // sur la qualité du résultat.
  1424. // on doit pouvoir l'améliorer mais attention : toujours expérimenter sur des données réelles (air de musique)
  1425. // avant de valider la moindre "améloration".
  1426.  
  1427. //if ( (memo_y[3] - memo_y[2]) >0.5 && (memo_y[1] - memo_y[2]) >0.5 )
  1428. if ( (memo_y[3] - memo_y[2]) > 1.1 && (memo_y[1] - memo_y[2]) > 1.1 )
  1429. {
  1430. x0 = memo_x[2]; // point d'inflexion probable
  1431. y0 = memo_y[2];
  1432.  
  1433. if( !rapide) // donc pas d'affichage en mode rapide
  1434. {
  1435. ligne1 = new QGraphicsLineItem(x0, 60, x0, 350);
  1436. ligne1->setPen(pen1); // BLEU
  1437. calque_lignes_F_zero->addToGroup(ligne1);
  1438. ligne1 = new QGraphicsLineItem(x0, T_i-1, x0, T_i+1); // T_i : variable GLOBALE
  1439. ligne1->setPen(pen1);
  1440. }
  1441.  
  1442. int m0 = 0;
  1443. m0 = calcul_num_midi(x0);
  1444. enr_i.t = T_i; // T_i : variable GLOBALE
  1445. enr_i.num = num_raie;
  1446. enr_i.midi = m0;
  1447. enr_i.amplitude = y0;
  1448.  
  1449. // tracer sur tableau fréquences
  1450. if(num_raie<10) // 6
  1451. {
  1452. liste_ENR_FFT << enr_i; // memorisation ; donc 5 notes max pour un temps (T_i) donné
  1453. // les notes ayant même T_i seront considérées comme simultanées (accord)
  1454. tracer_1enr(enr_i); // sur le 2eme onglet (NOTES)
  1455. }
  1456.  
  1457. num_raie++;
  1458. }
  1459. }
  1460. }
  1461. T_i++; // variable GLOBALE
  1462.  
  1463.  
  1464.  
  1465. // T_i est ici incrémenté à chaque appel de la fonction
  1466. // sachant que chaque appel de cette fonction analyse 1024 échantillons du signal.
  1467. // et que chaque échantillon représente une durée = 0.5ms du signal d'origine
  1468. // donc T_i est (virtuellement) incrémenté toutes les 1024*0.5ms = 512ms;
  1469. // pourquoi 'virtuellement' ? parce que chaque échantillon "REPRESENTE" une durée de 0.5 ms
  1470. // mais ne "DURE PAS" 0.5ms; L'analyse s'effectue à très haute vitesse sur un signal pré-échantilloné.
  1471. // de quel chapeau sort ce 0.5ms? Voir la fontion 'void MainWindow::remplir_tableau_echantillons_signal()'
  1472.  
  1473. num_raie=0;
  1474. //affi_notes();
  1475.  
  1476. }
  1477.  
  1478.  
  1479. void MainWindow::tracer_echelle_temps_TAB_NOTES() //en secondes (scene4 sur l'onglet NOTES)
  1480. {
  1481.  
  1482. QString s1;
  1483. double x, x0, dx;
  1484. int offset_x = 80;
  1485. int y0 = 620;
  1486. double nbs;
  1487.  
  1488. //effacer_calque(scene4, calque_echelle_temporelle);
  1489.  
  1490. if (visu_ech_tps == true) {y0 = 0;} // grandes lignes
  1491. for(int n=0; n<=120; n++)
  1492. {
  1493. x0 = 10.0 * doubleSpinBox_T0->value();
  1494. dx = 1000.0 * pas_echantillonage/256.0; // = 1000 * 24 /256 = 93.75
  1495.  
  1496. x = x0 + dx * zoom_x * (double)n;
  1497.  
  1498. ligne1 = new QGraphicsLineItem(offset_x + x, y0-5, offset_x + x, 650);
  1499. QPen pen1;
  1500. pen1.setColor("#00FF00"); //
  1501. ligne1->setPen(pen1);
  1502. calque_echelle_temporelle->addToGroup(ligne1);
  1503.  
  1504. nbs = (double) n;
  1505. s1.setNum(nbs, 10, 0); // base 10, 0 décimale
  1506. s1 += "s";
  1507.  
  1508. Etiquette(offset_x + x, 630, 0, s1, "#FFFFFF", "#000000", "#00FF00", calque_echelle_temporelle);
  1509. }
  1510. }
  1511.  
  1512.  
  1513.  
  1514. void MainWindow::tracer_1enr(ENR_FFT enr_i) // c.a.d. ayant la durée élémentaire T_i = 256 ms
  1515. {
  1516. // "notes" primaires -> calque 'calque_TAB_FRQ' sur le 2eme onglet (NOTES)
  1517.  
  1518. int T2;
  1519. //uint8_t num_raie;
  1520. uint8_t m0;
  1521. double yH, yL;
  1522. double y0, y2, dy, dy2;
  1523. uint16_t v; // v comme 'vertical'
  1524. double offset_y = 350.0;
  1525. QString couleur1;
  1526.  
  1527. T2 = zoom_x * enr_i.t;
  1528.  
  1529. m0 = enr_i.midi;
  1530. y0 = enr_i.amplitude;
  1531.  
  1532. if (checkBox_flitrer->isChecked() && (m0 != spinBox_filtre->value())) {return;}
  1533.  
  1534. v= 700 - (16 * (m0-40) );
  1535. y2 = -y0 + offset_y;
  1536. dy = y2/30.0; // 40
  1537. //dy = y2/10;
  1538. //dy=dy*dy; // pour un meilleur affichage ; A VOIR !!!!
  1539. //dy /=5.0;
  1540. dy *= gain;
  1541.  
  1542. if (dy > 200) {dy = 200;} // bridage amplitude max
  1543.  
  1544. if(v > 730) {return;}
  1545.  
  1546. if (dy > seuil)
  1547. {
  1548. dy2 = dy;
  1549. if (checkBox_norm->isChecked()) {dy2=5; } // bride la hauteur des tirets
  1550. double x = 80.0 + T2;
  1551. yH = v+dy2/2;
  1552. yL = v-dy2/2;
  1553. // rabotage pour éviter le scrolling de l'affichage:
  1554. if(yH > 730) {yH = 730;}
  1555. if(yL <0) {yH = 0;}
  1556.  
  1557. //ligne1 = new QGraphicsLineItem(x, yL, x, yH);
  1558.  
  1559. rectangle1 = new QGraphicsRectItem(x, v-dy2/2, zoom_x-2, dy2);
  1560. int h1 = calcul_hauteur_note(m0);
  1561.  
  1562. if (checkBox_norm->isChecked()) // utilise une couleur en fonction de l'amplitude du signal
  1563. {
  1564. double dy3 = dy/ 20;
  1565. if (dy3 > 0.8) {dy3 = 0.8;}
  1566. couleur1 = calcul_couleur(dy3);
  1567. }
  1568. else
  1569. {
  1570. // utilise une couleur en fonction de la fréquence ('hauteur') de la note
  1571. couleur1 = liste_couleurs[h1];
  1572. }
  1573.  
  1574. QPen pen1;
  1575. pen1.setColor(couleur1);
  1576.  
  1577. rectangle1->setPen(pen1);
  1578. rectangle1->setBrush(QColor(couleur1));
  1579.  
  1580. QBrush br1;
  1581. br1.setStyle(Qt::SolidPattern);
  1582. br1.setColor(couleur1);
  1583. rectangle1->setBrush(br1);
  1584. calque_TAB_FRQ->addToGroup(rectangle1); // lent !
  1585.  
  1586. graphicsView1->verticalScrollBar()->setValue(0);
  1587. }
  1588. }
  1589.  
  1590.  
  1591. void MainWindow::detection_notes_auto() // notes secondaires (affi par petits cercles colorés)
  1592. {
  1593. ENR_FFT enr_i;
  1594.  
  1595. int T2;
  1596. uint32_t n_max;
  1597. uint8_t m0;
  1598. double A1;
  1599. double x, y, y0, y2;
  1600. double memo_x = 0;
  1601. double offset_y = 350.0;
  1602. double decalage;
  1603. QString couleur1;
  1604. QPen pen1;
  1605. pen1.setWidth(1);
  1606.  
  1607. double pas_grille = spinBox_dxa->value()/2.0 * zoom_x;
  1608. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  1609.  
  1610. n_max = liste_ENR_FFT.size();
  1611. //qDebug() << "n_max" << n_max;
  1612.  
  1613. if (n_max == 0) return;
  1614.  
  1615. tableWidget_type_M->setCurrentCell(2, 0);
  1616. on_tableWidget_type_M_cellClicked(2, 0);
  1617.  
  1618. liste_NOTES.clear();
  1619.  
  1620. for(int n=0; n<83; n++)
  1621. {
  1622. table_integration_amplitudes[n] =0; // RAZ
  1623. }
  1624. calque_notes_auto->setPos(0, 0);
  1625.  
  1626. for(uint32_t n=0; n<n_max-1; n++)
  1627. {
  1628. enr_i = liste_ENR_FFT[n];
  1629. T2 = zoom_x * enr_i.t;
  1630.  
  1631. m0 = enr_i.midi;
  1632.  
  1633. y0 = enr_i.amplitude;
  1634. y2 = -y0 + offset_y;
  1635.  
  1636. y = 700 - (16 * (m0-40) );
  1637. A1 = y2/10.0; // 40
  1638. A1 *= gain;
  1639.  
  1640. // table_integration_amplitudes[m0] /= 2.0; // usure volontaire
  1641. if(A1<20)
  1642. {
  1643. table_integration_amplitudes[m0] = 0; // ce qui est débloquant
  1644. }
  1645.  
  1646. if (A1 > 20) // 30
  1647. {
  1648. x = 80.0 + T2 -8; // le -8 pour décaler dans le temps (de la durée de l'intégration)
  1649.  
  1650. //intégration temporelle des amplitudes en vue de valider en tant que note
  1651. if(table_integration_amplitudes[m0] >=0) // si pas de blocage en cours
  1652. {
  1653. table_integration_amplitudes[m0] += A1;
  1654. }
  1655.  
  1656. if (table_integration_amplitudes[m0] > 200.0)
  1657. {
  1658. // la NOTE est comfirmée, on va l'ajouter à la fin de la liste des notes
  1659. // Mais il faut aussi empêcher des re-détections multiples lorsque l'amplitute du signal ne décroit
  1660. // que progressivement. Pour cela on attribue la valeur -1 dans la table d'intégration
  1661. // pour le n° midi de la note, ce qui sera bloquant.
  1662. // Le déblocage se produira lorsque l'amplitude du signal concernant cette note
  1663. // sera descendu en dessous d'un certain niveau.
  1664.  
  1665. table_integration_amplitudes[m0] = -1; //ce qui est bloquant (voir 10 lignes +haut)
  1666.  
  1667. int h1 = calcul_hauteur_note(m0); //'hauteur' au sens musical, gamme chromatique
  1668. couleur1 = liste_couleurs[h1];
  1669. pen1.setColor(couleur1);
  1670.  
  1671. int delta_x = int(x - memo_x);
  1672. memo_x = x ;
  1673.  
  1674. ellipse1 = new QGraphicsEllipseItem(x-A1/2, y-A1/2, A1, A1);
  1675. ellipse1->setPen(pen1);
  1676. calque_notes_auto->addToGroup(ellipse1); // cercle coloré
  1677. //on va ajouter la note à la liste des notes
  1678.  
  1679. int n_barre = num_barre(x);
  1680.  
  1681. if (n_barre != -1) {ajout_note(m0, n_barre, 0);}
  1682.  
  1683. // ellipse1 = new QGraphicsEllipseItem(x, v-1, 2, 2);
  1684. // pen1.setColor("#FFFFFF");
  1685. // ellipse1->setPen(pen1);
  1686. // calque_notes_auto->addToGroup(ellipse1); // point blanc
  1687. }
  1688. }
  1689. // voir la fonction -> 'tracer_1enr(ENR_FFT enr_i)' pour le cadrage
  1690.  
  1691. }
  1692. calque_notes_auto->setPos(offset_x, 0);
  1693. mode='M';
  1694. on_Bt_toggle_grille_T_clicked(); // basculera à T;
  1695. doubleSpinBox_vitesse->setValue(30);
  1696. }
  1697.  
  1698.  
  1699. void MainWindow::retracer_TAB_FRQ()
  1700. {
  1701. ENR_FFT enr_i;
  1702. uint16_t n_max = liste_ENR_FFT.length();
  1703. if (n_max == 0) return;
  1704. //effacer_calque(scene1,calque_trace_FFT );
  1705. tracer_graduation_TAB_NOTES();
  1706.  
  1707. calque_TAB_FRQ->setPos(0, 0);
  1708. for(uint16_t n=0; n<n_max-1; n++)
  1709. {
  1710. enr_i = liste_ENR_FFT[n];
  1711. tracer_1enr(enr_i);
  1712. }
  1713.  
  1714. double pas_grille = spinBox_dxa->value()/2.0 * zoom_x;
  1715. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  1716. calque_TAB_FRQ->setPos(offset_x, 0);
  1717. }
  1718.  
  1719.  
  1720.  
  1721. void RAZ_tableau_echantillons()
  1722. {
  1723. uint n;
  1724. for(n=0; n < nb_ech; n++)
  1725. {
  1726. ech[n].a = 0; // partie reelle
  1727. ech[n].b = 0; // partie imaginaire
  1728. }
  1729. }
  1730.  
  1731.  
  1732.  
  1733. uint bit_reversal(uint num, uint nb_bits)
  1734. {
  1735. uint r = 0, i, s;
  1736. if ( num > (1<< nb_bits)) { return 0; }
  1737.  
  1738. for (i=0; i<nb_bits; i++)
  1739. {
  1740. s = (num & (1 << i));
  1741. if(s) { r |= (1 << ((nb_bits - 1) - i)); }
  1742. }
  1743. return r;
  1744. }
  1745.  
  1746.  
  1747.  
  1748. void MainWindow::bit_reverse_tableau_X()
  1749. {
  1750. // recopie les échantillons en les classant dans l'ordre 'bit reverse'
  1751. uint n,r;
  1752.  
  1753. for(n=0; n < nb_ech; n++) // nb d'échantillons
  1754. {
  1755. r=bit_reversal(n,nb_etapes);
  1756. tab_X[n] = ech[r];
  1757. }
  1758. }
  1759.  
  1760. void MainWindow::calcul_tableau_W()
  1761. {
  1762. if (tableau_w_plein == true) {return;}
  1763. // calcul et memorisation dans un tableau des twiddle factors (facteurs de rotation)
  1764. uint n;
  1765. double x;
  1766. for(n=0; n<(nb_ech/2-1); n++)
  1767. {
  1768. x=2.0*M_PI * n / nb_ech;
  1769.  
  1770. tab_W[n].a = cos(x); // partie reelle
  1771. tab_W[n].b = -sin(x); // partie imaginaire
  1772. }
  1773. tableau_w_plein = true;
  1774. }
  1775.  
  1776.  
  1777. void MainWindow::calcul_FFT()
  1778. {
  1779. Complexe produit; // voir la classe "Complexe" : complexe.h et complexe.ccp
  1780.  
  1781. uint etape, e1, e2, li, w, ci;
  1782. uint li_max=nb_ech;
  1783. e2=1;
  1784.  
  1785. for (etape=1; etape<=nb_etapes; etape++)
  1786. {
  1787. e1=e2; //(e1 évite d'effectuer des divisions e2/2 plus bas)
  1788. e2=e2+e2; // plus rapide que *=2
  1789.  
  1790. for (li=0; li<li_max; li+=1)
  1791. {
  1792. ci=li & (e2-1); // ET bit à bit
  1793. if (ci>(e1-1))
  1794. {
  1795. w=li_max/e2*(li & (e1 -1)); // ET bit à bit calcul du numéro du facteur de rotation W
  1796. produit = tab_W[w] * tab_X[li]; // le twiddle factor est lu en memoire; le produit est une mutiplication de nb complexes. Voir "complexe.cpp"
  1797. tab_X[li]=tab_X[li-e1] - produit; // concerne la ligne basse du croisillon; soustraction complexe; Voir "complexe.cpp"
  1798. tab_X[li-e1]=tab_X[li-e1] + produit; // concerne la ligne haute du croisillon; addition complexe; Voir "complexe.cpp"
  1799. }
  1800. }
  1801. }
  1802. }
  1803.  
  1804.  
  1805. void MainWindow::Tic1() // pour l'analyse de Fourier en vitesse lente
  1806. {
  1807.  
  1808. nb_tics++;
  1809. if(nb_tics > 4000)
  1810. {
  1811. Timer1->stop();
  1812. nb_tics=0;
  1813. }
  1814. else
  1815. {
  1816. spinBox_4->setValue( spinBox_4->value() +1);
  1817. Timer1->setInterval(2); // à voir
  1818. }
  1819. }
  1820.  
  1821.  
  1822. void MainWindow::trace_time_line()
  1823. {
  1824. double x_note, x, dx;
  1825.  
  1826.  
  1827. if(mode=='T') { x_note = calcul_x_barre(liste_NOTES[num_note_jouee-1].n_barreT); }
  1828. if(mode=='M') { x_note = calcul_x_barre(liste_NOTES[num_note_jouee-1].n_barreM); }
  1829. dx = calcul_pas_grille();
  1830. x = x_note + double(num_barre_en_cours) * dx;
  1831.  
  1832.  
  1833. int midi_i = liste_NOTES[num_note_jouee-1].midi;
  1834. int y = calcul_y_note(midi_i) ;
  1835.  
  1836. int h1 = calcul_hauteur_note(midi_i);
  1837. QString couleur1 = liste_couleurs[h1];
  1838.  
  1839. QPen pen1;
  1840. pen1.setColor(couleur1);
  1841. pen1.setWidth(2);
  1842.  
  1843. //ellipse1 = new QGraphicsEllipseItem(x, y, 2, 2) ;
  1844. //ellipse1->setPen(pen1);
  1845. //ellipse1->setBrush(blanc);
  1846. //calque_notes_jouee->addToGroup(ellipse1);
  1847.  
  1848. rectangle1 = new QGraphicsRectItem(x, y, dx, 2) ;
  1849. rectangle1->setPen(pen1);
  1850. calque_notes_jouee->addToGroup(rectangle1);
  1851. }
  1852.  
  1853.  
  1854.  
  1855. void MainWindow::Tic2() // pour jouer le morceau (la liste des notes détectées)
  1856. {
  1857.  
  1858. double dt, vts;
  1859. int deltaT;
  1860.  
  1861. num_barre_en_cours++;
  1862.  
  1863. trace_time_line();
  1864.  
  1865. nb_tics2++;
  1866. if(nb_tics2 >= d_barre2)
  1867. {
  1868. nb_tics2=0;
  1869. num_barre_en_cours=-1;
  1870. d_barre2 = joue_1_note_de_la_liste(); // nb de barres temporelles séparant la note avec celle qui suit
  1871. }
  1872.  
  1873. vts = 2.0 * doubleSpinBox_vitesse->value();
  1874. dt = 20.0; // * (double)d_barre;
  1875. dt *= (100.0 / vts);
  1876. if(mode == 'M') {dt *= 8.0;}
  1877. deltaT = (int) dt;
  1878.  
  1879. if (d_barre2>0) {Timer2->setInterval(deltaT);} else {Timer2->setInterval(0);}
  1880.  
  1881. }
  1882.  
  1883.  
  1884. void clear_temp_data()
  1885. {
  1886. for(int i=0; i<2000000; i++)
  1887. {
  1888. temp_data[i]=0;
  1889. }
  1890.  
  1891. }
  1892.  
  1893.  
  1894. void MainWindow::on_Bt_load_wav_clicked()
  1895. {
  1896. open_fichier_wav(); // associe le binStream1 au fichier wav
  1897. decode_entete();
  1898.  
  1899. MainWindow::setCursor(Qt::WaitCursor);
  1900. liste_ENR_FFT.clear();
  1901. effacer_calque(scene1,calque_trace_signal1 );
  1902.  
  1903. effacer_calque(scene1, calque_trace_FFT);
  1904. clear_temp_data();
  1905. garnis_temp_data(0);
  1906.  
  1907. ajustement_gain();
  1908. // donne accès à la totalité (2MB) du fichier wav (dans le 'temp_data')
  1909. tracer_signal_complet();
  1910. MainWindow::setCursor(Qt::ArrowCursor);
  1911. tracer_gradu_temporelle_signal_entree();
  1912.  
  1913. frame_3->setVisible(true);
  1914. Bt_scan_auto->setVisible(true);
  1915. checkBox_rapide->setVisible(true);
  1916. }
  1917.  
  1918.  
  1919.  
  1920. /*
  1921.   char RIFF[4]; (4 bytes)
  1922.   unsigned long ChunkSize; (4 bytes)
  1923.   char WAVE[4]; (4 bytes)
  1924.   char fmt[4]; (4 bytes)
  1925.   unsigned long Subchunk1Size; (4 bytes)
  1926.   unsigned short AudioFormat; (2 octets)
  1927.   unsigned short NumOfChan; (2 octets)
  1928.   unsigned long SamplesPerSec; (4 bytes)
  1929.   unsigned long bytesPerSec; (4 bytes)
  1930.   unsigned short blockAlign; (2 octets)
  1931.   unsigned short bitsPerSample; (2 octets)
  1932.   char Subchunk2ID[4]; (4 bytes)
  1933.   unsigned long Subchunk2Size; (4 bytes)
  1934.  
  1935.   TOTAL 44 octets
  1936. */
  1937.  
  1938.  
  1939. QString separ_milliers(uint n) // séparation des miliers par des espaces
  1940. {
  1941. QString s1, s1a, s1b, s1c;
  1942. s1.setNum(n);
  1943. int L= s1.length(); s1a = s1.right(3); s1b = s1.mid(L-6, 3); s1c = s1.mid(L-9, 3);
  1944. return (s1c+" "+s1b+" "+s1a);
  1945. }
  1946.  
  1947.  
  1948.  
  1949. void MainWindow::save_fichier_ini()
  1950. {
  1951. QFile file1(QDir::currentPath() + "/" + "params_FFT.ini"); // dans le dossier de l'exécutable
  1952. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  1953. {
  1954. //int p1= string_currentFile.lastIndexOf('/');
  1955. //string_currentDir = string_currentFile.left(p1);
  1956.  
  1957. QTextStream out(&file1);
  1958.  
  1959. out << "# Ce fichier est crée automatiquement par le programme";
  1960. out << '\n';
  1961. out << "#";
  1962. out << '\n';
  1963. out << "# chemins:";
  1964. out << '\n';
  1965. out << "<currentDir>" << string_currentDir << "</currentDir>";
  1966. out << '\n';
  1967. out << "<currentFile>" << string_currentFile << "</currentFile>";
  1968. }
  1969. file1.close();
  1970. }
  1971.  
  1972.  
  1973.  
  1974. void MainWindow::open_fichier_wav()
  1975. {
  1976. // Le fichier .wav comprend un signal audio stéréo échantilloné à 48 000 octets/seconde pour chaque canal
  1977. // ce qui fait 96000 octets/s pour l'ensemble du signal stéréo
  1978.  
  1979. string_currentFile = QFileDialog::getOpenFileName(this, tr("Ouvrir Fichier wav..."), string_currentDir,
  1980. tr("Fichiers wav (*.wav);;All Files (*)"));
  1981. if (string_currentFile != "")
  1982. {
  1983. save_fichier_ini();
  1984. }
  1985. lineEdit_1->setText(string_currentFile);
  1986.  
  1987. int p1= string_currentFile.lastIndexOf('/');
  1988. string_currentDir = string_currentFile.left(p1);
  1989. lineEdit_current_dir->setText(string_currentDir);
  1990.  
  1991. save_fichier_ini();
  1992.  
  1993. file_wav.setFileName(string_currentFile);
  1994. if (!file_wav.open(QIODevice::ReadOnly))
  1995. {
  1996. wav_ok = false;
  1997. Bt_scan_auto->setStyleSheet("background-color: rgb(200, 200, 200);");
  1998. return ;
  1999. }
  2000. else
  2001. {
  2002. binStream1.setDevice(&file_wav); // accès à la totalité du fichier wav
  2003. wav_ok = true;
  2004. Bt_scan_auto->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  2005.  
  2006. }
  2007. // le fichier reste ouvert pour toute la session
  2008. }
  2009.  
  2010.  
  2011.  
  2012.  
  2013. void MainWindow::decode_entete()
  2014. {
  2015. // ============ [Bloc de déclaration d'un fichier au format WAVE] ============
  2016.  
  2017. if (! wav_ok) {return;}
  2018. QString s3, s4, s5, fileSize1;
  2019. uint8_t x, nb_canaux;
  2020. double tot1, tot2, tot3, tot4;
  2021.  
  2022.  
  2023. binStream1.device()->seek(0); // retour de la lecture au début du fichier
  2024. binStream1.readRawData (temp_entete, 100); // lecture entete du fichier
  2025. //FileTypeBlocID
  2026. x=(uint8_t)temp_entete[0]; if ((x>64) && (x<127)) { s3 = char(x); }
  2027. x=(uint8_t)temp_entete[1]; if ((x>64) && (x<127)) { s3 += char(x); }
  2028. x=(uint8_t)temp_entete[2]; if ((x>64) && (x<127)) { s3 += char(x); }
  2029. x=(uint8_t)temp_entete[3]; if ((x>64) && (x<127)) { s3 += char(x); }
  2030. tableWidget_1->setItem(0, 0, new QTableWidgetItem (s3) ); //FileTypeBlocID
  2031.  
  2032. // FileSize
  2033. x=(uint8_t)temp_entete[4]; s3.setNum(x); tableWidget_1->setItem(1, 0, new QTableWidgetItem (s3) );
  2034. x=(uint8_t)temp_entete[5]; s3.setNum(x); tableWidget_1->setItem(1, 1, new QTableWidgetItem (s3) );
  2035. x=(uint8_t)temp_entete[6]; s3.setNum(x); tableWidget_1->setItem(1, 2, new QTableWidgetItem (s3) );
  2036. x=(uint8_t)temp_entete[7]; s3.setNum(x); tableWidget_1->setItem(1, 3, new QTableWidgetItem (s3) );
  2037.  
  2038. tot1 = temp_entete[4] + (2<<7) * temp_entete[5] + (2<<15) * temp_entete[6] + (2<23)* temp_entete[7];
  2039. fileSize1 = separ_milliers(tot1);
  2040. tableWidget_1->setItem(1, 4, new QTableWidgetItem ("= " + fileSize1) );
  2041.  
  2042. // FileFormatID
  2043. x=(uint8_t)temp_entete[8]; if ((x>64) && (x<127)) { s3 = char(x); }
  2044. x=(uint8_t)temp_entete[9]; if ((x>64) && (x<127)) { s3 += char(x); }
  2045. x=(uint8_t)temp_entete[10]; if ((x>64) && (x<127)) { s3 += char(x); }
  2046. x=(uint8_t)temp_entete[11]; if ((x>64) && (x<127)) { s3 += char(x); }
  2047. tableWidget_1->setItem(2, 0, new QTableWidgetItem (s3) );
  2048.  
  2049. // ============ [Bloc décrivant le format audio] ==============
  2050.  
  2051. // FormatBlocID
  2052. x=(uint8_t)temp_entete[12]; if ((x>64) && (x<127)) { s3 = char(x); }
  2053. x=(uint8_t)temp_entete[13]; if ((x>64) && (x<127)) { s3 += char(x); }
  2054. x=(uint8_t)temp_entete[14]; if ((x>64) && (x<127)) { s3 += char(x); }
  2055. x=(uint8_t)temp_entete[15]; if ((x>64) && (x<127)) { s3 += char(x); }
  2056. tableWidget_1->setItem(3, 0, new QTableWidgetItem (s3) );
  2057.  
  2058. //BlocSize
  2059. x=(uint8_t)temp_entete[16]; s3.setNum(x); tableWidget_1->setItem(4, 0, new QTableWidgetItem (s3) );
  2060. x=(uint8_t)temp_entete[17]; s3.setNum(x); tableWidget_1->setItem(4, 1, new QTableWidgetItem (s3) );
  2061. x=(uint8_t)temp_entete[18]; s3.setNum(x); tableWidget_1->setItem(4, 2, new QTableWidgetItem (s3) );
  2062. x=(uint8_t)temp_entete[19]; s3.setNum(x); tableWidget_1->setItem(4, 3, new QTableWidgetItem (s3) );
  2063.  
  2064. tot2 = (uint8_t)temp_entete[16] + (2<<7) * (uint8_t)temp_entete[17] + (2<<15) * (uint8_t)temp_entete[18] + (2<23)* (uint8_t)temp_entete[19];
  2065. tableWidget_1->setItem(4, 4, new QTableWidgetItem ("= " + separ_milliers(tot2)) );
  2066.  
  2067. //AudioFormat
  2068. x=(uint8_t)temp_entete[20]; s3.setNum(x); tableWidget_1->setItem(5, 0, new QTableWidgetItem (s3) );
  2069. x=(uint8_t)temp_entete[21]; s3.setNum(x); tableWidget_1->setItem(5, 1, new QTableWidgetItem (s3) );
  2070.  
  2071. if ((uint8_t)temp_entete[20]==1){tableWidget_1->setItem(5, 4, new QTableWidgetItem ("PCM") );}
  2072.  
  2073. //NbrCanaux
  2074. nb_canaux=(uint8_t)temp_entete[22]; s3.setNum(nb_canaux); tableWidget_1->setItem(6, 0, new QTableWidgetItem (s3) );
  2075. x=(uint8_t)temp_entete[23]; s3.setNum(x); tableWidget_1->setItem(6, 1, new QTableWidgetItem (s3) );
  2076.  
  2077. //Fréquence d'échantillonage en Hz
  2078. x=(uint8_t)temp_entete[24]; s3.setNum(x); tableWidget_1->setItem(7, 0, new QTableWidgetItem (s3) );
  2079. x=(uint8_t)temp_entete[25]; s3.setNum(x); tableWidget_1->setItem(7, 1, new QTableWidgetItem (s3) );
  2080. x=(uint8_t)temp_entete[26]; s3.setNum(x); tableWidget_1->setItem(7, 2, new QTableWidgetItem (s3) );
  2081. x=(uint8_t)temp_entete[27]; s3.setNum(x); tableWidget_1->setItem(7, 3, new QTableWidgetItem (s3) );
  2082.  
  2083. tot3 = (uint8_t)temp_entete[24] + (2<<7) * (uint8_t)temp_entete[25] + (2<<15) * (uint8_t)temp_entete[26] + (2<23)* (uint8_t)temp_entete[27];
  2084. tableWidget_1->setItem(7, 4, new QTableWidgetItem ("= " + separ_milliers(tot3)) );
  2085.  
  2086. //BytePerSec
  2087. x=temp_entete[28]; s3.setNum(x); tableWidget_1->setItem(8, 0, new QTableWidgetItem (s3) );
  2088. x=temp_entete[29]; s3.setNum(x); tableWidget_1->setItem(8, 1, new QTableWidgetItem (s3) );
  2089. x=temp_entete[30]; s3.setNum(x); tableWidget_1->setItem(8, 2, new QTableWidgetItem (s3) );
  2090. x=temp_entete[31]; s3.setNum(x); tableWidget_1->setItem(8, 3, new QTableWidgetItem (s3) );
  2091.  
  2092. tot4 = (uint8_t)temp_entete[28] + (2<<7) * (uint8_t)temp_entete[29] + (2<<15) * (uint8_t)temp_entete[30] + (2<23)* (uint8_t)temp_entete[31];
  2093. s3.setNum(tot4); // 96000
  2094.  
  2095. tableWidget_1->setItem(8, 4, new QTableWidgetItem (s3));
  2096. //tableWidget_1->setItem(8, 4, new QTableWidgetItem ("= " + separ_milliers(tot4)) );
  2097.  
  2098. //BytePerBloc
  2099. x=(uint8_t)temp_entete[32]; s3.setNum(x); tableWidget_1->setItem(9, 0, new QTableWidgetItem (s3) );
  2100. x=(uint8_t)temp_entete[33]; s3.setNum(x); tableWidget_1->setItem(9, 1, new QTableWidgetItem (s3) );
  2101.  
  2102. //BitsPerSample
  2103. x=(uint8_t)temp_entete[34]; s3.setNum(x); tableWidget_1->setItem(10, 0, new QTableWidgetItem (s3) );
  2104. x=(uint8_t)temp_entete[35]; s3.setNum(x); tableWidget_1->setItem(10, 1, new QTableWidgetItem (s3) );
  2105.  
  2106. x=(uint8_t)temp_entete[36]; if ((x>64) && (x<127)) { s3 = char(x); }
  2107. x=(uint8_t)temp_entete[37]; if ((x>64) && (x<127)) { s3 += char(x); }
  2108. x=(uint8_t)temp_entete[38]; if ((x>64) && (x<127)) { s3 += char(x); }
  2109. x=(uint8_t)temp_entete[39]; if ((x>64) && (x<127)) { s3 += char(x); }
  2110. tableWidget_1->setItem(11, 0, new QTableWidgetItem (s3) );
  2111.  
  2112. // DataSize
  2113. x=(uint8_t)temp_entete[40]; s3.setNum(x); tableWidget_1->setItem(12, 0, new QTableWidgetItem (s3) );
  2114. x=(uint8_t)temp_entete[41]; s3.setNum(x); tableWidget_1->setItem(12, 1, new QTableWidgetItem (s3) );
  2115. x=(uint8_t)temp_entete[42]; s3.setNum(x); tableWidget_1->setItem(12, 2, new QTableWidgetItem (s3) );
  2116. x=(uint8_t)temp_entete[43]; s3.setNum(x); tableWidget_1->setItem(12, 3, new QTableWidgetItem (s3) );
  2117.  
  2118. int tot5a = 1 * (uint8_t) temp_entete[40]; //because le temp_entête de type 'char' code avec entiers signés
  2119. int tot5b = (1<<8) * (uint8_t)temp_entete[41]; // remarque: (1<<8) = 2^8 = 256 // ne pas écrire (2<<8) !!
  2120. int tot5c = (1<<16) * (uint8_t)temp_entete[42];
  2121. int tot5d = (1<<24) * (uint8_t)temp_entete[43];
  2122.  
  2123. data_size = tot5a + tot5b + tot5c + tot5d;
  2124.  
  2125. // 21248 + 458752 = 480000
  2126. // pour le .wav LA 440 (48000, durée 10s) ->14x(2^16) + 166 * (2^8) = 960000
  2127. // 960 000 kb (stéréo) / 96 000 kb/s (stéréo)= 10s
  2128.  
  2129. tableWidget_1->setItem(12, 4, new QTableWidgetItem ("= " + separ_milliers(data_size)) ); // DataSize
  2130.  
  2131. // durée calculée
  2132. duree_totale = data_size / tot4;
  2133. s3.setNum(duree_totale, 'f', 3);// double n, char format = 'g', int precision = 6
  2134. tableWidget_1->setItem(13, 4, new QTableWidgetItem (s3 + " s") );
  2135.  
  2136. s4.setNum(tot4);
  2137. s4 = "ech : " + s3;
  2138. s4 += " Bps / 2 voies (stéréo) = ";
  2139.  
  2140. s5.setNum(tot4/2000);
  2141. s5 +=" kBps";
  2142.  
  2143. tableWidget_1->setItem(8, 5, new QTableWidgetItem (s5) );
  2144. lineEdit_6->setText("File size = " + fileSize1 + " bytes ; " + s4 + s5 + " ; durée calculée = " +s3 + "s");
  2145.  
  2146. if ((nb_canaux == 2) && (tot4 != 96000))
  2147. {
  2148. QMessageBox msgBox;
  2149. QString s1;
  2150. s1 = "Attention: Le taux d'échentillonage n'est pas 48 kb/s";
  2151. msgBox.setText(s1);
  2152. msgBox.exec();
  2153. }
  2154. if (nb_canaux != 2)
  2155. {
  2156. QMessageBox msgBox;
  2157. QString s1;
  2158. s1 = "Attention: Signal mono (doit être STEREO !)";
  2159. msgBox.setText(s1);
  2160. msgBox.exec();
  2161. }
  2162. }
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168. // voir la page : https://fr.wikipedia.org/wiki/Waveform_Audio_File_Format
  2169. void MainWindow::garnis_temp_data(qint32 offset_i)
  2170. {
  2171. if (! wav_ok) {return;}
  2172.  
  2173. binStream1.device()->seek(0); // retour de la lecture au début du fichier
  2174. binStream1.skipRawData(44+offset_i); // saut bien plus loin dans le fichier
  2175. binStream1.readRawData (temp_data, 2000000); //lecture des données audio
  2176.  
  2177. //file_wav.close();
  2178. }
  2179.  
  2180.  
  2181. void MainWindow::calcul_compression()
  2182. {
  2183. double R;
  2184. double R_max=0;
  2185.  
  2186. for(uint n =0; n<nb_ech/4; n++)
  2187. {
  2188. R=ech[n].a;
  2189. if (R>R_max) {R_max=R;}
  2190. }
  2191. }
  2192.  
  2193.  
  2194. void MainWindow::remplir_tableau_echantillons_signal() // lecture du signal à analyser dans le 'temp_data' -> ech[n]
  2195. {
  2196.  
  2197. /*
  2198. Le fichier .wav doit avoir les caractéristiques suivantes :
  2199. - RIFF PCM WAVE fmt
  2200. - stéréo deux voies
  2201. - 96000 octets/s c'est à dire acqui avec 48000 octets/s x 2 voies
  2202. La FTT sera effectuée en 10 passes, sur un nb_ech = 2^10 = 1024 échantillons
  2203. */
  2204.  
  2205. uint n, n_max, i, offset_x;
  2206. double R;
  2207.  
  2208. offset_x = 40; // ou plus, si lecture plus loin dans le temps, à voir
  2209.  
  2210. uint8_t octet_n; // octet_B;
  2211. /*
  2212.   pour un codage 8 bits/sample = 2 * 1 octet/sample (stéréo)
  2213.   [Octet du Sample1 Canal1 ] (octet_A, octet_B)
  2214.   [Octet du Sample1 Canal2 ]
  2215.   ...
  2216. */
  2217. i=0;
  2218. n=0;
  2219. // on ne prend pas en compte tous les échantillons dispo dans le .wav (inutile ici)
  2220. // mais 1 sur 40 (la fréquence de la note la plus aigue (midi94) est = 932Hz)
  2221. // et seul le fondamental est pertinant pour reconnaitre la note, les harmoniques (timbre) sont ignorées
  2222. // il faut donc échantilloner à 932*2 = 1864 Hz au minimum
  2223. // Le fichier .wav d'origine est échantilloné à 48kHz
  2224. // 48000 / 1864 = 25.75
  2225. // On va prendre 1 échantillon sur 24 , ce qui donne un échantillonage à 48000/24 = 2000Hz
  2226. // attention : tout changement de cette valeur (pas = 24) change l'échelle de représentation de la FFT
  2227. // et fout le bocson dans tout le programme !!!
  2228. // chaque échantillon représente donc une durée = 1/2000 seconde = 0.5ms = 500us
  2229. // voir la suite des explications vers la fin de la fonction 'void MainWindow::tracer_segments_FFT()'
  2230.  
  2231. n_max = nb_ech /2; // = 1024/2 = 512
  2232. // 512*0.5ms = 256 ms
  2233.  
  2234. while (n < n_max)
  2235. {
  2236. octet_n = temp_data[offset_x + i]; // canal A
  2237. // i++; // pour sauter (et ignorer) le canal B (le signal dans le fichier .wav est stéréo)
  2238. i+= pas_echantillonage;
  2239.  
  2240. // x= 256 * octet_A + octet_B;
  2241. R = octet_n - 128; // pour oter la composante continue propre au codage par des octets non signés
  2242. R /= 10.0;
  2243. R *= doubleSpinBox_gain->value();
  2244.  
  2245. if (hamming) { R = R * (1- cos (2* M_PI * n / nb_ech/2 ));}
  2246.  
  2247. if (bourrage_de_zeros)
  2248. {
  2249. if (n<=nb_ech/4) // /4 -> signal
  2250. {
  2251. ech[n].a = R; // partie reelle
  2252. ech[n].b = 0; // partie imaginaire
  2253. }
  2254. else // -> Bourage de zéros
  2255. {
  2256. ech[n].a = 0; // partie reelle
  2257. ech[n].b = 0; // partie imaginaire
  2258. }
  2259. }
  2260. else
  2261. {
  2262. ech[n].a = R; // partie reelle
  2263. ech[n].b = 0; // partie imaginaire
  2264. }
  2265.  
  2266. n++; // n atteindra la valeur max = 512 ech représentant une durée totale de 256 ms
  2267. }
  2268.  
  2269. //calcul_compression();
  2270. }
  2271.  
  2272. /*
  2273. void MainWindow::on_toolButton_2_clicked() // recup signal
  2274. {
  2275.   RAZ_tableau_echantillons();
  2276.   remplir_tableau_echantillons_signal();
  2277.   tracer_signal_a_convertir();
  2278. }
  2279. */
  2280.  
  2281. void MainWindow::calcul_ofsset()
  2282. {
  2283. if(!wav_ok) return;
  2284. offset_t = spinBox_1->value() + 10 * spinBox_2->value() + 100 * spinBox_3->value() + 1000 * spinBox_4->value()
  2285. + 10000 * spinBox_5->value() + 100000 * spinBox_6->value();
  2286. QString s1;
  2287. s1 = separ_milliers(offset_t) ;
  2288. lineEdit_3->setText(s1);
  2289. effacer_calque(scene2, calque_encadrement2);
  2290. encadrement_signal(offset_t/1200, 25);
  2291. }
  2292.  
  2293.  
  2294. void MainWindow::traitement_signal() // lance les Transformées de Fourier du signal
  2295. {
  2296. if (! wav_ok) {return;}
  2297.  
  2298. garnis_temp_data(offset_t);
  2299. remplir_tableau_echantillons_signal();
  2300.  
  2301. calcul_tableau_W();
  2302. //RAZ_tableau_echantillons();
  2303.  
  2304. if(!rapide) { tracer_signal_a_convertir();}
  2305. bit_reverse_tableau_X();
  2306.  
  2307. calcul_FFT(); // 1 FFT s'effectue sur 1 cluster de 1024 échantillons.
  2308. //Le résultat représente un spectre élémentaire correspondant au cluster, c.a.d à une durée = 1024 x 0.5ms = 512 ms
  2309. // ce résultat est retourné dans le tableau 'Complexe tab_X[2048]'
  2310.  
  2311. //if (radioButton_notes->isChecked()) { tracer_segments_FFT(); }
  2312. //else { tracer_modules_FFT(); }
  2313.  
  2314. tracer_segments_FFT();
  2315. }
  2316.  
  2317.  
  2318.  
  2319. void MainWindow::analyse_tout() // FFT de tous les clusters, c.a.d. sur la totalité du signal
  2320. {
  2321.  
  2322. progressBar_1->setVisible(true);
  2323. /*
  2324.   if (wav_ok == false)
  2325.   {
  2326.   QMessageBox msgBox;
  2327.   msgBox.setText("file 'wav' not open");
  2328.   int ret = msgBox.exec();
  2329.   return;
  2330.   }
  2331. */
  2332. /*
  2333.   if (data_nts_ok == false)
  2334.   {
  2335.   QMessageBox msgBox;
  2336.   msgBox.setText("file 'nts' not open");
  2337.   int ret = msgBox.exec();
  2338.   return;
  2339.   }
  2340. */
  2341.  
  2342. QString s1;
  2343. offset_t=0;
  2344. T_i=0; // variable GLOBALE
  2345.  
  2346. uint16_t i_max = data_size / 1024; // = environ 6000
  2347.  
  2348. if (checkBox_debut_seul->isChecked()) {i_max=2000;} // pour gagner du temps lors de la phase de test
  2349.  
  2350.  
  2351. // data_size est affiché par le visualisateur d'entête
  2352. // et aussi dans le LineEdit en bas de l'onglet FFT
  2353. // data_size = de l'ordre de 7MB, ce qui nous donne un i_max d'environ 6900
  2354.  
  2355. effacer_calque(scene4, calque_TAB_FRQ);
  2356. liste_ENR_FFT.clear();
  2357. //clear_temp_data();
  2358. //garnis_temp_data(0);
  2359.  
  2360. // effacer_calque(scene4, calque_gradu_TAB_FRQ);
  2361. // effacer_calque(scene4, calque_notes_manuelles);
  2362. // effacer_calque(scene4, calque_notes_jouee);
  2363. // effacer_calque(scene4, calque_grille_mesures);
  2364. // effacer_calque(scene4, calque_echelle_temporelle);
  2365.  
  2366. for(uint16_t i=0 ; i<i_max ; i++) // cette boucle sera donc parcourue environ 6000 fois...
  2367. {
  2368. if ((i % 200) == 0)
  2369. {
  2370. uint16_t pc = 100 * i / i_max;
  2371. pc+=2;
  2372. progressBar_1->setValue(pc);
  2373. // la ligne suivante permet l'affichage de la progression
  2374. QCoreApplication::processEvents(QEventLoop::AllEvents, 1);
  2375. }
  2376. //s1.setNum(i); lineEdit_compteur->setText(s1);
  2377.  
  2378. traitement_signal(); // traitement d'un cluster de 1024 échantillons
  2379. offset_t += 1024; // on passera au cluster de 1024 échantillons suivant c.a.d à un temps + 0.5ms
  2380.  
  2381. }
  2382. progressBar_1->setVisible(false);
  2383.  
  2384. tracer_echelle_temps_TAB_NOTES();
  2385. }
  2386.  
  2387.  
  2388.  
  2389.  
  2390. void MainWindow::on_spinBox_1_valueChanged(int arg1)
  2391. {
  2392. if (arg1==10) { spinBox_1->setValue(0); spinBox_2->stepUp();}
  2393. calcul_ofsset();
  2394. traitement_signal();
  2395. }
  2396.  
  2397.  
  2398. void MainWindow::on_spinBox_2_valueChanged(int arg1)
  2399. {
  2400. if (arg1==-1) {spinBox_2->setValue(9); spinBox_3->stepDown();}
  2401. if (arg1==10) { spinBox_2->setValue(0); spinBox_3->stepUp();}
  2402. calcul_ofsset();
  2403. traitement_signal();
  2404. }
  2405.  
  2406.  
  2407. void MainWindow::on_spinBox_3_valueChanged(int arg1)
  2408. {
  2409. if (arg1==-1) {spinBox_3->setValue(9); spinBox_4->stepDown();}
  2410. if (arg1==10) { spinBox_3->setValue(0); spinBox_4->stepUp();}
  2411. calcul_ofsset();
  2412. traitement_signal();
  2413. }
  2414.  
  2415.  
  2416. void MainWindow::on_spinBox_4_valueChanged(int arg1)
  2417. {
  2418. if (arg1==-1) {spinBox_4->setValue(9); spinBox_5->stepDown();}
  2419. if (arg1==10) { spinBox_4->setValue(0); spinBox_5->stepUp();}
  2420. calcul_ofsset();
  2421. traitement_signal();
  2422. }
  2423.  
  2424.  
  2425. void MainWindow::on_spinBox_5_valueChanged(int arg1)
  2426. {
  2427. if (arg1==-1) {spinBox_5->setValue(9); spinBox_6->stepDown();}
  2428. if (arg1==10) { spinBox_5->setValue(0); spinBox_6->stepUp();}
  2429. calcul_ofsset();
  2430. traitement_signal();
  2431. }
  2432.  
  2433.  
  2434. void MainWindow::on_spinBox_6_valueChanged()
  2435. {
  2436. //if (arg1==-1) {spinBox_6->setValue(9);} //spinBox_6->stepDown();}
  2437. calcul_ofsset();
  2438. traitement_signal();
  2439. }
  2440.  
  2441.  
  2442. void MainWindow::on_doubleSpinBox_1_valueChanged()
  2443. {
  2444. calcul_ofsset();
  2445. traitement_signal();
  2446. }
  2447.  
  2448.  
  2449. void MainWindow::on_pushButton_8_clicked()
  2450. {
  2451. QMessageBox msgBox;
  2452. QString s1;
  2453. s1 = "Le fichier audio à analyser doit être au format unsigned 8 bits PCM";
  2454. s1 += " (généré par exemple avec Audacity)";
  2455. s1 += "\n";
  2456. s1 += "Attention: ce n'est pas le format PCM par défaut, il faut aller dans les sous-menus :";
  2457. s1 += "\n";
  2458. s1 += "Fichier/Exporter/Exporter en WAV / encodage : Unsigned 8-bit PCM";
  2459. s1 += "\n";
  2460. s1 += "Ce n'est pas 'top WiFi', mais largement suffisant pour en faire la FFT et retrouver les notes.";
  2461. s1 += "\n";
  2462. s1 += "Ce qui est le but ici.";
  2463. s1 += "\n";
  2464. s1 += "D'autre part il est vivement conseillé de compresser la dynamique de l'audio (ce qui est simple avec Audacity)";
  2465. s1 += "\n";
  2466. s1 += "ce qui facilite grandement la détection des notes.";
  2467.  
  2468. msgBox.setText(s1);
  2469. msgBox.exec();
  2470. }
  2471.  
  2472.  
  2473. void MainWindow::on_Bt_RAZ_clicked()
  2474. {
  2475. spinBox_1->setValue(0);
  2476. spinBox_2->setValue(0);
  2477. spinBox_3->setValue(0);
  2478. spinBox_4->setValue(0);
  2479. spinBox_5->setValue(0);
  2480. spinBox_6->setValue(0);
  2481. offset_t=0;
  2482. num_barre_en_cours=0;
  2483. }
  2484.  
  2485.  
  2486. void MainWindow::on_spinBox_7_valueChanged(int arg1)
  2487. {
  2488. // ligne verticale
  2489. effacer_calque(scene1,calque_curseur);
  2490. int x = arg1;
  2491. ligne1 = new QGraphicsLineItem(x, 10, x, 500);
  2492. ligne1->setPen(pen_curseur);
  2493. calque_curseur->addToGroup(ligne1);
  2494.  
  2495. }
  2496.  
  2497.  
  2498.  
  2499.  
  2500. void MainWindow::on_pushButton_2_clicked()
  2501. {
  2502. Timer1->stop();
  2503. nb_tics=0;
  2504. }
  2505.  
  2506.  
  2507. void MainWindow::on_Btn_52_clicked()
  2508. {
  2509. //spinBox_n_midi->setValue(52);
  2510.  
  2511. file_wav.setFileName(nom_fichier_in);
  2512. if (!file_wav.open(QIODevice::ReadOnly))
  2513. {
  2514. wav_ok = false;
  2515. return ;
  2516. }
  2517.  
  2518. wav_ok = true;
  2519.  
  2520. on_Bt_RAZ_clicked();
  2521.  
  2522. binStream1.setDevice(&file_wav);
  2523. calcul_ofsset();
  2524. traitement_signal();
  2525. }
  2526.  
  2527.  
  2528. void MainWindow::on_Btn_94_clicked()
  2529. {
  2530.  
  2531. file_wav.setFileName(nom_fichier_in);
  2532. if (!file_wav.open(QIODevice::ReadOnly))
  2533. {
  2534. wav_ok = false;
  2535. return ;
  2536. }
  2537.  
  2538. wav_ok = true;
  2539.  
  2540. on_Bt_RAZ_clicked();
  2541.  
  2542. binStream1.setDevice(&file_wav);
  2543. calcul_ofsset();
  2544. traitement_signal();
  2545. }
  2546.  
  2547.  
  2548. void MainWindow::on_Bt_efface_clicked()
  2549. {
  2550. QMessageBox msgBox;
  2551. msgBox.setText("Erase Frequences");
  2552. msgBox.setInformativeText("Effacer toutes les FFT ?");
  2553. msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
  2554. msgBox.setDefaultButton(QMessageBox::Cancel);
  2555. int ret = msgBox.exec();
  2556.  
  2557. if (ret == QMessageBox::Ok )
  2558. {
  2559. effacer_calque(scene1,calque_trace_signal1 );
  2560. effacer_calque(scene1,calque_trace_FFT );
  2561. effacer_calque(scene1,calque_lignes_F_zero );
  2562. effacer_calque(scene1,calque_encadrement1 );
  2563. effacer_calque(scene2,calque_encadrement2 );
  2564.  
  2565. effacer_calque(scene4,calque_TAB_FRQ );
  2566. on_Bt_RAZ_clicked();
  2567. T_i=0; // T_i : variable GLOBALE
  2568. }
  2569.  
  2570. }
  2571.  
  2572.  
  2573.  
  2574. void MainWindow::on_pushButton_3_clicked()
  2575. {
  2576.  
  2577. tableWidget_1->setVisible(true);
  2578. Bt_close_entete->setVisible(true);
  2579. }
  2580.  
  2581.  
  2582. void MainWindow::on_Bt_close_entete_clicked()
  2583. {
  2584. tableWidget_1->setVisible(false);
  2585. Bt_close_entete->setVisible(false);
  2586. }
  2587.  
  2588. /*
  2589. void MainWindow::on_Bt_close_frame1_clicked()
  2590. {
  2591.   frame_1->setVisible(false);
  2592.   frame_3->setVisible(true);
  2593. }
  2594.  
  2595.  
  2596. void MainWindow::on_pushButton_4_clicked()
  2597. {
  2598.   frame_3->setVisible(false);
  2599.   frame_1->setVisible(true);
  2600. }
  2601. */
  2602.  
  2603.  
  2604. void MainWindow::on_pushButton_6_clicked()
  2605. {
  2606. frame_notes->setVisible(false);
  2607. }
  2608.  
  2609.  
  2610.  
  2611. void MainWindow::on_pushButton_5_clicked()
  2612. {
  2613. spinBox_offset->setValue(-2124); // 2154 ; ref -2210 ; +/- 22 pour un décalage de +/-1/4 de ton
  2614. spinBox_echx->setValue(499); // 498
  2615. }
  2616.  
  2617.  
  2618.  
  2619. int MainWindow::save_fichier_FRQ(QString date_i)
  2620. {
  2621. // enregisterment incrémentiel sur le disque (nom de fichier = 1..2...3...)
  2622. ENR_FFT enr_i;
  2623. QString s1;
  2624.  
  2625. uint8_t x0a = spinBox_x0a->value();
  2626. double x0b = doubleSpinBox_x0b->value();
  2627.  
  2628. uint8_t dxa = spinBox_dxa->value();
  2629. double dxb = doubleSpinBox_dxb->value();
  2630.  
  2631. long n_max = liste_ENR_FFT.length();
  2632. if (n_max == 0)
  2633. {
  2634. QMessageBox msgBox; msgBox.setText("liste FRQ vide !"); msgBox.exec();
  2635. return 1;
  2636. }
  2637. int numero=0;
  2638. QString s2 = date_i;
  2639. Timer1->stop();
  2640.  
  2641. QFile file1(string_currentDir + "/" + s2 + ".FRQ");
  2642. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2643. {
  2644. QByteArray byteArray1;
  2645. QDataStream stream1(&byteArray1, QIODevice::WriteOnly);
  2646. stream1.setDevice(&file1);
  2647. stream1.setVersion(QDataStream::Qt_6_8);
  2648.  
  2649. // entête 64 octets------------------
  2650. double vts = doubleSpinBox_vitesse->value(); // 8 octets
  2651. stream1 << x0b << dxb << vts << Ta << Tb << x0a << dxa; //8+8+8+1+1+1+1 =28 octets au début du fichier
  2652.  
  2653. for (int i=0; i<(64-28); i++) {stream1 << 'x';} // complète à 64 octet
  2654. // ----------------------------------
  2655.  
  2656. for(int n=0; n<n_max; n++)
  2657. {
  2658. enr_i = liste_ENR_FFT[n];
  2659. stream1 << enr_i.amplitude << enr_i.midi << enr_i.num << enr_i.t; // sérialisation des data
  2660. }
  2661. }
  2662. file1.close();
  2663.  
  2664. return 0;
  2665.  
  2666. }
  2667.  
  2668.  
  2669. void MainWindow::choix_dossier_de_travail()
  2670. {
  2671.  
  2672. QString actuel = string_currentDir;
  2673. string_currentDir = QFileDialog::getExistingDirectory
  2674. (this, tr("Open Directory"), actuel, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  2675.  
  2676. if (string_currentDir != "")
  2677. {
  2678. dossier_de_travail_ok = true;
  2679. save_fichier_ini();
  2680. lineEdit_current_dir->setText(string_currentDir);
  2681. }
  2682. else { dossier_de_travail_ok = false; } // -> si on clique sur le bouton 'cancel'
  2683.  
  2684. }
  2685.  
  2686.  
  2687. void MainWindow::on_Bt_choix_current_dir_clicked()
  2688. {
  2689. choix_dossier_de_travail();
  2690. }
  2691.  
  2692.  
  2693. void MainWindow::ajustement_gain()
  2694. {
  2695. double somme;
  2696. double moyenne;
  2697. double R;
  2698. double gain;
  2699. uint8_t octet_n;
  2700. long i, j;
  2701.  
  2702. double pas = 10.0 * pas_echantillonage; // 240
  2703. double n_max = 2000000 / pas;
  2704.  
  2705. i=0;
  2706. j=0;
  2707. somme =0;
  2708. for(long n=0; n<n_max; n++)
  2709. {
  2710. octet_n = temp_data[i]; // canal 1
  2711. if (octet_n !=0)
  2712. {
  2713. R = octet_n - 128;// pour ôter la composante continue (octets non signés)
  2714. if (R<0) {R= -R;}
  2715. somme += R;
  2716. j++; // nb de notes effectivement prises en compte
  2717. }
  2718. i+= pas;
  2719. }
  2720. moyenne = somme / j;
  2721.  
  2722. gain = 20.0/moyenne;
  2723. doubleSpinBox_gain->setValue(gain);
  2724. }
  2725.  
  2726.  
  2727. void MainWindow::load_fichier_FRQ()
  2728. {
  2729. QString filename1;
  2730. QString s1;
  2731.  
  2732. if(dossier_de_travail_ok == false)
  2733. {
  2734. choix_dossier_de_travail();
  2735. if (dossier_de_travail_ok == false)
  2736. {
  2737. QMessageBox msgBox;
  2738. s1="Le dossier de travail n'est pas spécifié";
  2739. msgBox.setText(s1); msgBox.exec();
  2740. return ;
  2741. }
  2742. }
  2743.  
  2744. filename1 = QFileDialog::getOpenFileName(this,
  2745. tr("Ouvrir Fichier FRQ"), string_currentDir + "/", tr("Fichiers FRQ (*.FRQ)"));
  2746.  
  2747.  
  2748. lineEdit_fichier_FREQ->setText(filename1);
  2749.  
  2750. file_dat.setFileName(filename1);
  2751. if (!file_dat.open(QIODevice::ReadOnly))
  2752. {
  2753. data_nts_ok = false;
  2754. return ;
  2755. }
  2756. else
  2757. {
  2758. binStream1.setDevice(&file_dat); // accès à la totalité du fichier dat
  2759. binStream1.setVersion(QDataStream::Qt_6_8);
  2760. data_nts_ok = true;
  2761. liste_ENR_FFT.clear();
  2762. }
  2763.  
  2764. //int z = sizeof(ENR_FFT); // ATTENTION ! ne PAS utiliser cette valeur qui tient en compte l'alignement en RAM
  2765. long n_max = file_dat.bytesAvailable() / 14; // 14 bits par enr; voir la def de 'ENR_FFT' dans le .h
  2766.  
  2767. uint8_t x0a;
  2768. double x0b;
  2769. uint8_t dxa;
  2770. double dxb;
  2771.  
  2772. double vts;
  2773.  
  2774. // lecture entête -----------------
  2775.  
  2776. binStream1 >> x0b >> dxb >> vts >> Ta >> Tb >> x0a >> dxa; // 8+8+8+1+1+1+1=28 octets au début du fichiers
  2777.  
  2778. uint8_t xx;
  2779. for (int i=0; i<(64-28); i++) {binStream1 >> xx;} // lit en tout à 64 octets
  2780. //---------------------------------
  2781.  
  2782. spinBox_x0a->setValue(x0a);
  2783. doubleSpinBox_x0b->setValue(x0b);
  2784. spinBox_dxa->setValue(dxa);
  2785. doubleSpinBox_dxb->setValue(dxb);
  2786. doubleSpinBox_vitesse->setValue(vts);
  2787.  
  2788. //---------------------------------
  2789.  
  2790. ENR_FFT enr_i;
  2791. for(int n=0; n<n_max; n++)
  2792. {
  2793. binStream1 >> enr_i.amplitude >> enr_i.midi >> enr_i.num >> enr_i.t;
  2794. liste_ENR_FFT << enr_i;
  2795. }
  2796. file_dat.close();
  2797.  
  2798. retracer_TAB_FRQ();
  2799.  
  2800. }
  2801.  
  2802.  
  2803. int MainWindow::save_fichier_NOTES(QString date_i)
  2804. {
  2805. // enregisterment incrémentiel sur le disque (nom de fichier = 1..2...3...)
  2806. NOTE note_i;
  2807. QString s1;
  2808.  
  2809. uint8_t x0a = spinBox_x0a->value();
  2810. double x0b = doubleSpinBox_x0b->value();
  2811.  
  2812. uint8_t dxa = spinBox_dxa->value();
  2813. double dxb = doubleSpinBox_dxb->value();
  2814.  
  2815. uint16_t n_max = liste_NOTES.length();
  2816. if (n_max == 0)
  2817. {
  2818. QMessageBox msgBox; msgBox.setText("liste NOTES vide !"); msgBox.exec();
  2819. return 1;
  2820. }
  2821.  
  2822. int numero=0;
  2823. QString s2;
  2824.  
  2825. Timer1->stop();
  2826.  
  2827. s2 = date_i;
  2828.  
  2829. //QFile file1(string_currentDir + "/" + "NOTES_" + s2 + ".nts");
  2830. QFile file1(string_currentDir + "/" + s2 + ".NTS");
  2831. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2832. {
  2833. QByteArray byteArray1;
  2834. QDataStream stream1(&byteArray1, QIODevice::WriteOnly);
  2835. stream1.setDevice(&file1);
  2836. stream1.setVersion(QDataStream::Qt_6_8);
  2837.  
  2838. // entête 64 octets --------------
  2839. double vts = doubleSpinBox_vitesse->value(); // 8 octets
  2840. stream1 << x0b << dxb << vts << Ta << Tb << x0a << dxa; //8+8+8+1+1+1+1 =28 octets au début du fichier
  2841.  
  2842. for (int i=0; i<(64-28); i++) {stream1 << 'x';} // complète à 64 octets
  2843. //--------------------------------
  2844. for(uint16_t n=0; n<n_max; n++)
  2845. {
  2846. note_i = liste_NOTES[n];
  2847. // sérialisation des data
  2848. stream1 << note_i.numero << note_i.midi << note_i.n_barreT << note_i.n_barreM;
  2849. }
  2850. }
  2851. file1.close();
  2852.  
  2853. return 0;
  2854. }
  2855.  
  2856.  
  2857.  
  2858. void MainWindow::load_fichier_NOTES()
  2859. {
  2860. QString filename1;
  2861. QString s1;
  2862.  
  2863. if(dossier_de_travail_ok == false)
  2864. {
  2865. choix_dossier_de_travail();
  2866. if (dossier_de_travail_ok == false)
  2867. {
  2868. QMessageBox msgBox;
  2869. s1="Le dossier de travail n'est pas spécifié";
  2870. msgBox.setText(s1); msgBox.exec();
  2871. return ;
  2872. }
  2873. }
  2874.  
  2875. filename1 = QFileDialog::getOpenFileName(this,
  2876. tr("Ouvrir Fichier NTS"), string_currentDir+"/", tr("Fichiers nts (*.NTS)"));
  2877.  
  2878.  
  2879. lineEdit_fichier->setText(filename1);
  2880.  
  2881. file_dat.setFileName(filename1);
  2882. if (!file_dat.open(QIODevice::ReadOnly))
  2883. {
  2884. data_nts_ok = false;
  2885. return ;
  2886. }
  2887. else
  2888. {
  2889. binStream1.setDevice(&file_dat); // accès à la totalité du fichier dat
  2890. binStream1.setVersion(QDataStream::Qt_6_8);
  2891. data_nts_ok = true;
  2892. }
  2893.  
  2894. //int z = sizeof(NOTE); // ATTENTION ! ne PAS utiliser cette valeur qui tient en compte l'alignement en RAM
  2895. uint16_t n_max = file_dat.bytesAvailable() / 7; // 7 bits par enr; voir la def de 'NOTE' dans le .h
  2896.  
  2897. uint8_t x0a;
  2898. double x0b;
  2899. uint8_t dxa;
  2900. double dxb;
  2901.  
  2902. double vts;
  2903.  
  2904. // lecture entête -----------------
  2905. binStream1 >> x0b >> dxb >> vts >> Ta >> Tb >> x0a >> dxa; // 8+8+8+1+1+1+1=28 octets au début du fichiers
  2906.  
  2907. uint8_t xx;
  2908. for (int i=0; i<(64-28); i++) {binStream1 >> xx;} // lit en tout à 64 octets
  2909. //---------------------------------
  2910. spinBox_x0a->setValue(x0a);
  2911. doubleSpinBox_x0b->setValue(x0b);
  2912. spinBox_dxa->setValue(dxa);
  2913. doubleSpinBox_dxb->setValue(dxb);
  2914. doubleSpinBox_vitesse->setValue(vts);
  2915.  
  2916. switch (Ta)
  2917. {
  2918. case 2: {lineEdit_10->setText("2/4"); Ta=2; Tb=4;} break; // Ta et Tb variables globales
  2919. case 3: {lineEdit_10->setText("3/4"); Ta=3; Tb=4;} break;
  2920. case 4: {lineEdit_10->setText("4/4"); Ta=4; Tb=4;} break;
  2921. default: break;
  2922. }
  2923.  
  2924. NOTE note_i;
  2925. for(int n=0; n<n_max; n++)
  2926. {
  2927. binStream1 >> note_i.numero >> note_i.midi >> note_i.n_barreT >> note_i.n_barreM;
  2928. note_i.midi += spinBox_transposition->value();
  2929. liste_NOTES << note_i;
  2930. }
  2931.  
  2932. file_dat.close();
  2933.  
  2934. mode = 'M';
  2935. on_Bt_toggle_grille_T_clicked();
  2936.  
  2937. Bt_jouer_tout->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  2938.  
  2939. }
  2940.  
  2941.  
  2942. void decalle_notes(int d)
  2943. {
  2944. int nb;
  2945. uint16_t i_max = liste_NOTES.length();
  2946. for( int i =0; i<i_max; i++)
  2947. {
  2948. nb = liste_NOTES[i].n_barreT;
  2949. nb += d;
  2950. liste_NOTES[i].n_barreT = nb;
  2951. }
  2952.  
  2953. }
  2954.  
  2955.  
  2956.  
  2957. void MainWindow::on_Bt_load_FREQ_clicked()
  2958. {
  2959. load_fichier_FRQ();
  2960. on_Bt_toggle_grille_T_clicked();
  2961. //effacer_calque(scene5, calque_histogramme );
  2962. tracer_echelle_temps_TAB_NOTES();
  2963. }
  2964.  
  2965.  
  2966. void MainWindow::on_checkBox_rapide_stateChanged(int arg1)
  2967. {
  2968. rapide=arg1;
  2969. init_TAB_FRQ();
  2970. }
  2971.  
  2972.  
  2973.  
  2974. void MainWindow::on_doubleSpinBox_seuil_valueChanged(double arg1)
  2975. {
  2976. seuil = arg1;
  2977. effacer_calque(scene4, calque_TAB_FRQ);
  2978. retracer_TAB_FRQ();
  2979. }
  2980.  
  2981.  
  2982. void MainWindow::on_checkBox_norm_clicked()
  2983. {
  2984. /*
  2985.   if (checkBox_norm->isChecked())
  2986.   {
  2987.   textEdit_ETAT->setText("Mode Normalisé : \n Les couleurs représentent l'amplitude du signal");
  2988.   }
  2989.   else
  2990.   {
  2991.   textEdit_ETAT->setText(
  2992. "Mode Fréquences : \n"
  2993.  "Les couleurs représentent la valeur (fréquence) de la note (Do, RE, MI...) \n"
  2994.  "La taille de chaque tiret représente (abusivement sur l'axe fréquenciel) l'amplitude du signal \n"
  2995.  "cette taille ne signifie donc pas un étalement en fréquence du signal, c'est juste une astuce de représentation."
  2996.   );
  2997.   }
  2998. */
  2999. effacer_calque(scene4, calque_TAB_FRQ);
  3000. retracer_TAB_FRQ();
  3001. }
  3002.  
  3003.  
  3004.  
  3005. void MainWindow::surbrille_note(uint16_t n)
  3006. {
  3007. double x_note;
  3008.  
  3009. NOTE note_i;
  3010. uint16_t n_max = liste_NOTES.length();
  3011. if ( n>= n_max) {return;}
  3012.  
  3013. note_i = liste_NOTES[n];
  3014.  
  3015. // x_note = calcul_x_barre_T(note_i.n_barreT);
  3016.  
  3017. x_note=0;
  3018. if(mode=='T') { x_note = calcul_x_barre(note_i.n_barreT); }
  3019. if(mode=='M') { x_note = calcul_x_barre(note_i.n_barreM); }
  3020.  
  3021. //qDebug() << "x_note" << x_note;
  3022.  
  3023. if (checkBox_scrolling->isEnabled())
  3024. {
  3025. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  3026. double diff_x = (x_note - scroll_x);
  3027.  
  3028. if (diff_x > (memo_scroll_x + 1000))
  3029. {
  3030. on_Bt_next_clicked();
  3031. memo_scroll_x = graphicsView4->horizontalScrollBar()->value();
  3032. //graphicsView4->horizontalScrollBar()->setValue(diff_x - 1000);
  3033.  
  3034. }
  3035. }
  3036.  
  3037. int y;
  3038.  
  3039. int midi_i;
  3040. QString blanc = "#FFFFFF";
  3041.  
  3042. midi_i = note_i.midi;
  3043. y = calcul_y_note(midi_i) ;
  3044.  
  3045. //if (effacer) {effacer_calque(scene4, calque_notes_jouee);}
  3046.  
  3047. QPen pen1;
  3048. pen1.setColor(blanc);
  3049. pen1.setWidth(2);
  3050. ellipse1 = new QGraphicsEllipseItem(x_note-15, y-15, 30, 30) ;
  3051. ellipse1->setPen(pen1);
  3052. //ellipse1->setBrush(blanc);
  3053. calque_notes_jouee->addToGroup(ellipse1);
  3054. }
  3055.  
  3056.  
  3057. void MainWindow::complete_case(int row, int column, QString s1, QString c1, QString c2, bool bold1, QTableWidget *QTI)
  3058. {
  3059. QTableWidgetItem *Item1 = new QTableWidgetItem();
  3060. Item1->QTableWidgetItem::setForeground(QColor(c1));
  3061. Item1->QTableWidgetItem::setBackground(QColor(c2));
  3062.  
  3063. QFont font1;
  3064. font1.setBold(bold1);
  3065. Item1->setFont(font1);
  3066. Item1->setTextAlignment(Qt::AlignCenter);
  3067.  
  3068. Item1->setText(s1);
  3069. QTI->setItem(row,column,Item1);
  3070. }
  3071.  
  3072.  
  3073. void MainWindow::affiche_liste_notes() // en TEXTE dans le petit tableau
  3074. {
  3075. NOTE note_i;
  3076. QString s1;
  3077.  
  3078. QString blanc = "#FFFFFF";
  3079. QString jaune = "#FFFF00";
  3080. QString cyan = "#00FFFF";
  3081.  
  3082. tableWidget_lst_notes->clear();
  3083. tableWidget_lst_notes->setRowCount(0);
  3084. init_TAB_lst_notes();
  3085.  
  3086. uint16_t n_max = liste_NOTES.length();
  3087. if (n_max == 0) {return;}
  3088.  
  3089. for(int n=0; n<n_max; n++) //n_max
  3090. {
  3091. note_i=liste_NOTES[n];
  3092.  
  3093. int numero = note_i.numero;
  3094. int midi = note_i.midi;
  3095. int n_barreT = note_i.n_barreT;
  3096. int n_barreM = note_i.n_barreM;
  3097.  
  3098. int num_ligne = tableWidget_lst_notes->rowCount();
  3099. tableWidget_lst_notes->setRowCount(num_ligne+1); // ajout une ligne au tableau
  3100.  
  3101. s1.setNum(numero);
  3102.  
  3103. complete_case(n, 0, s1, "000000", "#FFFFFF", false, tableWidget_lst_notes);
  3104.  
  3105. s1.setNum(midi);
  3106. int h1 = calcul_hauteur_note(midi);
  3107.  
  3108.  
  3109. QString couleur1 = liste_couleurs[h1];
  3110. complete_case(n, 1, s1, "#000000", couleur1, true, tableWidget_lst_notes);
  3111.  
  3112. s1 = nom_note(midi);
  3113. complete_case(n, 2, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  3114.  
  3115. s1.setNum(n_barreT);
  3116. complete_case(n, 3, s1, jaune, "#555555", true, tableWidget_lst_notes);
  3117.  
  3118. s1.setNum(n_barreM);
  3119. complete_case(n, 4, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  3120.  
  3121. }
  3122.  
  3123. tableWidget_lst_notes->AdjustToContents;
  3124. affiche_histogramme();
  3125.  
  3126. }
  3127.  
  3128.  
  3129. void MainWindow::affiche_histogramme_durees()
  3130. {
  3131. int x;
  3132. double dy;
  3133. double echelle;
  3134. QBrush br1;
  3135. QString couleur1;
  3136. QString s1;
  3137.  
  3138. effacer_calque(scene5, calque_histogramme);
  3139.  
  3140. GraphicsTextItem = new QGraphicsTextItem("Histogramme des durées \n en nb de barres 1/40s");
  3141. GraphicsTextItem->setFont(QFont("Arial", 12));
  3142. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3143. GraphicsTextItem->setPos(220, -160);
  3144. calque_histogramme->addToGroup(GraphicsTextItem);
  3145.  
  3146. //calcul de la valeur la plus grande
  3147. int total=0;
  3148. for(int n=0; n<=20; n++) // attention à ne pas dépasser la taille de la table...
  3149. {
  3150. dy = table_histogramme_durees[n];
  3151. if (dy > total ) {total = dy;}
  3152. }
  3153. //calcul échelle y
  3154. if (total == 0) {total = 1;}
  3155. echelle = 150.0 / total;
  3156.  
  3157. for(int n=0; n<=30; n++) // attention à ne pas dépasser la taille de la table...
  3158. {
  3159. x = 10*n;
  3160. dy = echelle * table_histogramme_durees[n];
  3161. dy = -dy;
  3162. rect1 = new QGraphicsRectItem(x, 0, 2, dy);
  3163.  
  3164. couleur1="#AAFFFF";
  3165. br1.setStyle(Qt::SolidPattern);
  3166. br1.setColor(QColor(couleur1));
  3167.  
  3168. rect1->setPen(QColor(couleur1));
  3169. rect1->setBrush(br1);
  3170. calque_histogramme->addToGroup(rect1);
  3171.  
  3172. if (n%2 == 0)
  3173. {
  3174. x = -5 + 20*n;
  3175. s1.setNum(n);
  3176. GraphicsTextItem = new QGraphicsTextItem(s1);
  3177. GraphicsTextItem->setFont(QFont("Arial", 10));
  3178. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3179. GraphicsTextItem->setPos(x, 0);
  3180. calque_histogramme->addToGroup(GraphicsTextItem);
  3181. }
  3182. }
  3183. }
  3184.  
  3185.  
  3186.  
  3187. void MainWindow::calcul_histogramme_durees()
  3188. {
  3189. uint16_t n_max = liste_NOTES.length();
  3190. if (n_max == 0) {return;}
  3191.  
  3192. for(int i=0; i<35; i++) { table_histogramme_durees[i]=0; } // RAZ
  3193.  
  3194. for(int n=0; n<n_max; n++) //n_max
  3195. {
  3196. int duree = liste_NOTES[n].n_barreT - liste_NOTES[n-1].n_barreT;
  3197. table_histogramme_durees[duree]++;
  3198. }
  3199. }
  3200.  
  3201.  
  3202. void MainWindow::affiche_histogramme_midi()
  3203. {
  3204.  
  3205. int x;
  3206. double dy;
  3207. double echelle;
  3208. QBrush br1;
  3209. QString couleur1;
  3210. QString s1;
  3211.  
  3212. effacer_calque(scene5, calque_histogramme);
  3213.  
  3214. GraphicsTextItem = new QGraphicsTextItem("Histogramme des notes midi");
  3215. GraphicsTextItem->setFont(QFont("Arial", 12));
  3216. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3217. GraphicsTextItem->setPos(150, -160);
  3218. calque_histogramme->addToGroup(GraphicsTextItem);
  3219.  
  3220. //calcul de la valeur la plus grande
  3221. int total=0;
  3222. for(int n=0; n<=42; n++) // attention à ne pas dépasser la taille de la table...
  3223. {
  3224. dy = table_histogramme_midi[n];
  3225. if (dy > total ) {total = dy;}
  3226. }
  3227. //calcul échelle y
  3228. if (total == 0) {total = 1;}
  3229. echelle = 150.0 / total;
  3230.  
  3231. for(int n=0; n<=40; n++) // 42 attention à ne pas dépasser la taille de la table...
  3232. {
  3233. x = 10*n;
  3234. dy = echelle * table_histogramme_midi[n];
  3235. dy = -dy;
  3236. rect1 = new QGraphicsRectItem(x, 0, 5, dy);
  3237.  
  3238. couleur1="#AAFFFF";
  3239. int h1 = calcul_hauteur_note(n+40);
  3240. QString couleur1 = liste_couleurs[h1];
  3241. br1.setStyle(Qt::SolidPattern);
  3242. br1.setColor(QColor(couleur1));
  3243.  
  3244. rect1->setPen(QColor(couleur1));
  3245. rect1->setBrush(br1);
  3246. calque_histogramme->addToGroup(rect1);
  3247.  
  3248. if (n%2== 0)
  3249. {
  3250. x = -5 + 10*n;
  3251. s1.setNum(n+40);
  3252. GraphicsTextItem = new QGraphicsTextItem(s1);
  3253. GraphicsTextItem->setFont(QFont("Arial", 10));
  3254. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3255. GraphicsTextItem->setPos(x, 0);
  3256. calque_histogramme->addToGroup(GraphicsTextItem);
  3257. }
  3258. }
  3259.  
  3260. }
  3261.  
  3262.  
  3263. void MainWindow::calcul_histogramme_midi()
  3264. {
  3265. for(int i=0; i<42; i++)
  3266. {
  3267. table_histogramme_midi[i]=0; // RAZ
  3268. }
  3269.  
  3270. uint16_t n_max = liste_NOTES.length();
  3271.  
  3272. for(int n=0; n<n_max; n++)
  3273. {
  3274. int M=liste_NOTES[n].midi;
  3275. if ((M>=40)&&(M<=82)) { table_histogramme_midi[M-40]++;}
  3276. }
  3277. }
  3278.  
  3279. /*
  3280. Liste des correspondances en fonction des dièses présents à la clef :
  3281. Pas d'altération : Do Majeur
  3282.  Fa# : Sol Majeur
  3283.  Fa#, Do# -> gamme de Ré Majeur
  3284.  Fa#, Do#, Sol# -> gamme de La Majeur
  3285.  Fa#, Do#, Sol#, Ré# -> gamme de Mi Majeur
  3286.  Fa#, Do#, Sol#, Ré#, La# -> gamme de Si Majeur
  3287.  Fa#, Do#, Sol#, Ré#, La#, Mi# -> gamme de Fa dièse Majeur
  3288.  Fa#, Do#, Sol#, Ré#, La#, Mi#, Si# -> gamme de Do dièse Majeur
  3289. */
  3290.  
  3291.  
  3292. QString MainWindow::denombre_diezes_a_la_cle()
  3293. {
  3294. // FA♯ DO♯ SOL♯ RÉ♯ LA♯ MI♯ SI♯
  3295. // 42 49 56 51 46 53 48 // midi
  3296. // 6 1 8 3 10 5 0 (reportées dans la première octave)
  3297.  
  3298. QString s1, s2;
  3299. int N;
  3300. int FA=0, DO=0, SOL=0, RE=0, LA=0, MI=0, SI=0;
  3301. s1="";
  3302. if (table_histogramme_degre[6] > 0) {FA=1; s1+=" FA#";}
  3303. if ((table_histogramme_degre[1] > 0)&&(FA==1)) {DO=1; s1+= " DO#";}
  3304. if ((table_histogramme_degre[8] > 0)&&(DO==1)) {SOL=1; s1+= " SOL#";}
  3305. if ((table_histogramme_degre[3] > 0)&&(SOL==1)) {RE=1; s1+= " RE#";}
  3306. if ((table_histogramme_degre[10] > 0)&&(RE==1)) {LA=1; s1+= " LA#";}
  3307. if ((table_histogramme_degre[5] > 0)&&(LA==1)) {MI=1; s1+= " MI#";}
  3308. if ((table_histogramme_degre[0] > 0)&&(MI==1)) {SI=1; s1+= " SI#";}
  3309.  
  3310. N = FA+DO+SOL+RE+LA;
  3311. s2.setNum(N);
  3312. s2+=" dièse";
  3313. if (N>1) {s2+="s";}
  3314. s2+=" à la clé " ;
  3315. s2 += s1;
  3316. return s2;
  3317. }
  3318.  
  3319.  
  3320. void MainWindow::affiche_histogramme_degre()
  3321. {
  3322.  
  3323. int y1, y2;
  3324. double dx;
  3325. double echelle;
  3326. QBrush br1;
  3327. QString couleur1;
  3328. QString s1;
  3329.  
  3330. effacer_calque(scene5, calque_histogramme);
  3331.  
  3332. GraphicsTextItem = new QGraphicsTextItem("Histogramme des degrés (gamme chromatique)");
  3333. GraphicsTextItem->setFont(QFont("Arial", 12));
  3334. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3335. GraphicsTextItem->setPos(80, -170);
  3336. calque_histogramme->addToGroup(GraphicsTextItem);
  3337.  
  3338. //calcul de la valeur la plus grande
  3339. int total=0;
  3340. for(int n=0; n<12; n++) // attention à ne pas dépasser la taille de la table...
  3341. {
  3342. dx = table_histogramme_degre[n];
  3343. if (dx > total ) {total = dx;}
  3344. }
  3345. //calcul échelle y
  3346. if (total == 0) {total = 1;}
  3347. echelle = 150.0 / total;
  3348.  
  3349. for(int n=0; n<12; n++)
  3350. {
  3351. y1 = 20 - 10*n;
  3352. dx = echelle * table_histogramme_degre[n];
  3353. if (dx>0)
  3354. {
  3355. rect1 = new QGraphicsRectItem(40, y1, dx, 4);
  3356.  
  3357. couleur1="#AAFFFF";
  3358. int h1 = n;
  3359. QString couleur1 = liste_couleurs[h1];
  3360. br1.setStyle(Qt::SolidPattern);
  3361. br1.setColor(QColor(couleur1));
  3362.  
  3363. rect1->setPen(QColor(couleur1));
  3364. rect1->setBrush(br1);
  3365. calque_histogramme->addToGroup(rect1);
  3366. }
  3367.  
  3368. y2 = 12 - 10*n;
  3369. //s1.setNum(n+1);
  3370. s1=gamme_chromatique[n];
  3371. GraphicsTextItem = new QGraphicsTextItem(s1);
  3372. GraphicsTextItem->setFont(QFont("Arial", 8));
  3373. GraphicsTextItem->setDefaultTextColor(couleur1);
  3374. GraphicsTextItem->setPos(0, y2);
  3375. calque_histogramme->addToGroup(GraphicsTextItem);
  3376.  
  3377. }
  3378.  
  3379. s1 = denombre_diezes_a_la_cle();
  3380. Etiquette(10, -140, 0, s1, "#FFFF00", "#000000", "#FFFFFF", calque_histogramme );
  3381.  
  3382.  
  3383. }
  3384.  
  3385.  
  3386.  
  3387. void MainWindow::calcul_histogramme_degre() // degres de la gamme chromatique (= 1..12 )
  3388. {
  3389. for(int n=0; n<12; n++)
  3390. {
  3391. table_histogramme_degre[n]=0; // RAZ
  3392. }
  3393.  
  3394. uint16_t n_max = liste_NOTES.length();
  3395.  
  3396. for(int n=0; n<n_max; n++)
  3397. {
  3398. int M=liste_NOTES[n].midi;
  3399. if ((M>=40)&&(M<=82))
  3400. {
  3401. //int midi = M-40;
  3402. int H = calcul_hauteur_note(M);
  3403. table_histogramme_degre[H]++;
  3404. }
  3405. }
  3406. }
  3407.  
  3408.  
  3409. void MainWindow::affiche_histogramme()
  3410. {
  3411. if(radioButton_D->isChecked())
  3412. {
  3413. calcul_histogramme_durees();
  3414. affiche_histogramme_durees();
  3415. }
  3416. if(radioButton_M->isChecked())
  3417. {
  3418. calcul_histogramme_midi();
  3419. affiche_histogramme_midi();
  3420. }
  3421. if(radioButton_H->isChecked())
  3422. {
  3423. calcul_histogramme_degre();
  3424. affiche_histogramme_degre();
  3425. }
  3426. }
  3427.  
  3428.  
  3429.  
  3430. void MainWindow::trace_liste_notes() //dessine des cercles colorés (couleur midi) sur la grille
  3431. {
  3432. effacer_calque(scene4,calque_notes_manuelles);
  3433.  
  3434. QString s1;
  3435. int db, midi_i;
  3436. double x, y; //,dx, dbx, dy;
  3437. int numero;
  3438. uint16_t n_max = liste_NOTES.length();
  3439. int n_barre_1;
  3440. int x0a = spinBox_x0a->value();
  3441. double x0b = 10.0 * doubleSpinBox_x0b->value();
  3442. x0b += 20.0 * x0a;
  3443. QString blanc = "#FFFFFF";
  3444. QString jaune = "#FFFF00";
  3445. QString cyan = "#00FFFF";
  3446.  
  3447. for(int n=0; n<n_max; n++)
  3448. {
  3449. n_barre_1=0;
  3450. if (mode=='T') {n_barre_1 = liste_NOTES[n].n_barreT; }
  3451. if (mode=='M') {n_barre_1 = liste_NOTES[n].n_barreM; }
  3452. x = calcul_x_barre(n_barre_1);
  3453. midi_i = liste_NOTES[n].midi;
  3454.  
  3455. if ((midi_i >=40) && (midi_i <=83) )
  3456. {
  3457. y = calcul_y_note(midi_i);
  3458. int h1 = calcul_hauteur_note(midi_i);
  3459. QString couleur1 = liste_couleurs[h1];
  3460. ellipse1 = new QGraphicsEllipseItem(x-10, y-10, 20, 20);
  3461. if (mode=='T') {ellipse1->setPen(QColor(jaune));}
  3462. if (mode=='M') {ellipse1->setPen(QColor(blanc));}
  3463. ellipse1->setBrush(QColor(couleur1));
  3464. calque_notes_manuelles->addToGroup(ellipse1);
  3465.  
  3466. // inscrit le numéro de la note au centre de la note
  3467. numero = liste_NOTES[n].numero;
  3468. s1.setNum(numero);
  3469. GraphicsTextItem = new QGraphicsTextItem(s1);
  3470. GraphicsTextItem->setFont(QFont("Arial", 8));
  3471. GraphicsTextItem->setDefaultTextColor("#000000");
  3472. int x2 = x-12; if(numero<10){x2+=4;}
  3473. GraphicsTextItem->setPos(x2, y-10);
  3474. calque_notes_manuelles->addToGroup(GraphicsTextItem);
  3475. }
  3476. }
  3477. tracer_echelle_temps_TAB_NOTES();
  3478. }
  3479.  
  3480.  
  3481. void MainWindow::numerotation_liste_notes()
  3482. {
  3483. uint16_t i_max = liste_NOTES.length();
  3484.  
  3485. for(uint16_t n=0; n<i_max; n++)
  3486. {
  3487. liste_NOTES[n].numero = n;
  3488. }
  3489. }
  3490.  
  3491.  
  3492. void MainWindow::suppression_notes_invalides()
  3493. {
  3494. int midi;
  3495. int nb = 0;
  3496. uint16_t n_max = liste_NOTES.length();
  3497. if (n_max == 0) {return;}
  3498. bool boucler=true;
  3499. do
  3500. {
  3501. nb=0;
  3502. for(uint16_t n=0; n<n_max; n++)
  3503. {
  3504. midi = liste_NOTES[n].midi;
  3505. if ((midi <40) || (midi>82))
  3506. {
  3507. supprime_note(n);
  3508. if (n_max == 0) {return;}
  3509. n_max --;
  3510. nb++;
  3511. }
  3512. }
  3513. if (nb==0) {boucler=false;}
  3514. }
  3515. while (boucler == true);
  3516. }
  3517.  
  3518.  
  3519. void MainWindow::suppression_mesures()
  3520. {
  3521. //int midi;
  3522. uint16_t n_max = liste_NOTES.length();
  3523. int nb = 0;
  3524.  
  3525. bool boucler=true;
  3526. do
  3527. {
  3528. nb=0;
  3529. for(int n=0; n<n_max; n++)
  3530. {
  3531. //midi = liste_NOTES[n].midi;
  3532. /*
  3533.   if (midi == 100) // midi=100 codera pour les barres de mesures
  3534.   {
  3535.   supprime_note(n);
  3536.   n_max --;
  3537.   nb++;
  3538.   }
  3539. */
  3540. }
  3541. if (nb==0) {boucler=false;}
  3542. }
  3543. while (boucler == true);
  3544.  
  3545. }
  3546.  
  3547.  
  3548.  
  3549. void MainWindow::tri_liste_notes_par_num_barre()
  3550. {
  3551.  
  3552. // tri par bulles
  3553.  
  3554. int ba1, ba2; // barres
  3555. NOTE note_i;
  3556. uint16_t i_max = liste_NOTES.length();
  3557. if (i_max==0){return;}
  3558.  
  3559. for(int p=0; p<i_max; p++)
  3560. {
  3561. for(int n=0; n<i_max-1; n++)
  3562. {
  3563. if(mode=='T')
  3564. {
  3565. ba1=liste_NOTES[n].n_barreT;
  3566. ba2=liste_NOTES[n+1].n_barreT;
  3567. }
  3568. if(mode=='M')
  3569. {
  3570. ba1=liste_NOTES[n].n_barreM;
  3571. ba2=liste_NOTES[n+1].n_barreM;
  3572. }
  3573.  
  3574. if(ba1 > ba2)
  3575. {
  3576. //permutter les notes
  3577. note_i = liste_NOTES[n];
  3578. liste_NOTES[n] = liste_NOTES[n+1];
  3579. liste_NOTES[n+1] = note_i;
  3580. }
  3581. }
  3582. }
  3583. }
  3584.  
  3585.  
  3586.  
  3587. void MainWindow::ajout_note(int midi, int n_barreT, int n_barreM)
  3588. {
  3589. // ajout d'une note à la fin de la liste 'liste_NOTES[]'
  3590. NOTE note_i;
  3591. note_i.midi = midi;
  3592. note_i.n_barreT = n_barreT; // valeur discrète, entière : numéro de la barre de la grille temporelle
  3593. note_i.n_barreM = n_barreM;
  3594. liste_NOTES << note_i;
  3595. }
  3596.  
  3597.  
  3598. void MainWindow::deplace_note(int n, int d)
  3599. {
  3600. if (n<=0) {return;}
  3601. if (n >= liste_NOTES.length()) {return;}
  3602. NOTE note_i;
  3603. note_i = liste_NOTES[n];
  3604. if (mode == 'T') { note_i.n_barreT = note_i.n_barreT+d; }
  3605. if (mode == 'M') { note_i.n_barreM = note_i.n_barreM+d; }
  3606. liste_NOTES[n] = note_i;
  3607. }
  3608.  
  3609.  
  3610.  
  3611. void MainWindow::supprime_note(uint16_t n)
  3612. {
  3613. int L = liste_NOTES.length();
  3614. if (L==0) {return;}
  3615.  
  3616. if (n<L)
  3617. {
  3618. liste_NOTES.remove(n);
  3619. effacer_calque(scene4, calque_notes_manuelles);
  3620. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  3621.  
  3622. numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  3623.  
  3624. trace_liste_notes();
  3625. }
  3626. }
  3627.  
  3628.  
  3629.  
  3630. int MainWindow::test_if_note_in_liste(uint16_t n_barre, int midi)
  3631. {
  3632. // retourne la position dans la liste, sinon zéro;
  3633. uint16_t barre_i=0;
  3634. int midi_i;
  3635. int i_max = liste_NOTES.length();
  3636. for(int n=0; n<i_max; n++)
  3637. {
  3638. if(mode=='T') {barre_i = liste_NOTES[n].n_barreT;}
  3639. if(mode=='M') {barre_i = liste_NOTES[n].n_barreM;}
  3640.  
  3641. midi_i = liste_NOTES[n].midi;
  3642.  
  3643. int diff_n = abs(barre_i-n_barre);
  3644. if ((diff_n ==0) && (midi_i == midi))
  3645. {
  3646. return n;
  3647. }
  3648. }
  3649. return -1;
  3650. }
  3651.  
  3652.  
  3653. uint16_t MainWindow::calcul_n_barreM_note(uint16_t n)
  3654. //numero de la barre M la plus proche de la note posée sur une barre T
  3655. {
  3656. uint16_t nT = liste_NOTES[n].n_barreT;
  3657. mode='T';
  3658. int xT = calcul_x_barre(nT);
  3659.  
  3660. int trouve = 0;
  3661. int16_t i =-250;
  3662.  
  3663. mode='M';
  3664.  
  3665. // int x0a = spinBox_x0a->value();
  3666. // double x0b = 10.0 * doubleSpinBox_x0b->value();
  3667. // x0b += 20.0 * x0a;
  3668.  
  3669. while ((trouve == 0) && (i<250))
  3670. {
  3671. double xi = calcul_x_barre(i);
  3672. double diff = xT - xi;
  3673. if(diff<0)diff = -diff;
  3674. //qDebug() << "diff" << diff;
  3675.  
  3676. if(diff < calcul_pas_grille() /2 )
  3677. {
  3678. trouve = 1;
  3679. }
  3680. i++;
  3681. }
  3682. if (trouve == 0) {i=1;}
  3683. mode='T';
  3684. return i-1;
  3685. }
  3686.  
  3687.  
  3688. uint16_t MainWindow::calcul_n_barreT_note(uint16_t n)
  3689. {
  3690. //numero de la barre T la plus proche de la note posée sur une barre M
  3691. //toutefois cette fonction est à revoir, HS telle-quelle !
  3692.  
  3693. uint16_t nM = liste_NOTES[n].n_barreM;
  3694. mode='M';
  3695. int xM = calcul_x_barre(nM);
  3696.  
  3697.  
  3698. int trouve = 0;
  3699. int16_t i = -500;
  3700. //spinBox_x0a->setValue(0);
  3701.  
  3702. mode='T';
  3703. double pas_T = calcul_pas_grille();
  3704. while ((trouve == 0) && (i<2000))
  3705. {
  3706.  
  3707. double xi = calcul_x_barre(i);
  3708. if (xi>0)
  3709. {
  3710. double diff = xM - xi;
  3711. if(diff<0)diff = -diff;
  3712. if(diff < (pas_T /2) )
  3713. {
  3714. trouve = 1;
  3715. }
  3716. }
  3717. i++;
  3718. }
  3719. if (trouve == 0) {i=1;}
  3720. mode='M';
  3721. return i-1;
  3722. }
  3723.  
  3724.  
  3725.  
  3726. void MainWindow::affi_txt_en_couleur(int midi_i, QLineEdit *lineEdit_i)
  3727. {
  3728. int h1 = calcul_hauteur_note(midi_i);
  3729.  
  3730. QString c1 = liste_couleurs[h1];
  3731. QString c2 = "#000000";
  3732. lineEdit_i->setStyleSheet("color: " + c1 + "; background-color: " + c2 + "; font: 700 14pt 'Ubuntu';");
  3733. }
  3734.  
  3735.  
  3736.  
  3737. void MainWindow::encadre_midi(int n_midi) // dans la liste des notes à gauche
  3738. {
  3739. if (n_midi>82) {return;}
  3740.  
  3741. effacer_calque(scene3, calque_gradu_TAB_FRQ);
  3742. tracer_graduation_TAB_NOTES();
  3743. double x, dx, y, dy;
  3744.  
  3745. int dm = n_midi -40;
  3746. y = 645 - (dm * 16);
  3747.  
  3748. dy=16;
  3749. x=0;
  3750. dx=85;
  3751.  
  3752. rectangle1 = new QGraphicsRectItem(x, y, dx, dy);
  3753. QPen pen1;
  3754. pen1.setColor("#FFFFFF");
  3755. pen1.setWidth(2);
  3756. rectangle1->setPen(pen1);
  3757. calque_gradu_TAB_FRQ->addToGroup(rectangle1);
  3758. }
  3759.  
  3760.  
  3761. int MainWindow::num_barre(double xi) // en fonction de la position x
  3762. {
  3763. //double pas_grille = spinBox_dxa->value()/2.0 * zoom_x; // pas de la grille
  3764. //double offset_grille = 0; //75;
  3765. //double x_barre = offset_grille; //0
  3766.  
  3767. int n_barre=0; // numero de la barre verticale de la grille T temporelle (depuis le départ)
  3768. double x_barre=0;
  3769. bool trouve = false; // à priori
  3770. int n =-1;
  3771. while ((n<2000) && (trouve == false))
  3772. {
  3773. double dx2 = xi- x_barre;
  3774. if (dx2<0) {dx2 = -dx2;}
  3775.  
  3776. if (dx2 < calcul_pas_grille()/2.0)
  3777. {
  3778. trouve = true;
  3779. n_barre = n; // numero de la barre verticale de la grille temporelle
  3780. }
  3781. x_barre = calcul_x_barre(n+1);
  3782. n++;
  3783. }
  3784.  
  3785. if (trouve == false) {return -1;}
  3786. if (n==0) {return -1;}
  3787.  
  3788. qDebug() << "n_barre" << n_barre;
  3789. return n_barre;
  3790. }
  3791.  
  3792.  
  3793.  
  3794. void MainWindow::mousePressEvent(QMouseEvent *event)
  3795. {
  3796. if(event->button() == Qt::RightButton) {return;}
  3797.  
  3798. qDebug() << "clic de gauche";
  3799.  
  3800. if (tabWidget_Global->currentIndex() != 1) {return;}
  3801.  
  3802. QString s1;
  3803. double x0, y0; // position cliquée
  3804.  
  3805. int n_barre=0; // numero de la barre verticale de la grille temporelle (depuis le départ)
  3806. int n2=0;
  3807.  
  3808. //double x_barre=0;
  3809. double x_min, x_max;
  3810. double y_min, y_max;
  3811.  
  3812. int midi=0; // midi
  3813.  
  3814. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  3815. double scroll_y = graphicsView4->verticalScrollBar()->value();
  3816.  
  3817. graphicsView4->verticalScrollBar()->setValue(0);
  3818.  
  3819. s1.setNum(scroll_x); lineEdit_8->setText(s1);
  3820. s1.setNum(scroll_y); lineEdit_9->setText(s1);
  3821.  
  3822. x_min = graphicsView4->x();
  3823. x_max = x_min + graphicsView4->width();
  3824.  
  3825. y_min = graphicsView4->y()+60;
  3826. y_max = y_min + graphicsView4->height() + 32; // +32 sinon rate le mi grave (midi 40)
  3827.  
  3828. x_clic_ecran = event->position().x();
  3829. y_clic_ecran = event->position().y();
  3830.  
  3831. x0 = x_clic_ecran-102 + scroll_x; // position cliquée
  3832. y0 = y_clic_ecran-78 + scroll_y;
  3833.  
  3834.  
  3835. // ----------------------
  3836.  
  3837. if (x_clic_ecran > x_min && x_clic_ecran < x_max && y_clic_ecran > y_min && y_clic_ecran < y_max)
  3838. {
  3839. s1.setNum(x0); lineEdit_4->setText(s1);
  3840. s1.setNum(y0); lineEdit_5->setText(s1); // =481 foire !
  3841.  
  3842. // recherche (verticale) de la note midi la plus proche du point cliqué
  3843. int dm =0;
  3844. for(int n=0; n<=43; n++)
  3845. {
  3846. int d1= (700-y0) - 16*n; // 704
  3847. //d1=abs(d1);
  3848. if(d1<0){d1= -d1;}
  3849.  
  3850. if(d1 <= 8) // 8 sachant que l'espacement (vertical) de niveaux est = 16
  3851. {
  3852. dm = n;
  3853. }
  3854. }
  3855.  
  3856. // calcul de la valeur midi de la note
  3857. midi = 40 + dm;
  3858. encadre_midi(midi);
  3859.  
  3860. n_barre = num_barre(x0);
  3861.  
  3862. if (n_barre == -1) {return;}
  3863.  
  3864. s1.setNum(midi);
  3865. lineEdit_7->setText(s1);
  3866.  
  3867. affi_txt_en_couleur(midi, lineEdit_7b);
  3868. lineEdit_7b->setText(nom_note(midi));
  3869.  
  3870. affi_txt_en_couleur(midi, lineEdit_7e);
  3871. QString s1;
  3872.  
  3873. s1=nom_note_GB(midi);
  3874. s1+=nom_octave_GB(midi);
  3875. lineEdit_7e->setText(s1);
  3876.  
  3877. double F = freq_mid(midi);
  3878. s1.setNum(F);
  3879. s1.replace('.',','); // ce qui permet un copié-collé direct dans 'Adacity'
  3880. lineEdit_7d->setText(s1);
  3881.  
  3882. n2 = test_if_note_in_liste(n_barre, midi); // si note in liste, -> n2 = num de la note
  3883. if (n2 != -1) { QString s1; s1.setNum(n2); lineEdit_7c->setText(s1); }
  3884.  
  3885.  
  3886. if (write_mode == 3) // SELECT
  3887. {
  3888. n2 = test_if_note_in_liste(n_barre, midi);
  3889. if (n2 != -1) // si la note figure dans la liste...
  3890. {
  3891. effacer_calque(scene4, calque_notes_jouee);
  3892. num_note_cliquee = n2;
  3893. surbrille_note(n2);
  3894. }
  3895. }
  3896.  
  3897. play_note(midi);
  3898.  
  3899. if (write_mode == 1) // WRITE (ajout d'une note)
  3900. {
  3901. n2 = test_if_note_in_liste(n_barre, midi);
  3902. if (n2 == -1) // si la note ne figure pas déjà dans la liste...
  3903. {
  3904. // enregistre la note dans la liste (à la fin)
  3905. if(mode=='T') {ajout_note(midi, n_barre, 0);}
  3906. if(mode=='M') {ajout_note(midi, 0, n_barre);}
  3907. }
  3908. }
  3909.  
  3910. if (write_mode == 2) // EFFACE
  3911. {
  3912. n2 = test_if_note_in_liste(n_barre, midi);
  3913. if (n2 != -1) // si la note figure dans la liste...
  3914. {
  3915. supprime_note(n2);
  3916. }
  3917. }
  3918.  
  3919.  
  3920. if (mode_select == true)
  3921. {
  3922. n2 = test_if_note_in_liste(n_barre, midi);
  3923. if (n2 != -1) // si la note figure dans la liste...
  3924. {
  3925. effacer_calque(scene4, calque_notes_jouee);
  3926. num_note_cliquee = n2;
  3927. surbrille_note(n2);
  3928. }
  3929. }
  3930.  
  3931. }
  3932. //int h1 = calcul_hauteur_note(midi);
  3933. //QColor couleur1 = liste_couleurs[h1];
  3934.  
  3935. effacer_calque(scene4,calque_notes_manuelles);
  3936. tri_liste_notes_par_num_barre(); // les notes seront triées par num_barre croissant
  3937. numerotation_liste_notes(); // les notes seront numérotées par num_barre croissant
  3938. affiche_liste_notes();
  3939. trace_liste_notes();
  3940.  
  3941. if (0) // 1 pour test (affiche une petite croix)
  3942. {
  3943. int d=10; // taille
  3944. QPen pen1; pen1.setColor("#FFFF00");
  3945. ligne1 = new QGraphicsLineItem(x0-d, y0-d, x0+d, y0+d);
  3946. ligne1->setPen(pen1);
  3947. calque_notes_manuelles->addToGroup(ligne1);
  3948. ligne1 = new QGraphicsLineItem(x0-d, y0+d, x0+d, y0-d);
  3949. ligne1->setPen(pen1);
  3950. calque_notes_manuelles->addToGroup(ligne1);
  3951. }
  3952.  
  3953. }
  3954.  
  3955.  
  3956. void MainWindow::contextMenuEvent(QContextMenuEvent *event)
  3957. //declenche le menu contextuel lors du clic de droite
  3958. {
  3959. qDebug() << "clic de droite";
  3960. return;
  3961.  
  3962. }
  3963.  
  3964.  
  3965. int MainWindow::joue_1_note_de_la_liste()
  3966. {
  3967. NOTE note_i1, note_i2;
  3968. int midi_i;
  3969. int barre1=0;
  3970. int barre2=0;
  3971. int d_barre;
  3972. QString s1;
  3973.  
  3974. QDateTime tpi;
  3975. tpi = QDateTime::currentDateTime();
  3976. qint64 tp_relatif = temps_0.msecsTo(tpi); // en ms
  3977. s1.setNum(tp_relatif);
  3978.  
  3979. uint16_t num_max = liste_NOTES.length();
  3980. if (num_max == 0) {return 0;}
  3981. if (num_max < 3) {return 0;}
  3982.  
  3983.  
  3984. if (num_note_jouee >= (num_max))
  3985. {
  3986. on_Bt_stop_clicked();
  3987. return 0;
  3988. }
  3989. note_i1 = liste_NOTES[num_note_jouee];
  3990. note_i2 = liste_NOTES[num_note_jouee+1];
  3991.  
  3992. if(mode == 'T')
  3993. {
  3994. barre1 = note_i1.n_barreT;
  3995. barre2 = note_i2.n_barreT;
  3996. }
  3997. if(mode == 'M')
  3998. {
  3999. barre1 = note_i1.n_barreM;
  4000. barre2 = note_i2.n_barreM;
  4001. }
  4002.  
  4003. if (barre1 == barre2) // detection d'un accord (notes simultanées)
  4004. {
  4005. surbrille_note(num_note_jouee);
  4006. surbrille_note(num_note_jouee+1);
  4007. nb_acc++;
  4008. }
  4009. else
  4010. {
  4011. if (nb_acc == 0) {effacer_calque(scene4, calque_notes_jouee);}
  4012. surbrille_note(num_note_jouee);
  4013. nb_acc--; if (nb_acc<0) {nb_acc=0;}
  4014. }
  4015.  
  4016. d_barre = barre2 - barre1;
  4017. if (d_barre < 0){d_barre = -d_barre;}
  4018.  
  4019. midi_i=note_i1.midi;
  4020.  
  4021. s1.setNum(num_note_jouee); lineEdit_7c->setText(s1);
  4022. lineEdit_7->setText("");
  4023. lineEdit_7b->setText("");
  4024.  
  4025.  
  4026. s1.setNum(midi_i) ;
  4027.  
  4028. if ( ! (checkBox_basses->isChecked() && midi_i > spinBox_filtre_2->value() ))
  4029. {
  4030. play_note(midi_i);
  4031. encadre_midi(midi_i);
  4032. }
  4033.  
  4034. num_note_jouee++;
  4035. if(num_note_jouee > num_note_max)
  4036. {
  4037. Timer2->stop();
  4038. num_note_jouee=0;
  4039. }
  4040.  
  4041. return d_barre; // permet de retrouver l'espacement temporel entre la note et celle qui suit.
  4042. }
  4043.  
  4044.  
  4045.  
  4046.  
  4047. void MainWindow::on_Bt_toggle_grille_T_clicked()
  4048. {
  4049. mode = 'T';
  4050. Bt_toggle_grille_T->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4051. Bt_toggle_grille_M->setStyleSheet("background-color: rgb(200, 200, 200);");
  4052. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4053. numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  4054. affiche_liste_notes();
  4055. mode_grille_T();
  4056. trace_liste_notes();
  4057. effacer_calque(scene4, calque_echelle_temporelle);
  4058. //effacer_calque(scene4, calque_grille_M);
  4059. }
  4060.  
  4061.  
  4062. void MainWindow::on_Bt_toggle_visu_notes_clicked()
  4063. {
  4064. if(visu_notes == true)
  4065. {
  4066. visu_notes = false;
  4067. Bt_toggle_visu_notes->setStyleSheet("background-color: rgb(200, 200, 200);");
  4068. effacer_calque(scene4, calque_notes_manuelles);
  4069. }
  4070. else
  4071. {
  4072. visu_notes = true;
  4073. Bt_toggle_visu_notes->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4074. trace_liste_notes();
  4075. }
  4076. }
  4077.  
  4078.  
  4079.  
  4080.  
  4081. void MainWindow::on_Bt_toggle_grille_M_clicked()
  4082. {
  4083. mode = 'M';
  4084. Bt_toggle_grille_M->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4085. Bt_toggle_grille_T->setStyleSheet("background-color: rgb(200, 200, 200);");
  4086. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4087. numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  4088. affiche_liste_notes();
  4089. mode_grille_M();
  4090. trace_liste_notes();
  4091. }
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097. void MainWindow::mode_grille_T()
  4098. {
  4099. effacer_calque(scene4, calque_grille_T);
  4100. effacer_calque(scene4, calque_grille_M);
  4101.  
  4102. frame_7->setVisible(true);
  4103. spinBox_dxa->setVisible(false);
  4104. doubleSpinBox_dxb->setVisible(false);
  4105. spinBox_x0a->setVisible(false);
  4106. doubleSpinBox_x0b->setVisible(false);
  4107.  
  4108. tracer_grille_T();
  4109. }
  4110.  
  4111.  
  4112.  
  4113. void MainWindow::mode_grille_M()
  4114. {
  4115. effacer_calque(scene4, calque_grille_T);
  4116. effacer_calque(scene4, calque_grille_M);
  4117.  
  4118. frame_7->setVisible(false);
  4119.  
  4120. spinBox_dxa->setVisible(true);
  4121. doubleSpinBox_dxb->setVisible(true);
  4122. spinBox_x0a->setVisible(true);
  4123. doubleSpinBox_x0b->setVisible(true);
  4124.  
  4125. tracer_grille_M();
  4126. }
  4127.  
  4128.  
  4129.  
  4130. void MainWindow::on_Bt_save_notes_clicked()
  4131. {
  4132. int r1, r2;
  4133.  
  4134. QDate date_systeme = QDate::currentDate();
  4135. QTime heure_systeme = QTime::currentTime();
  4136.  
  4137. QString date1 = date_systeme.toString("yyyyMMdd");
  4138. QString heure1 = heure_systeme.toString();
  4139. QString date_out = date1 + "_" + heure1;
  4140.  
  4141. r1 = save_fichier_NOTES(date_out);
  4142. r2 = save_fichier_FRQ(date_out);
  4143.  
  4144. if ((r1 + r2) != 2) // si = 2 -> aucun fichier enregistré, alors on n'affiche pas le message
  4145. {
  4146. QMessageBox msgBox;
  4147. QString s1="Fichiers enregistrés dans : \n" + string_currentDir + "/";
  4148. msgBox.setText(s1); msgBox.exec();
  4149. }
  4150. }
  4151.  
  4152.  
  4153.  
  4154. void MainWindow::on_Bt_load_notes_clicked()
  4155. {
  4156. uint16_t n_max = liste_NOTES.length();
  4157. if (n_max != 0) // pour éviter d'enregistrer un fichier vide lors du 1er chargement des notes
  4158. {
  4159. QMessageBox msgBox;
  4160.  
  4161. msgBox.setText("Confirmation de chargement");
  4162. msgBox.setInformativeText("Un enregistrement des notes va être effectué au préalable.\n \n"
  4163. "Si clic sur No, les notes actuelles seront perdues.\n \n"
  4164. "Si clic sur Cancel, opération annulée");
  4165.  
  4166. msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Ok | QMessageBox::Cancel);
  4167. msgBox.setDefaultButton(QMessageBox::Cancel);
  4168. int ret = msgBox.exec();
  4169. if (ret == QMessageBox::Cancel ) { return; }
  4170. if (ret == QMessageBox::Ok ) { on_Bt_save_notes_clicked(); }
  4171. }
  4172.  
  4173. liste_NOTES.clear();
  4174. effacer_calque(scene4,calque_notes_manuelles);
  4175. effacer_calque(scene4,calque_notes_auto);
  4176. effacer_calque(scene4,calque_notes_jouee);
  4177. effacer_calque(scene5, calque_histogramme );
  4178. effacer_calque(scene4, calque_echelle_temporelle);
  4179. load_fichier_NOTES();
  4180.  
  4181. suppression_notes_invalides();
  4182.  
  4183. // calcul_histogramme_durees();
  4184. // affiche_histogramme_durees();
  4185. on_Bt_toggle_grille_M_clicked();
  4186. }
  4187.  
  4188.  
  4189. void MainWindow::on_Bt_joue_passage_clicked()
  4190. {
  4191. if (liste_NOTES.length() == 0) {return;}
  4192.  
  4193. if (Timer2->isActive())
  4194. {
  4195. Timer2->stop();
  4196. return;
  4197. }
  4198.  
  4199. Timer2->start(500);
  4200.  
  4201. int note_de_depart = spinBox_10->value();
  4202. int nb_notes_a_jouer = spinBox_11->value()-1;
  4203.  
  4204. num_note_jouee = note_de_depart;
  4205. num_note_max = note_de_depart + nb_notes_a_jouer;
  4206. if (num_note_max > liste_NOTES.length()-1) { num_note_max = liste_NOTES.length()-1;}
  4207.  
  4208. NOTE note_i = liste_NOTES[note_de_depart];
  4209. double x_note = 80 + note_i.n_barreT * spinBox_dxa->value()/2.0 * zoom_x;
  4210. // graphicsView4->horizontalScrollBar()->setValue(x_note - 100);
  4211.  
  4212. Timer2->start(500);
  4213. }
  4214.  
  4215.  
  4216. void MainWindow::on_Bt_joue_wav_clicked()
  4217. {
  4218. QStringList arguments;
  4219. arguments << string_currentFile;
  4220. QString program = "audacity"; //"audacious"
  4221. QProcess *myProcess = new QProcess();
  4222. myProcess->start(program, arguments);
  4223. }
  4224.  
  4225.  
  4226.  
  4227. void MainWindow::on_Bt_joue_wav_2_clicked()
  4228. {
  4229. on_Bt_joue_wav_clicked();
  4230. }
  4231.  
  4232.  
  4233. void MainWindow::on_Btn_RAZ_notes_clicked()
  4234. {
  4235. QMessageBox msgBox;
  4236. msgBox.setText("Erase notes");
  4237. msgBox.setInformativeText("Effacer toutes les notes ?");
  4238. msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
  4239. msgBox.setDefaultButton(QMessageBox::Cancel);
  4240. int ret = msgBox.exec();
  4241.  
  4242. if (ret == QMessageBox::Ok )
  4243. {
  4244. liste_NOTES.clear();
  4245. effacer_calque(scene4,calque_notes_manuelles);
  4246. effacer_calque(scene4, calque_notes_auto);
  4247. affiche_liste_notes();
  4248. }
  4249. }
  4250.  
  4251.  
  4252. void MainWindow::on_Bt_stop_clicked()
  4253. {
  4254. num_note_depart = 0;
  4255. num_note_jouee=0;
  4256. Timer2->stop();
  4257. Timer2->setInterval(0);
  4258. lecture_en_cours == false;
  4259. Bt_jouer_tout->setText("Jouer tout");
  4260. num_barre_en_cours=0;
  4261. }
  4262.  
  4263.  
  4264. void MainWindow::on_spinBox_8_textChanged()
  4265. {
  4266. effacer_calque(scene4, calque_echelle_temporelle);
  4267. tracer_echelle_temps_TAB_NOTES();
  4268. }
  4269.  
  4270.  
  4271. void MainWindow::on_doubleSpinBox_x0_valueChanged(double arg1)
  4272. {
  4273.  
  4274. //double pas_grille = spinBox_dt->value()/2.0 * zoom_x;
  4275. //double offset_x = 10 * arg1 + spinBox_d_barres->value() * pas_grille;
  4276. // calque_TAB_FRQ->setPos(offset_x, 0);
  4277. // calque_notes_auto->setPos(offset_x, 0);
  4278.  
  4279. effacer_calque(scene4, calque_grille_M);
  4280. tracer_grille_M();
  4281. // effacer_calque(scene4, calque_notes_manuelles);
  4282. // affiche_liste_notes();
  4283. // trace_liste_notes();
  4284. // effacer_calque(scene4, calque_echelle_temporelle);
  4285. // tracer_echelle_temps_TAB_NOTES();
  4286. }
  4287.  
  4288.  
  4289. void MainWindow::on_spinBox_dxa_valueChanged(int arg1)
  4290. {
  4291. //doubleSpinBox_dxb->setValue(0);
  4292. effacer_calque(scene4, calque_echelle_temporelle);
  4293. effacer_calque(scene4, calque_grille_M);
  4294. tracer_grille_M();
  4295. //effacer_calque(scene4, calque_notes_manuelles);
  4296. //affiche_liste_notes();
  4297. //trace_liste_notes();
  4298.  
  4299. // tracer_echelle_temps_TAB_NOTES();
  4300. if (visu_notes == true) {trace_liste_notes();}
  4301. }
  4302.  
  4303.  
  4304. void MainWindow::on_doubleSpinBox_dxb_valueChanged(double arg1)
  4305. {
  4306. effacer_calque(scene4, calque_grille_M);
  4307. effacer_calque(scene4, calque_echelle_temporelle);
  4308.  
  4309. //effacer_calque(scene4, calque_notes_manuelles);
  4310. //affiche_liste_notes();
  4311. //trace_liste_notes();
  4312.  
  4313. tracer_echelle_temps_TAB_NOTES();
  4314. if (visu_notes == true) {trace_liste_notes();}
  4315. tracer_grille_M();
  4316. }
  4317.  
  4318.  
  4319. void MainWindow::on_Bt_mode_R_clicked()
  4320. {
  4321. write_mode=0;
  4322. mode_select=false;
  4323. MainWindow::setCursor(Qt::ArrowCursor);
  4324. Bt_mode_R->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4325. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4326. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4327. Bt_deplace_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4328. Bt_deplace_L->setStyleSheet("background-color: rgb(200, 200, 200);");
  4329. }
  4330.  
  4331.  
  4332. void MainWindow::on_Bt_mode_W_clicked()
  4333. {
  4334. write_mode=1;
  4335. mode_select=false;
  4336. //MainWindow::setCursor(Qt::SplitHCursor);
  4337. Bt_mode_W->setStyleSheet("background-color: rgb(255, 0, 0);"); // rouge
  4338. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4339. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4340. Bt_deplace_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4341. Bt_deplace_L->setStyleSheet("background-color: rgb(200, 200, 200);");
  4342. }
  4343.  
  4344.  
  4345. void MainWindow::on_Bt_mode_E_clicked()
  4346. {
  4347. write_mode=2;
  4348. mode_select=false;
  4349. //MainWindow::setCursor(Qt::SplitHCursor);
  4350. Bt_mode_E->setStyleSheet("background-color: rgb(0, 200, 200);"); // cyan
  4351. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4352. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4353. Bt_deplace_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4354. Bt_deplace_L->setStyleSheet("background-color: rgb(200, 200, 200);");
  4355. }
  4356.  
  4357.  
  4358.  
  4359. void MainWindow::on_Bt_deplace_L_clicked()
  4360. {
  4361. write_mode=3;
  4362. Bt_deplace_L->setStyleSheet("background-color: rgb(200, 200, 0);"); // jaune
  4363. Bt_deplace_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4364. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4365. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4366. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4367.  
  4368. effacer_calque(scene4, calque_notes_manuelles);
  4369. effacer_calque(scene4, calque_notes_jouee);
  4370. deplace_note(num_note_cliquee, -1);
  4371. affiche_liste_notes();
  4372. trace_liste_notes();
  4373. }
  4374.  
  4375.  
  4376. void MainWindow::on_Bt_deplace_R_clicked()
  4377. {
  4378. write_mode=3;
  4379. Bt_deplace_R->setStyleSheet("background-color: rgb(200, 200, 0);"); // jaune
  4380. Bt_deplace_L->setStyleSheet("background-color: rgb(200, 200, 200);");
  4381. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4382. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4383. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4384.  
  4385. effacer_calque(scene4, calque_notes_manuelles);
  4386. effacer_calque(scene4, calque_notes_jouee);
  4387.  
  4388. deplace_note(num_note_cliquee, 1);
  4389. affiche_liste_notes();
  4390. trace_liste_notes();
  4391. }
  4392.  
  4393.  
  4394. void MainWindow::on_Bt_scan_auto_clicked()
  4395. {
  4396. if (! wav_ok) {return;}
  4397. if ( ! liste_ENR_FFT.isEmpty()) {on_Bt_efface_clicked();}
  4398.  
  4399. on_Bt_toggle_visu_notes_clicked();
  4400.  
  4401. if (rapide)
  4402. {
  4403. tabWidget_Global->setCurrentIndex(1);
  4404.  
  4405. on_Bt_RAZ_clicked();
  4406.  
  4407. MainWindow::setCursor(Qt::WaitCursor);
  4408. effacer_calque(scene4, calque_TAB_FRQ );
  4409. analyse_tout();
  4410. MainWindow::setCursor(Qt::ArrowCursor);
  4411. }
  4412. else {Timer1->start(10);}
  4413.  
  4414. }
  4415.  
  4416.  
  4417.  
  4418. void MainWindow::on_Bt_jouer_tout_clicked()
  4419. {
  4420. if (liste_NOTES.length() == 0) {return;}
  4421.  
  4422. if (lecture_en_cours == false)
  4423. {
  4424. Bt_jouer_tout->setText("[]");
  4425. lecture_en_cours = true;
  4426. graphicsView4->horizontalScrollBar()->setValue(0);
  4427. memo_scroll_x = 0;
  4428.  
  4429. Timer2->stop();
  4430. num_note_depart = 0;
  4431. num_note_jouee=0;
  4432. num_note_max = liste_NOTES.length();//-1;
  4433. if (num_note_max < 1) {return;}
  4434. num_barre_en_cours=0;
  4435. Timer2->start(1);
  4436. temps_0 = QDateTime::currentDateTime();
  4437. }
  4438. else
  4439. {
  4440. lecture_en_cours = false;
  4441. Timer2->stop();
  4442. Bt_jouer_tout->setText(">");
  4443. }
  4444.  
  4445. }
  4446.  
  4447.  
  4448.  
  4449. void MainWindow::on_Bt_toggle_visu_freq_clicked()
  4450. {
  4451. if(visu_freq == 0)
  4452. {
  4453. visu_freq = 1;
  4454. Bt_toggle_visu_freq->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4455. calque_TAB_FRQ->setVisible(true);
  4456. }
  4457. else
  4458. {
  4459. visu_freq = 0;
  4460. Bt_toggle_visu_freq->setStyleSheet("background-color: rgb(200, 200, 200);");
  4461. calque_TAB_FRQ->setVisible(false);
  4462. }
  4463. }
  4464.  
  4465.  
  4466. void MainWindow::on_Bt_efface_2_clicked() // sur tab FREQ-NOTES
  4467. {
  4468. on_Bt_efface_clicked(); // (celui de l'autre tab FFT)
  4469. }
  4470.  
  4471.  
  4472.  
  4473.  
  4474.  
  4475. void MainWindow::on_doubleSpinBox_t0_valueChanged()
  4476. {
  4477. effacer_calque(scene4, calque_grille_M);
  4478. effacer_calque(scene4, calque_echelle_temporelle);
  4479. effacer_calque(scene4, calque_notes_manuelles);
  4480.  
  4481. affiche_liste_notes();
  4482. trace_liste_notes();
  4483.  
  4484. tracer_echelle_temps_TAB_NOTES();
  4485. tracer_grille_M();
  4486. }
  4487.  
  4488.  
  4489.  
  4490. void MainWindow::maj_TAB_NOTES()
  4491. {
  4492. effacer_calque(scene4, calque_grille_M);
  4493. effacer_calque(scene4, calque_notes_manuelles);
  4494. effacer_calque(scene4, calque_notes_auto);
  4495. effacer_calque(scene4, calque_echelle_temporelle);
  4496. effacer_calque(scene4, calque_TAB_FRQ);
  4497.  
  4498. retracer_TAB_FRQ();
  4499. trace_liste_notes();
  4500. tracer_echelle_temps_TAB_NOTES();
  4501. tracer_grille_M();
  4502. }
  4503.  
  4504.  
  4505.  
  4506. void MainWindow::on_spinBox_zoom_2_valueChanged(int arg1)
  4507. {
  4508. zoom_x = arg1;
  4509. MainWindow::setCursor(Qt::WaitCursor);
  4510. effacer_calque(scene4, calque_grille_T);
  4511. maj_TAB_NOTES();
  4512. MainWindow::setCursor(Qt::ArrowCursor);
  4513. }
  4514.  
  4515.  
  4516.  
  4517. void MainWindow::on_pushButton_9_clicked()
  4518. {
  4519. QMessageBox msgBox;
  4520. QString s1;
  4521. s1 = "Le n° barre est compté depuis le début.";
  4522. s1 += "\n";
  4523.  
  4524. msgBox.setText(s1);
  4525. msgBox.exec();
  4526. }
  4527.  
  4528.  
  4529. void MainWindow::on_spinBox_offset_valueChanged()
  4530. {
  4531. //do_FFT_freq_midi();
  4532. }
  4533.  
  4534.  
  4535.  
  4536. void MainWindow::on_spinBox_d_barres_valueChanged()
  4537. {
  4538. double pas_grille = spinBox_dxa->value()/2.0 * zoom_x;
  4539. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  4540. calque_TAB_FRQ->setPos(offset_x, 0);
  4541. }
  4542.  
  4543.  
  4544. void MainWindow::on_Bt_decale_notes_L_clicked()
  4545. {
  4546. decalle_notes(-1);
  4547. effacer_calque(scene4,calque_notes_manuelles);
  4548. affiche_liste_notes(); // en texte
  4549. trace_liste_notes(); // ellipses
  4550. }
  4551.  
  4552.  
  4553. void MainWindow::on_Bt_decale_notes_R_clicked()
  4554. {
  4555. decalle_notes(1);
  4556. effacer_calque(scene4,calque_notes_manuelles);
  4557. affiche_liste_notes(); // en texte
  4558. trace_liste_notes(); // ellipses
  4559. }
  4560.  
  4561.  
  4562.  
  4563. void MainWindow::on_tableWidget_type_M_cellClicked(int row, int column)
  4564. {
  4565. switch (row)
  4566. {
  4567. case 0: {lineEdit_10->setText("2/4"); Ta=2; Tb=4;} break; // Ta et Tb variables globales
  4568. case 1: {lineEdit_10->setText("3/4"); Ta=3; Tb=4;} break;
  4569. case 2: {lineEdit_10->setText("4/4"); Ta=4; Tb=4;} break;
  4570. default: break;
  4571. }
  4572. tracer_grille_M();
  4573. }
  4574.  
  4575.  
  4576.  
  4577. void MainWindow::on_Bt_stop_2_clicked()
  4578. {
  4579. on_Bt_stop_clicked();
  4580. }
  4581.  
  4582.  
  4583. void MainWindow::on_checkBox_flitrer_clicked()
  4584. {
  4585. /*
  4586.   if (checkBox_flitrer->isChecked())
  4587.   {
  4588.   textEdit_ETAT->setText("Mode Filtré : \n Ne sont représentés que les signaux dont l'amplitude est supérieure au seuil choisi");
  4589.   }
  4590.   else
  4591.   {
  4592.   textEdit_ETAT->setText("Mode non-filtré : \n Tous les signaux issus de la FFT sont représentés");
  4593.   }
  4594. */
  4595.  
  4596. MainWindow::setCursor(Qt::WaitCursor);
  4597. maj_TAB_NOTES();
  4598. MainWindow::setCursor(Qt::ArrowCursor);
  4599. }
  4600.  
  4601. /*
  4602. void MainWindow::on_spinBox_filtre_valueChanged()
  4603. {
  4604.   if (checkBox_flitrer->isChecked())
  4605.   {
  4606.   MainWindow::setCursor(Qt::WaitCursor);
  4607.   maj_TAB_NOTES();
  4608.   MainWindow::setCursor(Qt::ArrowCursor);
  4609.   }
  4610. }
  4611. */
  4612. /*
  4613. void MainWindow::on_doubleSpinBox_gain_valueChanged()
  4614. {
  4615.   MainWindow::setCursor(Qt::WaitCursor);
  4616.   effacer_calque(scene4, calque_TAB_FRQ);
  4617.   retracer_TAB_FRQ();
  4618.   MainWindow::setCursor(Qt::ArrowCursor);
  4619. }
  4620. */
  4621.  
  4622. void MainWindow::on_Bt_open_DIR_clicked()
  4623. {
  4624. QString s1, path1;
  4625.  
  4626. path1 = string_currentDir;
  4627.  
  4628. QProcess process1;
  4629. process1.setProgram("caja");
  4630. process1.setArguments({path1});
  4631. process1.startDetached();
  4632. }
  4633.  
  4634.  
  4635.  
  4636. void MainWindow::on_Bt_goto_clicked()
  4637. {
  4638.  
  4639. QString s1;
  4640. int n = lineEdit_7c->text().toInt();
  4641. if ((n<0) || (n>=liste_NOTES.length())) {return;}
  4642.  
  4643. spinBox_10->setValue(n);
  4644. NOTE note_i = liste_NOTES[n];
  4645.  
  4646. double x_note = 80 + note_i.n_barreT * spinBox_dxa->value()/2.0 * zoom_x;
  4647.  
  4648. num_note_jouee = n;
  4649. surbrille_note(n);
  4650.  
  4651. int midi = note_i.midi;
  4652. s1.setNum(midi);
  4653.  
  4654. lineEdit_7->setText(s1);
  4655. affi_txt_en_couleur(midi, lineEdit_7b); // nom de la note
  4656. //affi_txt_en_couleur(midi, lineEdit_7e);
  4657.  
  4658. // graphicsView4->horizontalScrollBar()->setValue(x_note - 200);
  4659.  
  4660. }
  4661.  
  4662.  
  4663. void MainWindow::on_doubleSpinBox_T0_valueChanged(double arg1)
  4664. {
  4665. tracer_echelle_temps_TAB_NOTES();
  4666. }
  4667.  
  4668.  
  4669. void MainWindow::on_Bt_test1_clicked()
  4670. {
  4671. QString s1;
  4672. double valeur;
  4673.  
  4674. for (int n = 0; n <= 255; n+=1)
  4675. {
  4676. valeur = (double )n / 255;
  4677. s1 = calcul_couleur(valeur);
  4678.  
  4679. rectangle1 = new QGraphicsRectItem(n, 200, 2, 5);
  4680. QPen pen1;
  4681. pen1.setColor(s1);
  4682. pen1.setWidth(2);
  4683. rectangle1->setPen(pen1);
  4684. calque_grille_M->addToGroup(rectangle1);
  4685. }
  4686. }
  4687.  
  4688.  
  4689. void MainWindow::on_Bt_durees_div2_clicked()
  4690. {
  4691.  
  4692.  
  4693. uint16_t n_max = liste_NOTES.length();
  4694. if (n_max == 0) {return;}
  4695.  
  4696. NOTE note_i;
  4697. for(int n=0; n<n_max; n++) //n_max
  4698. {
  4699. note_i=liste_NOTES[n];
  4700.  
  4701. int n_barre =note_i.n_barreT;
  4702. n_barre /=2;
  4703. note_i.n_barreT = n_barre;
  4704.  
  4705. liste_NOTES[n] = note_i;
  4706. }
  4707.  
  4708. effacer_calque(scene4,calque_notes_manuelles);
  4709. affiche_liste_notes(); // en texte
  4710. trace_liste_notes(); // ellipses
  4711. }
  4712.  
  4713.  
  4714. void MainWindow::on_Bt_durees_mult2_clicked()
  4715. {
  4716.  
  4717. uint16_t n_max = liste_NOTES.length();
  4718. if (n_max == 0) {return;}
  4719.  
  4720. NOTE note_i;
  4721. for(int n=0; n<n_max; n++) //n_max
  4722. {
  4723. note_i=liste_NOTES[n];
  4724.  
  4725. int n_barre =note_i.n_barreT;
  4726. n_barre *=2;
  4727. note_i.n_barreT = n_barre;
  4728.  
  4729. liste_NOTES[n] = note_i;
  4730. }
  4731.  
  4732. effacer_calque(scene4,calque_notes_manuelles);
  4733. affiche_liste_notes(); // en texte
  4734. trace_liste_notes(); // ellipses
  4735.  
  4736. }
  4737.  
  4738.  
  4739.  
  4740. void MainWindow::on_Bt_div2_clicked()
  4741. {
  4742. gain /=sqrt(2); // en fait / par racine carrée de deux pour plus de finesse
  4743. MainWindow::setCursor(Qt::WaitCursor);
  4744. effacer_calque(scene4, calque_TAB_FRQ);
  4745. retracer_TAB_FRQ();
  4746. MainWindow::setCursor(Qt::ArrowCursor);
  4747. }
  4748.  
  4749.  
  4750. void MainWindow::on_pushButton_clicked()
  4751. {
  4752. gain *=sqrt(2);
  4753. MainWindow::setCursor(Qt::WaitCursor);
  4754. effacer_calque(scene4, calque_TAB_FRQ);
  4755. retracer_TAB_FRQ();
  4756. MainWindow::setCursor(Qt::ArrowCursor);
  4757. }
  4758.  
  4759.  
  4760. void MainWindow::on_Bt_next_clicked()
  4761. {
  4762. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  4763. graphicsView4->horizontalScrollBar()->setValue(scroll_x + 1000);
  4764.  
  4765. }
  4766.  
  4767.  
  4768. void MainWindow::on_Bt_prev_clicked()
  4769. {
  4770. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  4771. graphicsView4->horizontalScrollBar()->setValue(scroll_x - 1000);
  4772. }
  4773.  
  4774.  
  4775. void MainWindow::on_Bt_debut_clicked()
  4776. {
  4777. graphicsView4->horizontalScrollBar()->setValue(0);
  4778. }
  4779.  
  4780.  
  4781. void MainWindow::on_Bt_fin_clicked()
  4782. {
  4783. graphicsView4->horizontalScrollBar()->setValue(10000);
  4784. }
  4785.  
  4786.  
  4787.  
  4788. void MainWindow::on_bt_test_clicked()
  4789. {
  4790.  
  4791. for(int i=0; i<100; i++)
  4792. {
  4793. qDebug() << "i=" << i << "-->" << table_histogramme_durees[i];
  4794. }
  4795. }
  4796.  
  4797.  
  4798. void MainWindow::on_Bt_detection_notes_clicked()
  4799. {
  4800. effacer_calque(scene4,calque_notes_manuelles);
  4801. effacer_calque(scene4,calque_notes_auto);
  4802. detection_notes_auto();
  4803. on_Bt_toggle_visu_notes_clicked();
  4804.  
  4805. }
  4806.  
  4807.  
  4808. void MainWindow::on_Bt_toggle_visu_notes_auto_clicked()
  4809. {
  4810. if(visu_notes_auto == 0)
  4811. {
  4812. visu_notes_auto = 1;
  4813. Bt_toggle_visu_notes_auto->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4814. calque_notes_auto->setVisible(true);
  4815. //detection_notes_auto();
  4816. // tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4817. //numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  4818. // affiche_liste_notes();
  4819. // trace_liste_notes();
  4820. }
  4821. else
  4822. {
  4823. Bt_toggle_visu_notes_auto->setStyleSheet("background-color: rgb(200, 200, 200);");
  4824. visu_notes_auto = 0;
  4825. //effacer_calque(scene4,calque_notes_auto);
  4826. calque_notes_auto->setVisible(false);
  4827. }
  4828. }
  4829.  
  4830.  
  4831. void MainWindow::on_Bt_m10_clicked()
  4832. {
  4833. doubleSpinBox_vitesse->setValue(doubleSpinBox_vitesse->value()-10);
  4834. }
  4835.  
  4836.  
  4837. void MainWindow::on_Bt_p10_clicked()
  4838. {
  4839. doubleSpinBox_vitesse->setValue(doubleSpinBox_vitesse->value()+10);
  4840. }
  4841.  
  4842.  
  4843. void MainWindow::on_doubleSpinBox_gain_valueChanged(double arg1)
  4844. {
  4845. tracer_signal_complet();
  4846. }
  4847.  
  4848.  
  4849. void MainWindow::on_Bt_test2_clicked()
  4850. {
  4851. //calcul_histogramme_durees();
  4852. //affiche_histogramme_durees();
  4853. //tracer_grille_libre();
  4854.  
  4855. //QDate date_systeme;
  4856. //QTime heure_systeme;
  4857. QDate date_systeme = QDate::currentDate();
  4858. QTime heure_systeme = QTime::currentTime();
  4859.  
  4860. //qDebug() << "date_systeme" << date_systeme;
  4861. //qDebug() << "heure_systeme" << heure_systeme;
  4862. }
  4863.  
  4864.  
  4865. void MainWindow::on_Bt_open_DIR_2_clicked()
  4866. {
  4867. on_Bt_open_DIR_clicked();
  4868. }
  4869.  
  4870.  
  4871. void MainWindow::on_spinBox_nb_barres_valueChanged(int arg1)
  4872. {
  4873. effacer_calque(scene4, calque_grille_T);
  4874. tracer_grille_T();
  4875. }
  4876.  
  4877.  
  4878. void MainWindow::on_spinBox_barre_zero_valueChanged(int arg1)
  4879. {
  4880. effacer_calque(scene4, calque_grille_T);
  4881. tracer_grille_T();
  4882. }
  4883.  
  4884.  
  4885. void MainWindow::on_pushButton_10_clicked()
  4886. {
  4887. QMessageBox msgBox;
  4888. QString s1;
  4889. s1 = "Les notes sont dans une premier temps attachées à la grille T (Temporelle, fixe, 1/40s)"; s1 += "\n";
  4890. s1 += "Ensuite la grille M (Mesures) permet"; s1 += "\n";
  4891. s1 += "de placer leur double au plus près du tempo théorique"; s1 += "\n";
  4892. s1 += "La grille M (Mesures) doit être configurée manuellement"; s1 += "\n";
  4893. s1 += "(par 'x0' et 'dt' en haut)"; s1 += "\n";
  4894. s1 += "Le bouton 'Place T->M' sert à créer ces doubles"; s1 += "\n";
  4895. s1 += "et les place automatiquement sur la barre de mesure la plus proche"; s1 += "\n";
  4896.  
  4897. s1 += ""; s1 += "\n";
  4898.  
  4899. msgBox.setText(s1);
  4900. msgBox.exec();
  4901. }
  4902.  
  4903.  
  4904. void MainWindow::on_pushButton_11_clicked()
  4905. {
  4906. QMessageBox msgBox;
  4907. QString s1;
  4908.  
  4909. s1 += "Pour déplacer une note horizontalement :"; s1 += "\n";
  4910. s1 += "1) cliquez sur le bouton 'Select'"; s1 += "\n";
  4911. s1 += "2) cliquez sur la note pour la sélectionner"; s1 += "\n";
  4912. s1 += "3) cliquez sur les boutons '<' et '>' qui sont apparus à la place du bouton 'Select'"; s1 += "\n";
  4913.  
  4914. s1 += ""; s1 += "\n";
  4915.  
  4916. msgBox.setText(s1);
  4917. msgBox.exec();
  4918. }
  4919.  
  4920.  
  4921.  
  4922. void MainWindow::on_Bt_RAZ_general_clicked()
  4923. {
  4924. liste_NOTES.clear();
  4925. liste_ENR_FFT.clear();
  4926. parametrages();
  4927. graphicsView4->horizontalScrollBar()->setValue(0);
  4928. }
  4929.  
  4930.  
  4931.  
  4932. void MainWindow::on_spinBox_x0a_valueChanged(int arg1)
  4933. {
  4934. effacer_calque(scene4, calque_echelle_temporelle);
  4935. effacer_calque(scene4, calque_grille_M);
  4936.  
  4937. trace_liste_notes();
  4938. tracer_grille_M();
  4939. }
  4940.  
  4941.  
  4942. void MainWindow::on_doubleSpinBox_x0b_valueChanged(double arg1)
  4943. {
  4944. effacer_calque(scene4, calque_echelle_temporelle);
  4945. effacer_calque(scene4, calque_grille_M);
  4946.  
  4947. trace_liste_notes();
  4948. tracer_grille_M();
  4949. }
  4950.  
  4951.  
  4952.  
  4953. void MainWindow::on_Bt_copy_nt_T_to_M_clicked()
  4954. {
  4955. uint16_t n;
  4956. uint16_t n_max = liste_NOTES.length();
  4957. uint16_t nb_M;
  4958.  
  4959. for(int n=0; n<n_max; n++)
  4960. {
  4961. nb_M = calcul_n_barreM_note(n);
  4962. liste_NOTES[n].n_barreM = nb_M;
  4963. }
  4964. mode='M';
  4965. affiche_liste_notes();
  4966. trace_liste_notes();
  4967. }
  4968.  
  4969.  
  4970. void efface_notes_T()
  4971. {
  4972. uint16_t n_max = liste_NOTES.length();
  4973. for(int n=0; n<n_max; n++)
  4974. {
  4975. liste_NOTES[n].n_barreT = 0;
  4976. }
  4977. }
  4978.  
  4979.  
  4980.  
  4981. void MainWindow::on_Bt_copy_nt_M_to_T_clicked()
  4982. {
  4983. uint16_t n;
  4984. uint16_t n_max = liste_NOTES.length();
  4985. uint16_t nb_T;
  4986.  
  4987. efface_notes_T();
  4988.  
  4989. for(int n=0; n<n_max; n++)
  4990. {
  4991. nb_T = calcul_n_barreT_note(n);
  4992. //nb_T = liste_NOTES[n].n_barreM * 14 ; //8.5; // méthode directe. à voir...
  4993. if (nb_T < 1000) {liste_NOTES[n].n_barreT = nb_T;}
  4994. }
  4995. mode='T';
  4996. mode_grille_T();
  4997. affiche_liste_notes();
  4998. trace_liste_notes();
  4999. }
  5000.  
  5001.  
  5002. void MainWindow::on_pushButton_4_clicked()
  5003. {
  5004. pushButton_4->setVisible(false);
  5005. mode_select = true;
  5006. }
  5007.  
  5008.  
  5009.  
  5010. void MainWindow::on_radioButton_D_clicked()
  5011. {
  5012. affiche_histogramme();
  5013. }
  5014.  
  5015.  
  5016. void MainWindow::on_radioButton_M_clicked()
  5017. {
  5018. affiche_histogramme();
  5019. }
  5020.  
  5021.  
  5022. void MainWindow::on_radioButton_H_clicked()
  5023. {
  5024. affiche_histogramme();
  5025. }
  5026.  
  5027.  

Mais où se cache cette fameuse transformée de Fourier rapide dans ce programme ?

Cherchez la fonction :

void MainWindow::calcul_FFT()

ainsi que les fonctions :

void MainWindow::calcul_tableau_W()
void MainWindow::bit_reverse_tableau_X()
uint bit_reversal(uint num, uint nb_bits)


Voir aussi les fichiers complexe.cpp et complexe.h

Et pour les explications et les démonstrations mathématiques vior les liens au bas de cet article.

5 'wav to midi' : fichier mainwindow.h

CODE SOURCE en C++
  1.  
  2. #ifndef MAINWINDOW_H
  3. #define MAINWINDOW_H
  4.  
  5. #include <QMainWindow>
  6. #include "ui_mainwindow.h"
  7.  
  8. #include <QGraphicsView>
  9. #include <QGraphicsSceneMouseEvent>
  10. #include <QGraphicsTextItem>
  11. #include <QGraphicsLineItem>
  12. #include <QGraphicsRectItem>
  13. #include <QGraphicsItemGroup>
  14. //#include <QImage>
  15. #include <QProcess>
  16. #include <QtMultimedia/QMediaPlayer>
  17. #include <QAudioOutput>
  18. #include <QTimer>
  19.  
  20. #include "complexe.h"
  21.  
  22.  
  23. struct ENR_FFT
  24. {
  25. double amplitude; // 8 octets
  26. uint32_t t; // 4 octets
  27. uint8_t num; // 1 octet
  28. uint8_t midi; //1 octet
  29. // total 4+1+1+8 = 14 octets
  30. };
  31.  
  32.  
  33. // à propos des notes : PRINCIPE
  34. // les notes ont une fréquence qui n'est pas directement enregistrée ici mais est représenté par le numéro MIDI.
  35. // elles ont un emplacement qui est enregistré et qui permet de connaitre l'instant de son jeu, connaissant la grille.
  36. // pour la grille temporelle, voir 'tracer_grille_MESURES()'
  37. // la variable 'duree' pourrait être calculée en fonction des précédentes, mais le fait de l'avoir ici
  38. // permet de visualiser une toute partie de la partition, voir une note unique, en dehors du contexte
  39. struct NOTE
  40. {
  41. uint16_t numero; // 2 octets
  42. uint8_t midi; // 1 octet
  43. uint16_t n_barreT; // 2 octets; numéro de la barre temporelle (T, 1/20s)sur laquelle est posée la note
  44. int16_t n_barreM; // 2 octets; num de barre M sur laquelle.. (accepte les valeurs négatives)
  45. // total 7 octets
  46. };
  47.  
  48.  
  49.  
  50. /* FFT */
  51.  
  52. class MainWindow : public QMainWindow, public Ui::MainWindow
  53. {
  54. Q_OBJECT
  55.  
  56. public:
  57. explicit MainWindow(QWidget *parent = 0);
  58. ~MainWindow();
  59.  
  60. protected:
  61.  
  62. void mousePressEvent(QMouseEvent *event);
  63. void contextMenuEvent(QContextMenuEvent *event); // clic de droite
  64.  
  65.  
  66. private slots:
  67. void Tic1();
  68. void Tic2();
  69. void save_fichier_ini();
  70. void load_fichier_ini();
  71. void choix_dossier_de_travail();
  72. void open_fichier_wav();
  73.  
  74. void on_Bt_load_wav_clicked();
  75. void ajustement_gain();
  76. void load_fichier_FRQ();
  77. int save_fichier_FRQ(QString date_i);
  78. void load_fichier_NOTES();
  79. int save_fichier_NOTES(QString date_i);
  80.  
  81. void decode_entete();
  82. void garnis_temp_data(qint32 offset);
  83.  
  84. void parametrages();
  85. void init_TW_1();
  86. void init_TAB_FRQ();
  87. void init_TAB_lst_notes();
  88. void init_TW_type_M();
  89. void init_Autres();
  90.  
  91. void Etiquette(int x, int dx, int y, QString s, QString coul_txt, QString coul_fond, QString coul_cadre , QGraphicsItemGroup *calque_i);
  92.  
  93. void afficher_titre_calque(QString titre, int x, int y, QGraphicsItemGroup *calque_i);
  94. void tracer_graduations_signal();
  95. void tracer_graduations_FFT(); // sur onglet 'Source wav'
  96. void tracer_signal_complet(); // sur onglet 'Source wav'
  97. void tracer_gradu_temporelle_signal_entree(); // sur onglet 'Source wav'
  98. void tracer_signal_a_convertir(); // sur onglet 'Source wav'
  99. void tracer_graduation_TAB_NOTES(); // midi ; en colonne à gauche + noms des notes
  100. void tracer_echelle_temps_TAB_NOTES(); //en secondes (scene4 sur l'onglet NOTES)
  101. void tracer_grille_M();
  102. void tracer_grille_T();
  103. double calcul_pas_grille();
  104. //double calcul_pas_grille_M();
  105. double calcul_x_barre(int n_barre);
  106. int calcul_tempo();
  107. //double calcul_x_barre_M(int n_barre);
  108. void trace_1_barre_M(double xi, QString couleur_i);
  109. void tracer_1enr(ENR_FFT enr_i);
  110. void detection_notes_auto(); // notes secondaires (affi par petits cercles colorés)
  111. void retracer_TAB_FRQ();
  112. void maj_TAB_NOTES();
  113.  
  114. void encadrement_signal(int x, int dx);
  115. void encadrement_note(int n_midi);
  116. void encadre_midi(int n_midi);
  117. int calcul_num_midi(double x);
  118. void tracer_segments_FFT();
  119.  
  120. void complete_case(int row, int column, QString s1, QString c1, QString c2, bool bold1, QTableWidget *QTI);
  121. void affiche_liste_notes();
  122. void trace_liste_notes(); //dessine des cercles colorés (couleur midi) sur la grille
  123.  
  124. void calcul_histogramme_durees();
  125. void affiche_histogramme_durees();
  126.  
  127. void calcul_histogramme_midi();
  128. void affiche_histogramme_midi();
  129.  
  130. void calcul_histogramme_degre(); // degrés de la gamme chromatique = 1..12
  131. void affiche_histogramme_degre();
  132.  
  133. void affiche_histogramme();
  134.  
  135. QString denombre_diezes_a_la_cle();
  136. int test_if_note_in_liste(uint16_t n_barre, int midi);
  137. void affi_txt_en_couleur(int midi_i, QLineEdit *lineEdit_i);
  138.  
  139. int num_barre(double xi);
  140. void ajout_note(int midi, int n_barreT, int n_barreM);
  141. void deplace_note(int n, int d);
  142. void supprime_note(uint16_t n);
  143. uint16_t calcul_n_barreM_note(uint16_t n); // barre M la plus proche de la note posée sur une barre T
  144. uint16_t calcul_n_barreT_note(uint16_t n); // barre T la plus proche de la note posée sur une barre M
  145.  
  146. void remplir_tableau_echantillons_signal();
  147. void calcul_compression();
  148. void bit_reverse_tableau_X();
  149.  
  150. int calcul_y_note(int midi); // en pixels sur la grille
  151. int calcul_hauteur_note(int mid);
  152. void calcul_tableau_W();
  153. void calcul_FFT();
  154. void calcul_ofsset();
  155. void traitement_signal();
  156. void analyse_tout();
  157. QString nom_note(int mid);
  158. QString nom_note_GB(int mid);
  159. QString nom_octave_GB(int mid);
  160.  
  161. void numerotation_liste_notes();
  162. void tri_liste_notes_par_num_barre();
  163. void suppression_notes_invalides();
  164. void suppression_mesures();
  165.  
  166. void play_note(int midi);// sortie audio
  167. int joue_1_note_de_la_liste();
  168. void surbrille_note(uint16_t n);
  169. void trace_time_line();
  170.  
  171. void effacer_calque(QGraphicsScene *scene_i, QGraphicsItemGroup *calque_i);
  172.  
  173. void on_spinBox_1_valueChanged(int arg1);
  174. void on_spinBox_2_valueChanged(int arg1);
  175. void on_spinBox_3_valueChanged(int arg1);
  176. void on_spinBox_4_valueChanged(int arg1);
  177. void on_spinBox_5_valueChanged(int arg1);
  178. void on_spinBox_6_valueChanged();
  179. void on_spinBox_7_valueChanged(int arg1);
  180. void on_pushButton_8_clicked();
  181. void on_doubleSpinBox_1_valueChanged();
  182. void on_Bt_RAZ_clicked();
  183. void on_Bt_scan_auto_clicked();
  184. void on_pushButton_2_clicked();
  185. void on_Btn_52_clicked();
  186. void on_Btn_94_clicked();
  187. void on_pushButton_3_clicked();
  188. void on_Bt_close_entete_clicked();
  189. void on_pushButton_6_clicked();
  190. void on_Bt_efface_clicked();
  191. void on_pushButton_5_clicked();
  192. void on_checkBox_rapide_stateChanged(int arg1);
  193. void on_doubleSpinBox_seuil_valueChanged(double arg1);
  194. void on_checkBox_norm_clicked();
  195. void on_Bt_jouer_tout_clicked();
  196.  
  197. void mode_grille_T();
  198. void on_Bt_toggle_grille_T_clicked();
  199. void on_Bt_toggle_visu_notes_clicked();
  200. void mode_grille_M();
  201. void on_Bt_toggle_grille_M_clicked();
  202. void on_Bt_save_notes_clicked();
  203. void on_Bt_load_notes_clicked();
  204. void on_Bt_joue_passage_clicked();
  205. void on_Bt_joue_wav_clicked();
  206. void on_Btn_RAZ_notes_clicked();
  207. void on_Bt_stop_clicked();
  208. void on_Bt_stop_2_clicked();
  209. void on_Bt_mode_R_clicked();
  210. void on_Bt_mode_W_clicked();
  211. void on_Bt_toggle_visu_freq_clicked();
  212. void on_Bt_efface_2_clicked();
  213. void on_Bt_copy_nt_T_to_M_clicked();
  214. void on_Bt_copy_nt_M_to_T_clicked();
  215. void on_Bt_joue_wav_2_clicked();
  216. void on_Bt_choix_current_dir_clicked();
  217. void on_pushButton_9_clicked();
  218. void on_spinBox_8_textChanged();
  219. void on_doubleSpinBox_t0_valueChanged();
  220. void on_spinBox_offset_valueChanged();
  221. void on_spinBox_zoom_2_valueChanged(int arg1);
  222. void on_spinBox_d_barres_valueChanged();
  223. void on_Bt_load_FREQ_clicked();
  224. void on_Bt_decale_notes_L_clicked();
  225. void on_Bt_decale_notes_R_clicked();
  226. void on_tableWidget_type_M_cellClicked(int row, int column);
  227. void on_checkBox_flitrer_clicked();
  228. void on_Bt_open_DIR_clicked();
  229. void on_Bt_goto_clicked();
  230. void on_doubleSpinBox_x0_valueChanged(double arg1);
  231. void on_doubleSpinBox_T0_valueChanged(double arg1);
  232. void on_Bt_test1_clicked();
  233. void on_Bt_div2_clicked();
  234. void on_pushButton_clicked();
  235. void on_Bt_next_clicked();
  236. void on_Bt_prev_clicked();
  237. void on_Bt_debut_clicked();
  238. void on_Bt_fin_clicked();
  239. void on_Bt_durees_div2_clicked();
  240. void on_Bt_durees_mult2_clicked();
  241. void on_bt_test_clicked();
  242. void on_Bt_detection_notes_clicked();
  243. void on_Bt_toggle_visu_notes_auto_clicked();
  244. void on_Bt_m10_clicked();
  245. void on_Bt_p10_clicked();
  246. void on_doubleSpinBox_gain_valueChanged(double arg1);
  247. void on_Bt_test2_clicked();
  248. void on_Bt_open_DIR_2_clicked();
  249. void on_spinBox_nb_barres_valueChanged(int arg1);
  250. void on_spinBox_barre_zero_valueChanged(int arg1);
  251. void on_pushButton_10_clicked();
  252. void on_Bt_mode_E_clicked();
  253. void on_Bt_RAZ_general_clicked();
  254. void on_spinBox_x0a_valueChanged(int arg1);
  255. void on_doubleSpinBox_x0b_valueChanged(double arg1);
  256.  
  257. void on_spinBox_dxa_valueChanged(int arg1);
  258.  
  259. void on_Bt_deplace_L_clicked();
  260. void on_Bt_deplace_R_clicked();
  261.  
  262. void on_doubleSpinBox_dxb_valueChanged(double arg1);
  263.  
  264. void on_pushButton_4_clicked();
  265. void on_pushButton_11_clicked();
  266.  
  267.  
  268. void on_radioButton_D_clicked();
  269.  
  270. void on_radioButton_M_clicked();
  271.  
  272. void on_radioButton_H_clicked();
  273.  
  274. private:
  275.  
  276. QPoint Zoom_point2_;
  277.  
  278. // QImage image1;
  279.  
  280. QGraphicsScene *scene1; // sur l'onglet 'Source' - Trace FFT
  281. QGraphicsItemGroup *calque_reticule1;
  282. QGraphicsItemGroup *calque_trace_signal1;
  283. QGraphicsItemGroup *calque_trace_FFT;
  284. QGraphicsItemGroup *calque_curseur;
  285. QGraphicsItemGroup *calque_encadrement1;
  286. QGraphicsItemGroup *calque_lignes_F_zero;
  287.  
  288. QGraphicsScene *scene2; // sur l'onglet 'Source' - Signal d'entrée
  289. QGraphicsItemGroup *calque_reticule2;
  290. QGraphicsItemGroup *calque_encadrement2;
  291. QGraphicsItemGroup *calque_trace_signal2;
  292.  
  293. QGraphicsScene *scene3;
  294. QGraphicsItemGroup *calque_gradu_TAB_FRQ;
  295.  
  296. QGraphicsScene *scene4; // sur l'onglet 'NOTES'
  297. QGraphicsItemGroup *calque_TAB_FRQ;
  298.  
  299. QGraphicsScene *scene5; // sur l'onglet 'NOTES'
  300. QGraphicsItemGroup *calque_histogramme;
  301.  
  302. QGraphicsItemGroup *calque_grille_T;
  303. QGraphicsItemGroup *calque_grille_M;
  304. QGraphicsItemGroup *calque_echelle_temporelle;
  305. QGraphicsItemGroup *calque_notes_manuelles;
  306. QGraphicsItemGroup *calque_notes_auto;
  307. QGraphicsItemGroup *calque_notes_jouee;
  308.  
  309. QGraphicsLineItem *ligne1;
  310. QGraphicsLineItem *segment_trace;
  311. QGraphicsLineItem *segment_trace2;
  312. QGraphicsRectItem *rectangle1;
  313. QGraphicsRectItem *rectangle2;
  314. QGraphicsEllipseItem *ellipse1;
  315. QGraphicsRectItem *rect1;
  316. QGraphicsRectItem *rect2;
  317. QGraphicsRectItem *rect3;
  318.  
  319. QGraphicsTextItem *GraphicsTextItem;
  320.  
  321. QMediaPlayer *player1;
  322. QMediaPlayer *player2;
  323. QMediaPlayer *player3;
  324. QMediaPlayer *player4;
  325. QMediaPlayer *player5;
  326.  
  327. QAudioOutput *audioOutput1;
  328. QAudioOutput *audioOutput2;
  329. QAudioOutput *audioOutput3;
  330. QAudioOutput *audioOutput4;
  331. QAudioOutput *audioOutput5;
  332.  
  333. QTimer *Timer1; // pour analyse auto à faible vitesse
  334. QTimer *Timer2; // pour rejouer les notes détectées
  335.  
  336. };
  337.  
  338.  
  339.  
  340. #endif // MAINWINDOW_H
  341.  

6 'wav to midi' : fichier complexe.cpp

CODE SOURCE en C++
  1.  
  2. #include "complexe.h"
  3. //
  4.  
  5. void Complexe::multi_lambda(float lambda)
  6. {
  7. a *= lambda;
  8. b *= lambda;
  9. }
  10.  
  11.  
  12. Complexe Complexe::operator+ (Complexe c)
  13. {
  14. Complexe r;
  15. r.a=this->a+c.a;
  16. r.b=this->b+c.b;
  17. return r;
  18. }
  19.  
  20.  
  21. Complexe Complexe::operator- (Complexe c)
  22. {
  23. Complexe r;
  24. r.a=this->a-c.a;
  25. r.b=this->b-c.b;
  26. return r;
  27. }
  28.  
  29.  
  30. Complexe Complexe::operator* (Complexe c)
  31. {
  32. Complexe r;
  33. r.a=this->a * c.a - this->b * c.b;
  34. r.b=this->a * c.b + this->b * c.a;
  35. return r;
  36. }
  37.  
  38.  
  39.  
  40. /* rappel: fonction en pascal
  41. function produit_cplx(c1,c2:complexe):complexe;
  42.  begin
  43.   produit_cplx[1]:=c1[1]*c2[1]-c1[2]*c2[2];
  44.   produit_cplx[2]:=c1[1]*c2[2]+c1[2]*c2[1];
  45.  end;
  46. */
  47.  
  48.  

7 'wav to midi' : fichier complexe.h

CODE SOURCE en C++
  1.  
  2. #ifndef COMPLEXE_H
  3. #define COMPLEXE_H
  4. // Nombres complexes de la forme a+ib
  5.  
  6. //
  7. class Complexe
  8. {
  9.  
  10. public:
  11.  
  12. float a; // partie reelle
  13. float b; // partie imaginaire
  14. void multi_lambda(float lambda);
  15. Complexe operator+ (Complexe c);
  16. Complexe operator- (Complexe c);
  17. Complexe operator* (Complexe c); //equivaut a une rotation dans le plan (produit des modules, somme des arguments)
  18.  
  19. };
  20.  
  21.  
  22.  
  23.  
  24. #endif
  25.  

8 Autre programme : 'Guitare' - Présentation en vidéo


Ce nouveau programme constitue la suite logique du programme 'wav to midi'.
Il peut traiter la liste de notes générée par 'wav to midi'.
On part donc d'un fichier audio et on arrive à une sorte de suite de tablatures représentées sur la manche de la guitare avec position de chaque doigt de la main. Le tout ré-jouable avec respect du tempo.

Il fera l'objet d'un prochain article sur ce site. Je vous donne juste un aperçu en vidéo en attendant.
A suivre...

9 programme : 'Guitare' - video2


Vous aurez reconnu le court extrait de "Hotel California" à titre d'exemple.

10 programme : 'Guitare' - video 3


Vous aurez reconnu le court extrait de "Hotel California" à titre d'exemple.

11 Le code source 'Guitare' en C++ Qt6: fichier mainwindow.cpp

CODE SOURCE en C++
  1. #include "MainWindow.h"
  2. #include "ui_MainWindow.h"
  3.  
  4. #include "math.h"
  5. #include <QFile>
  6. #include <QFileDialog>
  7. #include <QTextStream>
  8. #include <QGraphicsView>
  9. #include <QPixmap>
  10. #include <QGraphicsPixmapItem>
  11. #include <QGraphicsEllipseItem>
  12. #include <QList>
  13. #include <QTimer>
  14. #include <QLine>
  15. #include <QProcess>
  16. #include <QDebug>
  17. #include <QMessageBox>
  18.  
  19. //#include <QSound>
  20. #include <QtMultimedia/QMediaPlayer>
  21. #include <QAudioOutput>
  22.  
  23. #include <QMouseEvent>
  24. #include <QScrollBar>
  25.  
  26.  
  27. QString version_i = "v18.2";
  28.  
  29. QFile file_dat;
  30.  
  31. uint16_t largeur_image = 1216; // image du manche de la guitare
  32. uint16_t hauteur_image = 180;
  33.  
  34. QDir currentDir;
  35. QString base_Dir;
  36. QString default_Dir = "/home/";
  37. QString string_currentDir = default_Dir; // à priori; sera mis à jour lors de la lecture du fichier 'params.ini'
  38. QString string_currentFile;
  39.  
  40. QString repertoire_images;
  41. QString nom_fichier_in="";
  42. QStringList liste_str_in;
  43. QStringList liste_accords;
  44.  
  45. QDataStream binStream1;
  46.  
  47. //QList<NOTE> liste_notes;
  48. //QList<MESURE> liste_mesures;
  49.  
  50. QList<uint16_t> positionsX;
  51. QList<QString> noms_notes;
  52. QList<QString> gamme_chromatique;
  53. QList<QString> gamme_chromatique_GB;
  54. //QList<QColor> liste_couleurs;
  55. QList<QString> liste_couleurs;
  56. QList<NOTE_importee> liste_NOTES_importees;
  57.  
  58. int type_accords=0; // 1=MAJ; 2=min; 3=7e dom
  59.  
  60. uint16_t x_clic_ecran, y_clic_ecran;
  61.  
  62. int nb_lignes;
  63. int L_save_min=0;
  64. int L_save_max=0;
  65. int numero_note=0; // dans la liste totale de la partition (ne compte QUE les notes)
  66. int num_ligne_en_cours=0; // lignes du tableWidget_3
  67. int num_note_A=0;
  68. int num_note_max=0;
  69. int num_note_stop=10000;
  70. int nb_notes_jouees_max;
  71. int nb_notes_jouees=0;
  72. int accord_en_cours=0;
  73. int num_note_jouee=0;
  74. int corde_jouee;
  75. int case_jouee;
  76. int n_midi_jouee;
  77. int ligne_TW3;
  78. int memo_corde_i;
  79. int memo_case_i;
  80. QString acc1="";
  81. QString memo_acc1="";
  82. char gamme;
  83.  
  84. int case_min=0;
  85. int case_max=0;
  86.  
  87. int mesure_a_encadrer=0;
  88. int memo_mesure_a_encadrer=0;
  89. int num_colonne_a_encadrer=0;
  90. int nb_colonnes_a_encadrer=1;
  91. int zoom=1;
  92.  
  93. int num_mesure_en_cours=0;
  94.  
  95. int Tp1;
  96. int temps1;
  97.  
  98. float duree=30;
  99. int boucler=0;
  100. int lecture_pause=1; // fonction du bouton lecture / pause
  101. int n_player=1;
  102.  
  103. double grille_t0;
  104. double grille_dt;
  105.  
  106. bool notes_pleines; // concerne le graphique : ellipse pleine ou bien juste un cercle
  107. bool notes_silencieuses; // pour représenter les positions d'accords, sans les jouer
  108. bool mode_depot_note=false; // pour écrire la valeur midi d'une note dans TW3 suite à clic de droite le manche
  109. bool data_ok = false;
  110. bool dossier_de_travail_ok = false;
  111.  
  112.  
  113.  
  114. MainWindow::MainWindow(QWidget *parent) :
  115. QMainWindow(parent)
  116. {
  117. setupUi(this);
  118. setWindowTitle("Guitare " + version_i);
  119.  
  120. //this->setGeometry(0,0, 1900, 1000);
  121. setWindowState(Qt::WindowMaximized);
  122.  
  123. //statusbar->showMessage("Position des doigts...");
  124.  
  125. frame_back->setGeometry(0, 0, 1900, 1050);
  126.  
  127. scene1 = new QGraphicsScene(this);
  128.  
  129. graphicsView1->setScene(scene1);
  130. graphicsView1->setGeometry(10,100, largeur_image+20, hauteur_image+5);
  131. pushButton_8->setGeometry(10, 100, 26, 26); // bouton aide1 (sur le manche)
  132. pushButton_9->setGeometry(38, 100, 26, 26); // bouton aide2 (sur le manche)
  133.  
  134. Timer2 = new QTimer(this);
  135.  
  136. connect(Timer2, SIGNAL(timeout()), this, SLOT(Tic2()));
  137. connect(tableWidget_T->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(TW_T_scroll(int)));
  138. connect(tableWidget_3->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(TW_3_scroll(int)));
  139.  
  140. repertoire_images = "./images/"; // chemin relatif / dossier de l'exécutable
  141. charger_image_manche();
  142.  
  143. calque_notes = new QGraphicsItemGroup();
  144. scene1->addItem(calque_notes);
  145.  
  146. calque_encadrement = new QGraphicsItemGroup();
  147. scene1->addItem(calque_encadrement);
  148.  
  149. Frame_wWidget1 = new QFrame();
  150.  
  151. positionsX << 5 << 55 << 140 <<225 << 305 << 385 << 459 << 528 << 595 << 650 << 714 << 765
  152. << 820 << 864 << 910 << 960 << 1000 << 1035 << 1072 << 1111 << 1145;
  153. // 21 valeurs en comptant les cordes à vide
  154. // indice max = 21-1 = 20
  155.  
  156. player1 = new QMediaPlayer;
  157. audioOutput1 = new QAudioOutput(this);
  158. player1->setAudioOutput(audioOutput1);
  159.  
  160. player2 = new QMediaPlayer;
  161. audioOutput2 = new QAudioOutput(this);
  162. player2->setAudioOutput(audioOutput2);
  163.  
  164. player3 = new QMediaPlayer;
  165. audioOutput3 = new QAudioOutput(this);
  166. player3->setAudioOutput(audioOutput3);
  167.  
  168. player4 = new QMediaPlayer;
  169. audioOutput4 = new QAudioOutput(this);
  170. player4->setAudioOutput(audioOutput4);
  171.  
  172. player5 = new QMediaPlayer;
  173. audioOutput5 = new QAudioOutput(this);
  174. player5->setAudioOutput(audioOutput5);
  175.  
  176. player6 = new QMediaPlayer;
  177. audioOutput6 = new QAudioOutput(this);
  178. player6->setAudioOutput(audioOutput6);
  179.  
  180. player7 = new QMediaPlayer;
  181. audioOutput7 = new QAudioOutput(this);
  182. player7->setAudioOutput(audioOutput7);
  183.  
  184. player8 = new QMediaPlayer;
  185. audioOutput8 = new QAudioOutput(this);
  186. player8->setAudioOutput(audioOutput8);
  187.  
  188. noms_notes<<"La"<<"Si"<<"Do"<<"Ré"<<"Mi" <<"Fa"<<"Sol"; // <- A B C D E F G
  189. gamme_chromatique<<"Do"<<"Do#"<<"Ré"<<"Mib"<<"Mi"<<"Fa"<<"Fa#"<<"Sol"<<"Sol#"<<"La"<<"Sib"<<"Si";
  190. gamme_chromatique_GB<<"C"<<"C#"<<"D"<<"Eb"<<"E"<<"F"<<"F#"<<"G"<<"G#"<<"A"<<"A#"<<"B";
  191.  
  192. liste_couleurs <<"#EF2929"<<"#FF5C00"<<"#FCAF3E"<<"#FFE300"<<"#BFFF00"<<"#07F64F"
  193. <<"#16D298"<<"#16D2C4"<<"#00AEFF"<<"#1667D2"<<"#7C00FF"<<"#FF67EF"<<"#EEEEEC"; //(la dernière = GRIS)
  194.  
  195. lecture_fichier_ini();
  196.  
  197. //init_TW_1();
  198. init_TW_3();
  199. init_TW_T();
  200. init_TAB_lst_notes();
  201. init_tableWidget_doigts();
  202. init_autres();
  203.  
  204. on_spinBox_2_valueChanged(0);
  205.  
  206. doubleSpinBox_vitesse->setValue(8.0);
  207. //on_doubleSpinBox_vitesse_valueChanged(30);
  208.  
  209. radioButton_Z1->setChecked(true); // set zomm 1
  210. set_zoom1();
  211.  
  212. Bt_lecture_2->setText("joue > debut");
  213. notes_pleines = true;
  214. notes_silencieuses = false;
  215.  
  216. on_pushButton_3_clicked();
  217. effacer_calque(scene1, calque_encadrement);
  218. label_43->clear();
  219. label_44->clear();
  220. label_45->clear();
  221. //line1 = new QFrame(this);
  222. Frame_wWidget1->setVisible(false);
  223.  
  224. }
  225.  
  226. MainWindow::~MainWindow()
  227. {
  228. delete ui;
  229. }
  230.  
  231.  
  232. void MainWindow::save_fichier_ini()
  233. {
  234. QFile file1(QDir::currentPath() + "/" + "params_Guitare.ini"); // dans le dossier de l'exécutable
  235. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  236. {
  237. //int p1= string_currentFile.lastIndexOf('/');
  238. // string_currentDir = string_currentFile.left(p1);
  239.  
  240. QTextStream out(&file1);
  241.  
  242. out << "# Ce fichier est cree automatiquement par le programme";
  243. out << '\n';
  244. out << "#";
  245. out << '\n';
  246. out << "# chemins:";
  247. out << '\n';
  248. out << "<currentDir>" << string_currentDir << "</currentDir>";
  249. out << '\n';
  250. out << "<currentFile>" << string_currentFile << "</currentFile>";
  251. }
  252. file1.close();
  253. }
  254.  
  255.  
  256. void MainWindow::lecture_fichier_ini()
  257. {
  258. //QMessageBox msgBox;
  259. QString line;
  260. int p1, p2, p3;
  261.  
  262. dossier_de_travail_ok = false; // à priori
  263. QFile file1(QDir::currentPath() + "/" + "params_Guitare.ini"); // dans le dossier de l'exécutable (= QDir::currentPath() )
  264. if (file1.open(QIODevice::ReadOnly | QIODevice::Text))
  265. {
  266. QTextStream in(&file1);
  267. in.reset();
  268. while ( !in.atEnd() )
  269. {
  270. line = in.readLine();
  271. if (line.at(0) !='#')
  272. {
  273. if ((p1 = line.indexOf("<currentDir>")) != -1)
  274. {
  275. p2 = line.indexOf('>',p1);
  276. p3 = line.indexOf("</",p2);
  277. QString s1 = line.mid(p2+1, p3-p2-1);
  278. string_currentDir = s1;
  279.  
  280. dossier_de_travail_ok = true;
  281. }
  282.  
  283.  
  284. if ((p1 = line.indexOf("<currentFile>")) != -1)
  285. {
  286. p2 = line.indexOf('>',p1);
  287. p3 = line.indexOf("</",p2);
  288. QString s1 = line.mid(p2+1, p3-p2-1);
  289. string_currentFile = s1;
  290. }
  291. }
  292. }
  293. file1.close();
  294. }
  295. else
  296. {
  297. QString s1 = "fichier .ini non trouvé, je le crée (dans le dossier de l'executable)";
  298. QMessageBox msgBox; msgBox.setText(s1); msgBox.exec();
  299. base_Dir=QDir::currentPath() + "/";
  300. save_fichier_ini();
  301. dossier_de_travail_ok = false;
  302. }
  303.  
  304. lineEdit_current_dir->setText(string_currentDir);
  305. }
  306.  
  307.  
  308. float freq_mid(int midi_i) // calcule la fréquence (en Hertz) d'une note à partir de son numéro midi
  309. {
  310. // https://fr.wikipedia.org/wiki/MIDI_Tuning_Standard
  311. float F, A;
  312. A=((float)midi_i-69.0)/12.0;
  313. F= 440 * powf(2,A);
  314. return F;
  315. }
  316.  
  317.  
  318. void MainWindow::init_TW_3() // affi grande liste verticale
  319. {
  320.  
  321. label_TW3->setGeometry(1205, 10, 50, 18);
  322. tableWidget_3->setGeometry(1250, 10, 640, 836); // la valeur 836 est critique pour l'encadrement ok
  323. tableWidget_3->clear();
  324. tableWidget_3->setRowCount(1);
  325. tableWidget_3->setColumnCount(12);
  326. QStringList liste_entetes;
  327. liste_entetes <<"note1"<<"note2"<<"note3"<<"Cmt"<<">"<<"dur"<<"M"<<"tps"<< "n°b"<<"ACC"<<"cases"<<"doigts";
  328. tableWidget_3->setHorizontalHeaderLabels (liste_entetes );
  329. tableWidget_3->resizeColumnsToContents();
  330. //for(int n=0; n<=2; n++)
  331. {
  332. tableWidget_3->setItem(0, 0, new QTableWidgetItem (" ") ); tableWidget_3->setColumnWidth(0,65);
  333. tableWidget_3->setItem(0, 1, new QTableWidgetItem (" ") ); tableWidget_3->setColumnWidth(1,65);
  334. tableWidget_3->setItem(0, 2, new QTableWidgetItem (" ") ); tableWidget_3->setColumnWidth(2,65);
  335.  
  336. tableWidget_3->setItem(0, 3, new QTableWidgetItem (" ") ); tableWidget_3->setColumnWidth(3,100); // commentaire
  337. tableWidget_3->setColumnWidth(3, 80);
  338.  
  339. QTableWidgetItem *Item1 = new QTableWidgetItem();
  340. Item1->setIcon(QIcon("../images/01.png" ));
  341. tableWidget_3->setItem(0, 4, Item1 );
  342. tableWidget_3->setColumnWidth(4, 20);
  343.  
  344. tableWidget_3->setItem(0, 5, new QTableWidgetItem ("0") ); // durée
  345. tableWidget_3->setColumnWidth(5, 40);
  346.  
  347. tableWidget_3->setItem(0, 6, new QTableWidgetItem ("0") ); // MESURE
  348. tableWidget_3->setColumnWidth(6, 40);
  349.  
  350. tableWidget_3->setItem(0, 7, new QTableWidgetItem (" ") ); // tps
  351. tableWidget_3->setColumnWidth(7, 40);
  352.  
  353. tableWidget_3->setItem(0, 8, new QTableWidgetItem (" ") ); // tot
  354. tableWidget_3->setColumnWidth(8, 40);
  355.  
  356. tableWidget_3->setItem(0, 9, new QTableWidgetItem (" ") ); // ACC
  357. tableWidget_3->setColumnWidth(9, 54);
  358.  
  359. tableWidget_3->setItem(0, 10, new QTableWidgetItem (" ") ); // cases
  360. tableWidget_3->setColumnWidth(10, 52);
  361.  
  362. tableWidget_3->setItem(0, 11, new QTableWidgetItem (" ") ); // doigts
  363. tableWidget_3->setColumnWidth(11, 60);
  364.  
  365. }
  366. }
  367.  
  368. void MainWindow::init_tableWidget_doigts()
  369. {
  370. tableWidget_doigts->setGeometry(5, 20, 200, 200);
  371.  
  372. tableWidget_doigts->clear();
  373. tableWidget_doigts->setRowCount(5);
  374. tableWidget_doigts->setColumnCount(3);
  375. QStringList liste_entetesH;
  376. liste_entetesH <<"corde"<<"case"<<"DOIGT";
  377. tableWidget_doigts->setHorizontalHeaderLabels (liste_entetesH );
  378.  
  379. QStringList liste_entetesV;
  380. liste_entetesV <<"0"<<"1"<<"2"<<"3"<<"4";
  381. tableWidget_doigts->setVerticalHeaderLabels(liste_entetesV );
  382.  
  383. for(int n=0; n<5; n++)
  384. {
  385. QTableWidgetItem *Item1 = new QTableWidgetItem();
  386. Item1->setIcon(QIcon("../images/02.png" ));
  387. tableWidget_doigts->setItem(n, 2, Item1 );
  388. }
  389. tableWidget_doigts->resizeColumnsToContents();
  390. tableWidget_doigts->setColumnWidth(2, 20);
  391.  
  392. pushButton_6->setGeometry(189, 0, 22, 21); // bouton aide position des doigts
  393.  
  394. Bt_copie_doigts_to_TW3->setGeometry(50, 147, 150, 26);
  395. Bt_RAZ_doigts->setGeometry(10, 147, 31, 26);
  396.  
  397.  
  398. int R, C;
  399. for (R=0; R<5; R++)
  400. {
  401. for (C=0; C<2; C++)
  402. {
  403. tableWidget_doigts->setItem(R, C, new QTableWidgetItem ("-") );
  404. tableWidget_doigts->item(R,C)->setTextAlignment(Qt::AlignCenter);
  405. }
  406. }
  407. }
  408.  
  409.  
  410.  
  411. void MainWindow::init_TW_T()
  412. {
  413. tableWidget_T->setGeometry(10, 880, 1870, 135);
  414. tableWidget_T->setColumnCount(300);
  415. label_timeline->setGeometry(10, 850, 100, 30);
  416.  
  417. tableWidget_T->clear();
  418. for(int n=0; n< tableWidget_T->columnCount(); n++)
  419. {
  420. complete_case(0, n, "-", "#000000", "#FFFFFF", false, tableWidget_T);
  421. //complete_case(5, n, "-", "#000000", "#FFFFFF", tableWidget_T);
  422. }
  423.  
  424. }
  425.  
  426.  
  427. void MainWindow::init_TAB_lst_notes()
  428. {
  429. tableWidget_lst_notes->setGeometry(140,640,450,231);
  430. QStringList liste_entetes1;
  431. liste_entetes1<<"numéro"<<"midi"<<"note"<<"n° barre"<< "temps"<< "durée" << " ";
  432. tableWidget_lst_notes->setHorizontalHeaderLabels (liste_entetes1);
  433. tableWidget_lst_notes->setEditTriggers(QAbstractItemView::NoEditTriggers);
  434.  
  435. }
  436.  
  437.  
  438.  
  439.  
  440. void MainWindow::init_autres()
  441. {
  442. groupBox_1->setGeometry(20, 450, 350, 181); // Configurateur d'Accords
  443. groupBox_2->setGeometry(900, 490, 311, 370);
  444. groupBox_3->setGeometry(670, 450, 200, 180); // Général
  445. groupBox_4->setGeometry(380, 450, 210, 180); // Position des doigts
  446.  
  447. groupBox_ZOOM->setGeometry(20, 760, 50, 70);
  448.  
  449. H_line_1->setVisible(false);
  450. V_line_1->setVisible(false);
  451. H_line_2->setVisible(false);
  452. V_line_2->setVisible(false);
  453. H_line_1b->setVisible(false);
  454. V_line_1b->setVisible(false);
  455. H_line_2b->setVisible(false);
  456. V_line_2b->setVisible(false);
  457.  
  458. label_44->setGeometry(900, 430, 111, 31);
  459. label_45->setGeometry(900, 450, 111, 31);
  460.  
  461. groupBox_Import->setGeometry(600, 640, 270, 100);
  462. pushButton_11->setGeometry(560, 640, 31, 26);
  463.  
  464. groupBox_sigles->setGeometry(600, 750, 270, 121);
  465.  
  466. Bt_save_ACD->setGeometry(1000, 50, 92, 26);
  467. Bt_load_ACD->setGeometry(1100, 50, 92, 26);
  468.  
  469.  
  470. create_100_lignes_V();
  471. }
  472.  
  473.  
  474. void MainWindow::effacer_calque(QGraphicsScene *scene_i, QGraphicsItemGroup *calque_i)
  475. {
  476. foreach( QGraphicsItem *item, scene_i->items( calque_i->boundingRect() ) )
  477. {if( item->group() == calque_i ) { delete item; }}
  478. }
  479.  
  480.  
  481.  
  482. void MainWindow::charger_image_manche()
  483. {
  484. QString fileName1;
  485. fileName1 = repertoire_images + "manche2.jpg";
  486.  
  487. QFile file1(fileName1);
  488. if (file1.exists() )
  489. {
  490. QImage image1(fileName1);
  491. image1 = image1.scaledToWidth(largeur_image);
  492. image1.load(fileName1);
  493. //imageLabel1->setPixmap(QPixmap::fromImage(image1));
  494. QGraphicsPixmapItem* item1 = new QGraphicsPixmapItem(QPixmap::fromImage(image1));
  495. scene1->addItem(item1);
  496. //calque_notes->addToGroup(item1);
  497. }
  498. }
  499.  
  500.  
  501. void MainWindow::affi_txt_en_couleur(int midi_i, QLineEdit *lineEdit_i)
  502. {
  503. int h1 = calcul_hauteur_note(midi_i); h1-=3; if(h1<0){h1+=12;} if(h1>11){h1-=12;}
  504. if ((h1<0) || (h1>(liste_couleurs.length()-1))) {h1 = 0;}
  505. QString c1 = liste_couleurs[h1];
  506. QString c2 = "#000000";
  507. lineEdit_i->setStyleSheet("color: " + c1 + "; background-color: " + c2 + "; font: 700 14pt 'Ubuntu';");
  508. }
  509.  
  510.  
  511. QString MainWindow::nom_note_FR(int mid)
  512. {
  513. QString s1;
  514.  
  515. int h1 = calcul_hauteur_note(mid);
  516. h1-=3;
  517. if(h1<0){h1+=12;}
  518. if(h1>11){h1-=12;}
  519.  
  520. if((h1<0) || ( h1>= gamme_chromatique.length())) {return "-";}
  521. s1 = gamme_chromatique[h1];
  522. return s1;
  523. }
  524.  
  525.  
  526. QString MainWindow::nom_note_GB(int mid)
  527. {
  528. QString s1;
  529.  
  530. int h1 = calcul_hauteur_note(mid);
  531. h1-=3;
  532. if(h1<0){h1+=12;}
  533. if(h1>11){h1-=12;}
  534.  
  535. if((h1<0) || ( h1>= gamme_chromatique_GB.length())) {return "-";}
  536. s1 = gamme_chromatique_GB[h1];
  537. return s1;
  538. }
  539.  
  540.  
  541. QString MainWindow::nom_octave_GB(int mid)
  542. {
  543. QString octave;
  544. if((mid>=40)&&(mid < 48)) {octave = "2";}
  545. if((mid>=48)&&(mid < 60)) {octave = "3";}
  546. if((mid>=60)&&(mid < 72)) {octave = "4";}
  547. if((mid>=72)&&(mid < 90)) {octave = "5";}
  548. return octave;
  549. }
  550.  
  551. int MainWindow::calcul_hauteur_note(int mid) //, char *nom_GB)
  552. {
  553. //40 E3 (mi octave 2)
  554.  
  555. int h1;
  556. QString s0, s1 , s2, s3, s4;
  557. h1 = mid-40;
  558. h1 -=5; // -5
  559. h1+=12;
  560. gamme=2;
  561. while(h1>=12)
  562. {
  563. h1-=12;
  564. gamme++;
  565. }
  566. if (h1==12) {h1=0;}
  567.  
  568. if (h1==0) {s2="A"; s3="La";}
  569. if (h1==1) {s2="Bb"; s3="Sib";}
  570. if (h1==2) {s2="B"; s3="Si";}
  571. if (h1==3) {s2="C"; s3="D0";}
  572. if (h1==4) {s2="C#"; s3="D0#";}
  573. if (h1==5) {s2="D"; s3="Re";}
  574. if (h1==6) {s2="Eb"; s3="Mib";}
  575. if (h1==7) {s2="E"; s3="Mi";}
  576. if (h1==8) {s2="F"; s3="Fa";}
  577. if (h1==9) {s2="F#"; s3="Fa#";}
  578. if (h1==10) {s2="G"; s3="Sol";}
  579. if (h1==11) {s2="G#"; s3="Lab";}
  580.  
  581.  
  582. s1.setNum(h1);
  583. s4.setNum(gamme);
  584.  
  585. s0=s2 + s4 + " (" +s3 +s4 + ")";
  586.  
  587. lineEdit_note->setText(s0);
  588.  
  589. return h1; // h1 = 0..11
  590. }
  591.  
  592.  
  593. int MainWindow::calcul_midi(int corde_i, int case_i)
  594. {
  595. // 40 -> Mi octave 2 (corde 6 à vide)
  596. int n;
  597. n = 40 + case_i; // corde6 de Mi grave
  598. if (corde_i == 5){n+=5;}
  599. if (corde_i == 4){n+=10;}
  600. if (corde_i == 3){n+=15;}
  601. if (corde_i == 2){n+=19;}
  602. if (corde_i == 1){n+=24;} // corde1 de Mi aigu (+2 octaves)
  603.  
  604. //*n_midi = n;
  605. return n;
  606.  
  607. }
  608.  
  609.  
  610. void MainWindow::calcul_xy_note(int corde_i, int case_i, int *x_i, int *y_i)
  611. {
  612. float x;
  613. float y;
  614. float dy;
  615. float y0;
  616. float ech;
  617.  
  618. if (case_i >= positionsX.length())
  619. {
  620. *x_i=1;
  621. *y_i=1;
  622. return;
  623. }
  624. x=positionsX[case_i];
  625.  
  626. y0=102;
  627. ech=1+case_i/90.0;
  628. dy=-20.0*((7-corde_i)-3.2);
  629.  
  630. dy *= ech;
  631. y=y0+dy;
  632.  
  633. *x_i=int(x);
  634. *y_i=int(y);
  635. }
  636.  
  637.  
  638.  
  639. void MainWindow::detecte_note_xy(int x_i, int y_i, int *corde_i, int *case_i)
  640. {
  641. // suite à un clic directement sur le manche
  642. // voir la fonction "mousePressEvent()"
  643. float y;
  644. float dy;
  645. float y0;
  646. float ech;
  647.  
  648. // détection du numéro de la case jouée
  649. *case_i=-1;
  650. for (int i=0; i<21; i++)
  651. {
  652. int x= positionsX[i] +30;
  653. if ((abs(x_i - x))<30) {*case_i = i;}
  654. }
  655. if (*case_i == -1)
  656. {
  657. *corde_i=0;
  658. *case_i=0;
  659. return;
  660. }
  661.  
  662. // détection du numéro de la corde jouée
  663. *corde_i=0;
  664. y0=220;
  665.  
  666. for (int i=1; i<=6; i++)
  667. {
  668. ech=1+ *case_i/90.0;
  669. dy=-20.0*((7-i)-3.2);
  670. dy *= ech;
  671. y=y0+dy;
  672.  
  673. if ((abs(y_i - y))<20) {*corde_i = i;}
  674. }
  675. }
  676.  
  677.  
  678. void MainWindow::numerote_1_note(int corde_i, int case_i, int num_i)
  679. {
  680. QString s1;
  681. int x, y;
  682.  
  683. s1.setNum(num_i);
  684.  
  685. calcul_xy_note(corde_i, case_i, &x, &y);
  686. textItem1 = new QGraphicsSimpleTextItem(s1);
  687. QBrush brush1;
  688. brush1.setStyle(Qt::SolidPattern);
  689. brush1.setColor("#000000");
  690. textItem1->setBrush(brush1);
  691. textItem1->setPos(x+2, y -1);
  692. calque_notes->addToGroup(textItem1);
  693. }
  694.  
  695.  
  696.  
  697. void MainWindow::dessine_1_note(int corde_i, int case_i, QColor couleur_i)
  698. {
  699. int x, y;
  700. // case_i = 0..20 (0 -> corde à vide)
  701.  
  702. if ( (case_i < case_min) || (case_i > case_max) ) {return;}
  703.  
  704. uint midi = calcul_midi(corde_i, case_i);
  705. affiche_details_note(midi);
  706.  
  707. QPen pen_note(couleur_i, 1, Qt::SolidLine);
  708.  
  709. if ((case_i>=0) && (case_i<=20))
  710. {
  711. calcul_xy_note(corde_i, case_i, &x, &y);
  712. ellipse1 = new QGraphicsEllipseItem(x, y, 15, 15);
  713. ellipse1->setPen(pen_note);
  714. if (notes_pleines == true) {ellipse1->setBrush(couleur_i);}
  715. calque_notes->addToGroup(ellipse1);
  716.  
  717. memo_case_i=case_i;
  718. memo_corde_i=corde_i;
  719. }
  720. }
  721.  
  722.  
  723. void MainWindow::encadre_accord(int case1, int case2)
  724. {
  725. int x0, y0, x1, y1, dx, dy;
  726.  
  727. effacer_calque(scene1, calque_encadrement);
  728.  
  729. if (case1>19) {return;}
  730. if (case2>20) {return;}
  731.  
  732. if (case1>case2) {return;}
  733.  
  734. qDebug() << "case1" << case1;
  735. qDebug() << "case2" << case2;
  736. qDebug() << "______________";
  737.  
  738. calcul_xy_note(1, case1, &x0, &y0);
  739. calcul_xy_note(6, case2, &x1, &y1);
  740. dx= x1-x0;
  741. dy=y1-y0;
  742.  
  743. Frame_wWidget1->setGeometry(QRect(x0-4, y0-2, dx+24, dy +14));
  744. Frame_wWidget1->setStyleSheet( "background: transparent;" "border: 1px solid yellow;" "border-radius: 15px;" );
  745. QGraphicsProxyWidget *proxy = scene1->addWidget(Frame_wWidget1);
  746. Frame_wWidget1->setVisible(true);
  747. }
  748.  
  749.  
  750. void MainWindow::dessine_accord(int corde_i1, int case_i1, int corde_i2, int case_i2)
  751. {
  752. //QGraphicsLineItem *QGraphicsScene::addLine(qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen = QPen())
  753. int x1, y1;
  754. int x2, y2;
  755. QString couleur1;
  756. calcul_xy_note(corde_i1, case_i1, &x1, &y1);
  757. calcul_xy_note(corde_i2, case_i2, &x2, &y2);
  758. couleur1 = liste_couleurs[4];
  759. QPen pen_ligne; //(liste_couleurs[4], 1, Qt::SolidLine);
  760. pen_ligne.setColor(couleur1);
  761. scene1->addLine(x1+8, y1+8, x2+8, y2+8, pen_ligne);
  762. }
  763.  
  764.  
  765.  
  766.  
  767.  
  768. /**
  769. REMARQUES:
  770.  
  771. pour la guitare :
  772. E2 = le Mi2 grave (corde 6 à vide)
  773. E3 = le Mi3 corde 4 case 2
  774. E4 = le Mi4 corde 1 à vide
  775. E5 = le Mi5 corde 1 case 12
  776. D6 = le Ré6 corde 1 case 22 (la note la plus aigüe de la guitare électrique)
  777.  
  778. donc au total (presque) 4 octaves (manque juste 2 notes, Mib6 et Mi6)
  779. **/
  780.  
  781.  
  782. void MainWindow::execute_note_midi(uint midi)
  783. {
  784. calcul_hauteur_note(midi);
  785. //if (checkBox1->isChecked()) {on_Bt_RAZ_clicked();} // efface tout avant de ne dessiner qu'une seule note
  786. //QString s1;
  787. //s1.setNum(i);
  788. //lineEdit_7->setText(s1);
  789. num_note_jouee++;
  790. switch(midi)
  791. {
  792. case 40: on_Bt_E3_clicked(); break; // mi octave 3
  793. case 41: on_Bt_F3_clicked(); break; // fa octave 3
  794. case 42: on_Bt_Fd3_clicked(); break; // fa# octave 3
  795. case 43: on_Bt_G3_clicked(); break; //sol
  796. case 44: on_Bt_Gd3_clicked(); break; //sol#
  797. case 45: on_Bt_A3_clicked(); break; //la
  798. case 46: on_Bt_Bb3_clicked(); break; //sib
  799. case 47: on_BT_B3_clicked(); break; //si
  800. case 48: on_Bt_C4_clicked(); break; //do
  801. case 49: on_Bt_Cd4_clicked(); break; //do#
  802. case 50: on_Bt_D4_clicked(); break; //re
  803. case 51: on_Bt_Eb4_clicked(); break; //mib
  804. case 52: on_Bt_E4_clicked(); break; //mi
  805. case 53: on_Bt_F4_clicked(); break; //fa
  806. case 54: on_Bt_Fd4_clicked(); break; //fa#
  807. case 55: on_Bt_G4_clicked(); break; //sol
  808. case 56: on_Bt_Gd4_clicked(); break; //sol#
  809. case 57: on_Bt_A4_clicked(); break; //la
  810. case 58: on_Bt_Bb4_clicked(); break; //sib
  811. case 59: on_Bt_B4_clicked(); break; //si
  812. case 60: on_Bt_C5_clicked(); break; //do
  813. case 61: on_Bt_Cd5_clicked(); break; //do#
  814. case 62: on_Bt_D5_clicked(); break; //re
  815. case 63: on_Bt_Eb5_clicked(); break; //mib
  816. case 64: on_Bt_E5_clicked(); break; //mi
  817. case 65: on_Bt_F5_clicked(); break; //fa
  818. case 66: on_Bt_Fd5_clicked(); break; //fa#
  819. case 67: on_Bt_G5_clicked(); break; //sol
  820. case 68: on_Bt_Gd5_clicked(); break; //sol#
  821. case 69: on_Bt_A5_clicked(); break; //la
  822. case 70: on_Bt_Bb5_clicked(); break; //sib
  823. case 71: on_Bt_B5_clicked(); break; //si
  824. case 72: on_Bt_C6_clicked(); break; //do
  825. case 73: on_Bt_Cd6_clicked(); break; //do#
  826. case 74: on_Bt_D6_clicked(); break; //re
  827. case 75: on_Bt_Eb6_clicked(); break; //mib
  828. case 76: on_Bt_E6_clicked(); break; //mi
  829. case 77: on_Bt_F6_clicked(); break; //fa
  830. case 78: on_Bt_Fd6_clicked(); break; //fa#
  831. case 79: on_Bt_G6_clicked(); break; //sol
  832. case 80: on_Bt_Gd6_clicked(); break; //sol#
  833. case 81: on_Bt_A6_clicked(); break; //la
  834. case 82: on_Bt_Bb6_clicked(); break; //sib
  835.  
  836. default: { ; } break;
  837. }
  838. }
  839.  
  840. /*
  841. A TRAITER: silences (rest)
  842.  
  843. voir fichier xml ligne 535
  844.   *
  845. <note>
  846.   <rest/>
  847.   <duration>12</duration>
  848.   <voice>1</voice>
  849.   <type>eighth</type>
  850.   <staff>1</staff>
  851. </note>
  852. */
  853.  
  854.  
  855. void MainWindow::effacer_touches()
  856. {
  857. QColor c = "#505050";
  858. set_couleur_label(c, label5);
  859. set_couleur_label(c, label6);
  860. set_couleur_label(c, label7);
  861. set_couleur_label(c, label8);
  862. set_couleur_label(c, label9);
  863. set_couleur_label(c, label10);
  864. set_couleur_label(c, label11);
  865. set_couleur_label(c, label12);
  866.  
  867. set_couleur_label(c, label1_2);
  868. set_couleur_label(c, label2_2);
  869. set_couleur_label(c, label3_2);
  870. set_couleur_label(c, label4_2);
  871. set_couleur_label(c, label5_2);
  872. set_couleur_label(c, label6_2);
  873. set_couleur_label(c, label7_2);
  874. set_couleur_label(c, label8_2);
  875. set_couleur_label(c, label9_2);
  876. set_couleur_label(c, label10_2);
  877. set_couleur_label(c, label11_2);
  878. set_couleur_label(c, label12_2);
  879.  
  880. set_couleur_label(c, label1_3);
  881. set_couleur_label(c, label2_3);
  882. set_couleur_label(c, label3_3);
  883. set_couleur_label(c, label4_3);
  884. set_couleur_label(c, label5_3);
  885. set_couleur_label(c, label6_3);
  886. set_couleur_label(c, label7_3);
  887. set_couleur_label(c, label8_3);
  888. set_couleur_label(c, label9_3);
  889. set_couleur_label(c, label10_3);
  890. set_couleur_label(c, label11_3);
  891. set_couleur_label(c, label12_3);
  892.  
  893. set_couleur_label(c, label1_4);
  894. set_couleur_label(c, label2_4);
  895. set_couleur_label(c, label3_4);
  896. set_couleur_label(c, label4_4);
  897. set_couleur_label(c, label5_4);
  898. set_couleur_label(c, label6_4);
  899. set_couleur_label(c, label7_4);
  900. set_couleur_label(c, label8_4);
  901. set_couleur_label(c, label9_4);
  902. set_couleur_label(c, label10_4);
  903. set_couleur_label(c, label11_4);
  904. set_couleur_label(c, label12_4);
  905.  
  906. }
  907.  
  908.  
  909. void MainWindow::on_Bt_RAZ_clicked()
  910. {
  911. // sur le manche
  912. effacer_calque(scene1, calque_notes);
  913. effacer_calque(scene1, calque_encadrement);
  914. Frame_wWidget1->setVisible(false);
  915.  
  916. // la suite sur les touches
  917. effacer_touches();
  918.  
  919. // label_44->setText("-");
  920. // label_45->setText("-");
  921.  
  922. }
  923.  
  924.  
  925. void MainWindow::set_couleur_bouton(QColor c1, QPushButton *Bt_i)
  926. {
  927. QPalette pal1 = Bt_i->palette();
  928. pal1.setColor(QPalette::Button, c1);
  929. Bt_i->setPalette(pal1);
  930. }
  931.  
  932.  
  933. void MainWindow::set_couleur_label(QColor c1, QLabel *Lb_i)
  934. {
  935. QPalette pal1 = Lb_i->palette();
  936. pal1.setColor(Lb_i->backgroundRole(), c1);
  937. Lb_i->setAutoFillBackground(true);
  938. Lb_i->setPalette(pal1);
  939. }
  940.  
  941.  
  942. void MainWindow::set_couleur_case(QColor couleur_i, QTableWidget *Tb_i, int L, int C)
  943. {
  944. QTableWidgetItem *Item1 = new QTableWidgetItem();
  945. Item1->setTextAlignment(Qt::AlignCenter);
  946. Item1->setFlags(Qt::ItemIsSelectable);
  947. Item1->QTableWidgetItem::setBackground(couleur_i);
  948. Tb_i->setItem(L,C,Item1);
  949. }
  950.  
  951.  
  952.  
  953. void MainWindow::Tic2()
  954. {
  955.  
  956. // à voir : ne lit pas les positions des doigts !!!
  957.  
  958. //int i_max = liste_notes.count();
  959. int i_max=tableWidget_3->rowCount();
  960. QString s1, s2, s3;
  961. QString duree_txt;
  962. int di=0;
  963.  
  964. int d_barre;
  965. float dt, vts;
  966. int itrv;
  967.  
  968. vts = doubleSpinBox_vitesse->value();
  969.  
  970. if ((num_ligne_en_cours >= 0) && (num_ligne_en_cours < i_max) )
  971. {
  972. s1 = tableWidget_3->item(num_ligne_en_cours, 6)->text();
  973. //s2 = s1.mid(1); // partie numérique de "*2"
  974. duree_txt = tableWidget_3->item(num_ligne_en_cours, 5)->text();
  975. d_barre = duree_txt.toInt();
  976. nb_colonnes_a_encadrer = d_barre;
  977. num_colonne_a_encadrer=Tp1;
  978.  
  979. write_Time_line();
  980. encadrement_colonne();
  981.  
  982. // memo_mesure_a_encadrer = mesure_a_encadrer;
  983. mesure_a_encadrer = s1.toInt(); // numero de la mesure
  984.  
  985. tableWidget_3->selectRow(num_ligne_en_cours);
  986.  
  987. //diF = duree_txt.toFloat();
  988. di = duree_txt.toInt();
  989.  
  990. s1 = tableWidget_3->item(num_ligne_en_cours, 9)->text();
  991. s2 = tableWidget_3->item(num_ligne_en_cours, 10)->text();
  992. notes_silencieuses = true;
  993. joue_accord_complet(s1, s2); // représentation graphique de la position avant de jouer la note
  994. notes_silencieuses = false;
  995.  
  996. s1 = tableWidget_3->item(num_ligne_en_cours, 6)->text();
  997. if (s1 !=" ") {play_toc();}
  998.  
  999. effacer_touches();
  1000.  
  1001. joue_1_ligne(num_ligne_en_cours);
  1002.  
  1003. s1 = tableWidget_3->item(num_ligne_en_cours, 11)->text();
  1004. affi_positions_doigts_dans_status(s1);
  1005.  
  1006. dt = 20.0 * (float)d_barre;
  1007. dt *= (100.0 / vts);
  1008. itrv = (int) dt;
  1009.  
  1010. //dt = 40.0 * d_barre;
  1011. //dt *= (10.0 - vts);
  1012. //itrv = (int) dt;
  1013.  
  1014. Timer2->setInterval(itrv);
  1015. }
  1016. num_ligne_en_cours++;
  1017. if (num_ligne_en_cours >= i_max)
  1018. {
  1019. Bt_lecture_2->setText("joue > debut");
  1020. Bt_lecture_2->setStyleSheet("QPushButton{background-color:#50FF1B;}");
  1021. lecture_pause =0;
  1022. QString s1;
  1023. s1.setNum(num_ligne_en_cours);// conversion num -> txt
  1024. Timer2->stop();
  1025. }
  1026.  
  1027.  
  1028. encadrement_ligne();
  1029. Tp1 += di;
  1030.  
  1031. nb_notes_jouees++;
  1032.  
  1033. if (nb_notes_jouees>nb_notes_jouees_max)
  1034. {
  1035. nb_notes_jouees=0;
  1036. lecture_pause =0;
  1037. Timer2->stop();
  1038. }
  1039. }
  1040.  
  1041.  
  1042. void MainWindow::play_toc()
  1043. {
  1044. QString s1;
  1045. s1="notes/bip.wav";
  1046. if (n_player == 1)
  1047. {
  1048. player1->setSource(QUrl::fromLocalFile(s1));
  1049. player1->play();
  1050. }
  1051. if (n_player == 2)
  1052. {
  1053. player2->setSource(QUrl::fromLocalFile(s1));
  1054. player2->play();
  1055. }
  1056. if (n_player == 3)
  1057. {
  1058. player3->setSource(QUrl::fromLocalFile(s1));
  1059. player3->play();
  1060. }
  1061. if (n_player == 4)
  1062. {
  1063. player4->setSource(QUrl::fromLocalFile(s1));
  1064. player4->play();
  1065. }
  1066.  
  1067. if (n_player == 5)
  1068. {
  1069. player5->setSource(QUrl::fromLocalFile(s1));
  1070. player5->play();
  1071. }
  1072. if (n_player == 6)
  1073. {
  1074. player6->setSource(QUrl::fromLocalFile(s1));
  1075. player6->play();
  1076. }
  1077. if (n_player == 7)
  1078. {
  1079. player7->setSource(QUrl::fromLocalFile(s1));
  1080. player7->play();
  1081. }
  1082. if (n_player == 8)
  1083. {
  1084. player8->setSource(QUrl::fromLocalFile(s1));
  1085. player8->play();
  1086. }
  1087.  
  1088. n_player++;
  1089. if (n_player >= 9) {n_player = 1;}
  1090.  
  1091. }
  1092.  
  1093.  
  1094. void MainWindow::play_note(int midi) // sortie audio
  1095. {
  1096. if (notes_silencieuses == true) {return ;}
  1097.  
  1098. if (!checkBox_not_erase->isChecked()) {on_Bt_RAZ_clicked();}
  1099.  
  1100. QString s1, freq_txt;
  1101.  
  1102. calcul_hauteur_note(midi);
  1103. s1.setNum(midi);
  1104.  
  1105. lineEdit_6->setText(s1);
  1106. lineEdit_n_midi->setText(s1);
  1107.  
  1108. float freq = freq_mid(midi-12);
  1109. freq_txt.setNum(freq,'f', 2);
  1110. lineEdit_freq->setText(freq_txt+" Hz");
  1111.  
  1112.  
  1113. s1="notes/"+s1+".wav"; // fichiers audio comprenant une seule note chacun, voir dans le dossier "notes" sur le HDD
  1114.  
  1115. if (n_player == 1)
  1116. {
  1117. player1->setSource(QUrl::fromLocalFile(s1));
  1118. player1->play();
  1119. }
  1120. if (n_player == 2)
  1121. {
  1122. player2->setSource(QUrl::fromLocalFile(s1));
  1123. player2->play();
  1124. }
  1125. if (n_player == 3)
  1126. {
  1127. player3->setSource(QUrl::fromLocalFile(s1));
  1128. player3->play();
  1129. }
  1130. if (n_player == 4)
  1131. {
  1132. player4->setSource(QUrl::fromLocalFile(s1));
  1133. player4->play();
  1134. }
  1135.  
  1136. if (n_player == 5)
  1137. {
  1138. player5->setSource(QUrl::fromLocalFile(s1));
  1139. player5->play();
  1140. }
  1141. if (n_player == 6)
  1142. {
  1143. player6->setSource(QUrl::fromLocalFile(s1));
  1144. player6->play();
  1145. }
  1146. if (n_player == 7)
  1147. {
  1148. player7->setSource(QUrl::fromLocalFile(s1));
  1149. player7->play();
  1150. }
  1151. if (n_player == 8)
  1152. {
  1153. player8->setSource(QUrl::fromLocalFile(s1));
  1154. player8->play();
  1155. }
  1156.  
  1157. n_player++;
  1158. if (n_player >= 9) {n_player = 1;}
  1159. }
  1160.  
  1161.  
  1162. void MainWindow::on_Bt_E3_clicked()
  1163. {
  1164. int n_midi=40;
  1165. play_note(n_midi); // numérotation MIDI
  1166. QColor c=liste_couleurs[4];
  1167. dessine_1_note(6, 0, c); // sur le manche
  1168. set_couleur_label(c, label5); // près de la touche piano
  1169. }
  1170.  
  1171. void MainWindow::on_Bt_F3_clicked()
  1172. {
  1173. int n_midi=41;
  1174. play_note(n_midi);
  1175. QColor c=liste_couleurs[5];
  1176. dessine_1_note(6, 1, c); // sur le manche
  1177. set_couleur_label(c, label6); // près de la touche piano
  1178. }
  1179.  
  1180. void MainWindow::on_Bt_Fd3_clicked()
  1181. {
  1182. int n_midi=42;
  1183. play_note(n_midi);
  1184. QColor c=liste_couleurs[6];
  1185. dessine_1_note(6, 2, c); // sur le manche
  1186. set_couleur_label(c, label7); // près de la touche piano
  1187. }
  1188.  
  1189. void MainWindow::on_Bt_G3_clicked()
  1190. {
  1191. int n_midi=43;
  1192. play_note(n_midi);
  1193. QColor c=liste_couleurs[7];
  1194. dessine_1_note(6, 3, c); // sur le manche
  1195. set_couleur_label(c, label8); // près de la touche piano
  1196. }
  1197.  
  1198. void MainWindow::on_Bt_Gd3_clicked()
  1199. {
  1200. int n_midi=44;
  1201. play_note(n_midi);
  1202. QColor c=liste_couleurs[8];
  1203. dessine_1_note(6, 4, c); // sur le manche
  1204. set_couleur_label(c, label9); // près de la touche piano
  1205. }
  1206.  
  1207. void MainWindow::on_Bt_A3_clicked()
  1208. {
  1209. int n_midi=45;
  1210. play_note(n_midi);
  1211. QColor c=liste_couleurs[9];
  1212. dessine_1_note(6, 5, c); dessine_1_note(5, 0, c); // sur le manche
  1213. set_couleur_label(c, label10); // près de la touche piano
  1214. }
  1215.  
  1216. void MainWindow::on_Bt_Bb3_clicked()
  1217. {
  1218. int n_midi=46;
  1219. play_note(n_midi);
  1220. QColor c=liste_couleurs[10];
  1221. dessine_1_note(6, 6, c); dessine_1_note(5, 1, c);
  1222. set_couleur_label(c, label11); // près de la touche piano
  1223. }
  1224.  
  1225. void MainWindow::on_BT_B3_clicked()
  1226. {
  1227. int n_midi=47;
  1228. play_note(n_midi);
  1229. QColor c=liste_couleurs[11];
  1230. dessine_1_note(6, 7, c); dessine_1_note(5, 2, c);
  1231. set_couleur_label(c, label12); // près de la touche piano
  1232. }
  1233.  
  1234. void MainWindow::on_Bt_C4_clicked()
  1235. {
  1236. int n_midi=48;
  1237. play_note(n_midi);
  1238. QColor c=liste_couleurs[0];
  1239. dessine_1_note(6, 8, c); dessine_1_note(5, 3, c);
  1240. set_couleur_label(c, label1_2);
  1241. }
  1242.  
  1243. void MainWindow::on_Bt_Cd4_clicked()
  1244. {
  1245. int n_midi=49;
  1246. play_note(n_midi);
  1247. QColor c=liste_couleurs[1];
  1248. dessine_1_note(6, 9, c); dessine_1_note(5, 4, c);
  1249. set_couleur_label(c, label2_2);
  1250. }
  1251.  
  1252. void MainWindow::on_Bt_D4_clicked()
  1253. {
  1254. int n_midi=50;
  1255. play_note(n_midi);
  1256. QColor c=liste_couleurs[2];
  1257. dessine_1_note(6, 10, c); dessine_1_note(5, 5, c); dessine_1_note(4, 0, c);
  1258. set_couleur_label(c, label3_2);
  1259. }
  1260.  
  1261. void MainWindow::on_Bt_Eb4_clicked()
  1262. {
  1263. int n_midi=51;
  1264. play_note(n_midi);
  1265. QColor c=liste_couleurs[3];
  1266. dessine_1_note(6, 11, c); dessine_1_note(5, 6, c); dessine_1_note(4, 1, c);
  1267. set_couleur_label(c, label4_2);
  1268. }
  1269.  
  1270. void MainWindow::on_Bt_E4_clicked()
  1271. {
  1272. int n_midi=52;
  1273. play_note(n_midi);
  1274. QColor c=liste_couleurs[4];
  1275. dessine_1_note(6, 12, c); dessine_1_note(5, 7, c); dessine_1_note(4, 2, c);
  1276. set_couleur_label(c, label5_2);
  1277. }
  1278.  
  1279. void MainWindow::on_Bt_F4_clicked()
  1280. {
  1281. int n_midi=53;
  1282. play_note(n_midi);
  1283. QColor c=liste_couleurs[5];
  1284. dessine_1_note(6, 13, c); dessine_1_note(5, 8, c); dessine_1_note(4, 3, c);
  1285. set_couleur_label(c, label6_2);
  1286. }
  1287.  
  1288. void MainWindow::on_Bt_Fd4_clicked()
  1289. {
  1290. int n_midi=54;
  1291. play_note(n_midi);
  1292. QColor c=liste_couleurs[6];
  1293. dessine_1_note(6, 14, c); dessine_1_note(5, 9, c); dessine_1_note(4, 4, c);
  1294. set_couleur_label(c, label7_2);
  1295. }
  1296.  
  1297. void MainWindow::on_Bt_G4_clicked()
  1298. {
  1299. int n_midi=55;
  1300. play_note(n_midi);
  1301. QColor c=liste_couleurs[7];
  1302. dessine_1_note(6, 15, c); dessine_1_note(5, 10, c); dessine_1_note(4, 5, c); dessine_1_note(3, 0, c);
  1303. set_couleur_label(c, label8_2);
  1304. }
  1305.  
  1306. void MainWindow::on_Bt_Gd4_clicked()
  1307. {
  1308. int n_midi=56;
  1309. play_note(n_midi);
  1310. QColor c=liste_couleurs[8];
  1311. dessine_1_note(6, 16, c); dessine_1_note(5, 11, c); dessine_1_note(4, 6, c); dessine_1_note(3, 1, c);
  1312. set_couleur_label(c, label9_2);
  1313. }
  1314.  
  1315. void MainWindow::on_Bt_A4_clicked()
  1316. {
  1317. int n_midi=57;
  1318. play_note(n_midi);
  1319. QColor c=liste_couleurs[9];
  1320. dessine_1_note(6, 17, c); dessine_1_note(5, 12, c); dessine_1_note(4, 7, c); dessine_1_note(3, 2, c);
  1321. set_couleur_label(c, label10_2);
  1322. }
  1323.  
  1324. void MainWindow::on_Bt_Bb4_clicked()
  1325. { int n_midi=58;
  1326. play_note(n_midi);
  1327. QColor c=liste_couleurs[10];
  1328. dessine_1_note(6, 18, c); dessine_1_note(5, 13, c); dessine_1_note(4, 8, c); dessine_1_note(3, 3, c);
  1329. set_couleur_label(c, label11_2);
  1330. }
  1331.  
  1332. void MainWindow::on_Bt_B4_clicked()
  1333. {
  1334. int n_midi=59;
  1335. play_note(n_midi);
  1336. QColor c=liste_couleurs[11];
  1337. dessine_1_note(2, 0, c); dessine_1_note(3, 4, c); dessine_1_note(4, 9, c); dessine_1_note(5, 14, c);
  1338. set_couleur_label(c, label12_2);
  1339. }
  1340.  
  1341. void MainWindow::on_Bt_C5_clicked()
  1342. {
  1343. int n_midi=60;
  1344. play_note(n_midi);
  1345. QColor c=liste_couleurs[0];
  1346. dessine_1_note(2, 1, c); dessine_1_note(3, 5, c); dessine_1_note(4, 10, c); dessine_1_note(5, 15, c);
  1347. set_couleur_label(c, label1_3);
  1348. }
  1349.  
  1350. void MainWindow::on_Bt_Cd5_clicked()
  1351. {
  1352. int n_midi=61;
  1353. play_note(n_midi);
  1354. QColor c=liste_couleurs[1];
  1355. dessine_1_note(2, 2, c); dessine_1_note(3, 6, c); dessine_1_note(4, 11, c); dessine_1_note(5, 16, c);
  1356. set_couleur_label(c, label2_3);
  1357. }
  1358.  
  1359. void MainWindow::on_Bt_D5_clicked()
  1360. {
  1361. int n_midi=62;
  1362. play_note(n_midi);
  1363. QColor c=liste_couleurs[2];
  1364. dessine_1_note(2, 3, c); dessine_1_note(3, 7, c); dessine_1_note(4, 12, c); dessine_1_note(5, 17, c);
  1365. set_couleur_label(c, label3_3);
  1366. }
  1367.  
  1368. void MainWindow::on_Bt_Eb5_clicked()
  1369. {
  1370. int n_midi=63;
  1371. play_note(n_midi);
  1372. QColor c=liste_couleurs[3];
  1373. dessine_1_note(2, 4, c); dessine_1_note(3, 8, c); dessine_1_note(4, 13, c); dessine_1_note(5, 18, c);
  1374. set_couleur_label(c, label4_3);
  1375. }
  1376.  
  1377. void MainWindow::on_Bt_E5_clicked()
  1378. {
  1379. int n_midi=64;
  1380. play_note(n_midi);
  1381. QColor c=liste_couleurs[4];
  1382. dessine_1_note(1, 0, c); dessine_1_note(2, 5, c); dessine_1_note(3, 9, c); dessine_1_note(4, 14, c);
  1383. set_couleur_label(c, label5_3);
  1384.  
  1385. }
  1386.  
  1387. void MainWindow::on_Bt_F5_clicked()
  1388. {
  1389. int n_midi=65;
  1390. play_note(n_midi);
  1391. QColor c=liste_couleurs[5];
  1392. dessine_1_note(1, 1, c); dessine_1_note(2, 6, c); dessine_1_note(3, 10, c); dessine_1_note(4, 15, c);
  1393. set_couleur_label(c, label6_3);
  1394. }
  1395.  
  1396. void MainWindow::on_Bt_Fd5_clicked()
  1397. {
  1398. int n_midi=66;
  1399. play_note(n_midi);
  1400. QColor c=liste_couleurs[6];
  1401. dessine_1_note(1, 2, c); dessine_1_note(2, 7, c); dessine_1_note(3, 11, c); dessine_1_note(4, 16, c);
  1402. set_couleur_label(c, label7_3);
  1403. }
  1404.  
  1405. void MainWindow::on_Bt_G5_clicked()
  1406. {
  1407. int n_midi=67;
  1408. play_note(n_midi);
  1409. QColor c=liste_couleurs[7];
  1410. dessine_1_note(1, 3, c); dessine_1_note(2, 8, c); dessine_1_note(3, 12, c); dessine_1_note(4, 17, c);
  1411. set_couleur_label(c, label8_3);
  1412. }
  1413.  
  1414. void MainWindow::on_Bt_Gd5_clicked()
  1415. {
  1416. int n_midi=68;
  1417. play_note(n_midi);
  1418. QColor c=liste_couleurs[8];
  1419. dessine_1_note(1, 4, c); dessine_1_note(2, 9, c); dessine_1_note(3, 13, c); dessine_1_note(4, 18, c);
  1420. set_couleur_label(c, label9_3);
  1421. }
  1422.  
  1423. void MainWindow::on_Bt_A5_clicked()
  1424. {
  1425. int n_midi=69;
  1426. play_note(n_midi);
  1427. QColor c=liste_couleurs[9];
  1428. dessine_1_note(1, 5, c); dessine_1_note(2, 10, c); dessine_1_note(3, 14, c);
  1429. set_couleur_label(c, label10_3);
  1430. }
  1431.  
  1432. void MainWindow::on_Bt_Bb5_clicked()
  1433. {
  1434. int n_midi=70;
  1435. play_note(n_midi);
  1436. QColor c=liste_couleurs[10];
  1437. dessine_1_note(1, 6, c); dessine_1_note(2, 11, c); dessine_1_note(3, 15, c);
  1438. set_couleur_label(c, label11_3);
  1439. }
  1440.  
  1441. void MainWindow::on_Bt_B5_clicked()
  1442. {
  1443. int n_midi=71;
  1444. play_note(n_midi);
  1445. QColor c=liste_couleurs[11];
  1446. dessine_1_note(1, 7, c); dessine_1_note(2, 12, c); dessine_1_note(3, 16, c);
  1447. set_couleur_label(c, label12_3);
  1448. }
  1449.  
  1450.  
  1451. void MainWindow::on_Bt_C6_clicked()
  1452. {
  1453. int n_midi=72;
  1454. play_note(n_midi);
  1455. QColor c=liste_couleurs[0];
  1456. dessine_1_note(1, 8, c); dessine_1_note(2, 13, c); dessine_1_note(3, 17, c);
  1457. set_couleur_label(c, label1_4);
  1458. }
  1459.  
  1460. void MainWindow::on_Bt_Cd6_clicked()
  1461. {
  1462. int n_midi=73;
  1463. play_note(n_midi);
  1464. QColor c=liste_couleurs[1];
  1465. dessine_1_note(1, 9, c); dessine_1_note(2, 14, c); dessine_1_note(3, 18, c);
  1466. set_couleur_label(c, label2_4);
  1467. }
  1468.  
  1469.  
  1470. void MainWindow::on_Bt_D6_clicked()
  1471. {
  1472. int n_midi=74;
  1473. play_note(n_midi);
  1474. QColor c=liste_couleurs[2];
  1475. dessine_1_note(1, 10, c); dessine_1_note(2, 15, c);
  1476. set_couleur_label(c, label3_4);
  1477. }
  1478.  
  1479. void MainWindow::on_Bt_Eb6_clicked()
  1480. {
  1481. int n_midi=75;
  1482. play_note(n_midi);
  1483. QColor c=liste_couleurs[3];
  1484. dessine_1_note(1, 11, c); dessine_1_note(2, 16, c);
  1485. set_couleur_label(c, label4_4);
  1486. }
  1487.  
  1488. void MainWindow::on_Bt_E6_clicked()
  1489. {
  1490. int n_midi=76;
  1491. play_note(n_midi);
  1492. QColor c=liste_couleurs[4];
  1493. dessine_1_note(1, 12, c); dessine_1_note(2, 17, c);
  1494. set_couleur_label(c, label5_4);
  1495. }
  1496.  
  1497. void MainWindow::on_Bt_F6_clicked()
  1498. {
  1499. int n_midi=77;
  1500. play_note(n_midi);
  1501. QColor c=liste_couleurs[5];
  1502. dessine_1_note(1, 13, c); dessine_1_note(2, 18, c);
  1503. set_couleur_label(c, label6_4);
  1504. }
  1505.  
  1506. void MainWindow::on_Bt_Fd6_clicked()
  1507. {
  1508. int n_midi=78;
  1509. play_note(n_midi);
  1510. QColor c=liste_couleurs[6];
  1511. dessine_1_note(1, 14, c); dessine_1_note(2, 19, c);
  1512. set_couleur_label(c, label7_4);
  1513. }
  1514.  
  1515. void MainWindow::on_Bt_G6_clicked()
  1516. {
  1517. int n_midi=79;
  1518. play_note(n_midi);
  1519. QColor c=liste_couleurs[7];
  1520. dessine_1_note(1, 15, c); dessine_1_note(2, 20, c);
  1521. set_couleur_label(c, label8_4);
  1522. }
  1523.  
  1524. void MainWindow::on_Bt_Gd6_clicked()
  1525. {
  1526. int n_midi=80;
  1527. play_note(n_midi);
  1528. QColor c=liste_couleurs[8];
  1529. dessine_1_note(1, 16, c);
  1530. set_couleur_label(c, label9_4);
  1531. }
  1532.  
  1533. void MainWindow::on_Bt_A6_clicked()
  1534. {
  1535. int n_midi=81;
  1536. play_note(n_midi);
  1537. QColor c=liste_couleurs[9];
  1538. dessine_1_note(1, 17, c);
  1539. set_couleur_label(c, label10_4);
  1540. }
  1541.  
  1542. void MainWindow::on_Bt_Bb6_clicked()
  1543. {
  1544. int n_midi=82;
  1545. play_note(n_midi);
  1546. QColor c=liste_couleurs[10];
  1547. dessine_1_note(1, 18, c);
  1548. set_couleur_label(c, label11_4);
  1549. }
  1550.  
  1551.  
  1552. void MainWindow::on_Bt_B6_clicked()
  1553. {
  1554. int n_midi=83;
  1555. play_note(n_midi);
  1556. QColor c=liste_couleurs[11];
  1557. dessine_1_note(1, 19, c);
  1558. set_couleur_label(c, label12_4);
  1559. }
  1560.  
  1561. void MainWindow::on_Bt_C7_clicked()
  1562. {
  1563. int n_midi=84;
  1564. play_note(n_midi);
  1565. QColor c=liste_couleurs[0];
  1566. dessine_1_note(1, 20, c);
  1567. //set_couleur_label(c, label13_4);
  1568. }
  1569.  
  1570.  
  1571.  
  1572. void MainWindow::joue_1_ligne(int ligne_i)
  1573. {
  1574. QString s1;
  1575.  
  1576. for(int C=0; C<4; C++)
  1577. {
  1578. //on_Bt_RAZ_clicked();
  1579. s1 = tableWidget_3->item(ligne_i, C)->text();
  1580. s1 = s1.left(3);
  1581. int m1 = s1.toInt();
  1582. execute_note_midi(m1);
  1583. }
  1584. }
  1585.  
  1586.  
  1587. void MainWindow::complete_case(int row, int column, QString s1, QColor c1, QColor c2, bool bold1, QTableWidget *QTI)
  1588. {
  1589. QTableWidgetItem *Item1 = new QTableWidgetItem();
  1590. Item1->QTableWidgetItem::setForeground(c1);
  1591. Item1->QTableWidgetItem::setBackground(c2);
  1592.  
  1593. QFont font1;
  1594. font1.setBold(bold1);
  1595. Item1->setFont(font1);
  1596. Item1->setTextAlignment(Qt::AlignCenter);
  1597.  
  1598. Item1->setText(s1);
  1599. QTI->setItem(row,column,Item1);
  1600. }
  1601.  
  1602.  
  1603. void MainWindow::affi_positions_doigts_dans_status(QString s_i)
  1604. {
  1605. // et dans le cadre 'Position de doigts' (tableWidget_doigts)
  1606. // et numérote les notes jouées sur le manche
  1607.  
  1608. QString s2, s3;
  1609. int corde1, case1, num1;
  1610. init_tableWidget_doigts();
  1611.  
  1612. s3="";
  1613. //---------------------------------------------------------------------------------------
  1614. s2=extraction_data(s_i, "D0v=");
  1615. if((s2 != "") && (s2 != "-"))
  1616. {
  1617. num1=0;
  1618. tableWidget_doigts->setItem(0, 0, new QTableWidgetItem (s2) ); // corde
  1619. tableWidget_doigts->item(0, 0)->setTextAlignment(Qt::AlignCenter);
  1620. s3 += "( DOIGT 1 corde " + s2;
  1621. corde1 = s2.toInt();
  1622. label_44->setText("corde " + s2);
  1623.  
  1624. s2=extraction_data(s_i, "D0h=");
  1625. case1 = s2.toInt();
  1626. s3 += " case " + s2 + " ) ";
  1627. tableWidget_doigts->setItem(0, 1, new QTableWidgetItem (s2) ); // case
  1628. tableWidget_doigts->item(0, 1)->setTextAlignment(Qt::AlignCenter);
  1629. numerote_1_note(corde1, case1, num1);
  1630. label_45->setText("case " + s2);
  1631. }
  1632. //---------------------------------------------------------------------------------------
  1633. s2=extraction_data(s_i, "D1v=");
  1634. if((s2 != "") && (s2 != "-"))
  1635. {
  1636. num1=1;
  1637. tableWidget_doigts->setItem(1, 0, new QTableWidgetItem (s2) ); // corde
  1638. tableWidget_doigts->item(1, 0)->setTextAlignment(Qt::AlignCenter);
  1639. s3 += "( DOIGT 1 corde " + s2;
  1640. corde1 = s2.toInt();
  1641. label_44->setText("corde " + s2);
  1642.  
  1643. s2=extraction_data(s_i, "D1h=");
  1644. case1 = s2.toInt();
  1645. s3 += " case " + s2 + " ) ";
  1646. tableWidget_doigts->setItem(1, 1, new QTableWidgetItem (s2) ); // case
  1647. tableWidget_doigts->item(1, 1)->setTextAlignment(Qt::AlignCenter);
  1648. numerote_1_note(corde1, case1, num1);
  1649. label_45->setText("case " + s2);
  1650. }
  1651. //---------------------------------------------------------------------------------------
  1652. s2=extraction_data(s_i, "D2v=");
  1653. if((s2 != "") && (s2 != "-"))
  1654. {
  1655. bool ok; int dec = s2.toInt(&ok, 10);
  1656. if (ok==true)
  1657. {
  1658. num1=2;
  1659. tableWidget_doigts->setItem(2, 0, new QTableWidgetItem (s2) ); // corde
  1660. tableWidget_doigts->item(2, 0)->setTextAlignment(Qt::AlignCenter);
  1661. s3 += "( DOIGT 2 corde " + s2;
  1662. corde1 = s2.toInt();
  1663. label_44->setText("corde " + s2);
  1664.  
  1665.  
  1666. s2=extraction_data(s_i, "D2h=");
  1667. case1 = s2.toInt();
  1668. label_45->setText("case " + s2);
  1669.  
  1670. s3 += " case " + s2 + " ) ";
  1671. tableWidget_doigts->setItem(2, 1, new QTableWidgetItem (s2) ); // case
  1672. tableWidget_doigts->item(2, 1)->setTextAlignment(Qt::AlignCenter);
  1673. numerote_1_note(corde1, case1, num1);
  1674. }
  1675. }
  1676. //---------------------------------------------------------------------------------------
  1677.  
  1678. s2=extraction_data(s_i, "D3v=");
  1679. if((s2 != "") && (s2 != "-"))
  1680. {
  1681. bool ok; int dec = s2.toInt(&ok, 10);
  1682. if (ok==true)
  1683. {
  1684. num1=3;
  1685. tableWidget_doigts->setItem(3, 0, new QTableWidgetItem (s2) ); // corde
  1686. tableWidget_doigts->item(3, 0)->setTextAlignment(Qt::AlignCenter);
  1687. s3 += "( DOIGT 3 corde " + s2;
  1688. corde1 = s2.toInt();
  1689. label_44->setText("corde " + s2);
  1690.  
  1691.  
  1692. s2=extraction_data(s_i, "D3h=");
  1693. case1 = s2.toInt();
  1694. s3 += " case " + s2 + " ) ";
  1695. label_45->setText("case " + s2);
  1696. tableWidget_doigts->setItem(3, 1, new QTableWidgetItem (s2) ); // case
  1697. tableWidget_doigts->item(3, 1)->setTextAlignment(Qt::AlignCenter);
  1698. numerote_1_note(corde1, case1, num1);
  1699. }
  1700. }
  1701. //---------------------------------------------------------------------------------------
  1702. s2=extraction_data(s_i, "D4v=");
  1703. if((s2 != "") && (s2 != "-"))
  1704. {
  1705. bool ok; int dec = s2.toInt(&ok, 10);
  1706. if (ok==true)
  1707. {
  1708. num1=4;
  1709. tableWidget_doigts->setItem(4, 0, new QTableWidgetItem (s2) ); // corde
  1710. tableWidget_doigts->item(4, 0)->setTextAlignment(Qt::AlignCenter);
  1711. s3 += "( DOIGT 4 corde " + s2;
  1712. corde1 = s2.toInt();
  1713. label_44->setText("corde " + s2);
  1714.  
  1715.  
  1716. s2=extraction_data(s_i, "D4h=");
  1717. case1 = s2.toInt();
  1718. s3 += " case " + s2 + " ) ";
  1719. label_45->setText("case " + s2);
  1720. tableWidget_doigts->setItem(4, 1, new QTableWidgetItem (s2) ); // case
  1721. tableWidget_doigts->item(4, 1)->setTextAlignment(Qt::AlignCenter);
  1722. numerote_1_note(corde1, case1, num1);
  1723. }
  1724. }
  1725. //---------------------------------------------------------------------------------------
  1726.  
  1727. statusbar->showMessage(s3);
  1728. }
  1729.  
  1730. /*
  1731. QString MainWindow::nom_note(int mid)
  1732. {
  1733.   QString s1;
  1734.  
  1735.   int h1 = calcul_hauteur_note(mid);
  1736.   h1-=3;
  1737.   if(h1<0){h1+=12;}
  1738.   if(h1>11){h1-=12;}
  1739.   s1 = gamme_chromatique[h1];
  1740.   return s1;
  1741. }
  1742. */
  1743.  
  1744. void MainWindow::affiche_liste_notes() // en TEXTE dans le petit tableau
  1745. {
  1746. NOTE_importee note_i;
  1747. QString s1;
  1748.  
  1749. // gestion_mesures();
  1750.  
  1751. tableWidget_lst_notes->clear();
  1752. tableWidget_lst_notes->setRowCount(0);
  1753. init_TAB_lst_notes();
  1754.  
  1755. int n_max = liste_NOTES_importees.length();
  1756. for(int n=0; n<n_max; n++)
  1757. {
  1758. note_i=liste_NOTES_importees[n];
  1759. int numero = note_i.numero;
  1760. int midi = note_i.midi;
  1761. int n_barre =note_i.n_barre;
  1762. int n_temps =note_i.n_temps;
  1763. int duree = note_i.duree;
  1764.  
  1765. int num_ligne = tableWidget_lst_notes->rowCount();
  1766. tableWidget_lst_notes->setRowCount(num_ligne+1); // ajout une ligne au tableau
  1767.  
  1768. s1.setNum(numero);
  1769. complete_case(n, 0, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1770.  
  1771. s1.setNum(midi);
  1772. int h1 = calcul_hauteur_note(midi); h1-=3; if(h1<0){h1+=12;} if(h1>11){h1-=12;}
  1773. QColor couleur1 = liste_couleurs[h1];
  1774. complete_case(n, 1, s1, "#000000", couleur1, true, tableWidget_lst_notes);
  1775.  
  1776.  
  1777. s1 = nom_note_FR(midi);
  1778. complete_case(n, 2, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1779.  
  1780. s1.setNum(n_barre);
  1781. complete_case(n, 3, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1782.  
  1783. s1.setNum(n_temps); // ok
  1784. complete_case(n, 4, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1785.  
  1786. s1.setNum(duree); //ok
  1787. complete_case(n, 5, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1788.  
  1789. /*
  1790.   if (duree == 16) {s1 = "R";} // Ronde
  1791.   if (duree == 12) {s1 = "B.";}
  1792.   if (duree == 8) {s1 = "B";} // blanche
  1793.   if (duree == 4) {s1 = "N";} // noire
  1794.   if (duree == 2) {s1 = "c";} // croche
  1795.   if (duree == 1) {s1 = "db_c";} // double croche
  1796.   if (duree == 0) {s1 = "-";}
  1797.   //if (midi == 100) {s1 = "--";}
  1798.  
  1799.   complete_case(n, 6, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1800. */
  1801. }
  1802. }
  1803.  
  1804. /*
  1805. void MainWindow::affiche_liste_notes() // en TEXTE dans le petit tableau
  1806. {
  1807.   NOTE_importee note_i;
  1808.   QString s1;
  1809.  
  1810.   tableWidget_lst_notes->clear();
  1811.   tableWidget_lst_notes->setRowCount(0);
  1812.   init_TAB_lst_notes();
  1813.  
  1814.   int n_max = liste_NOTES_importees.length();
  1815.   for(int n=0; n<n_max; n++)
  1816.   {
  1817.   note_i=liste_NOTES_importees[n];
  1818.   int numero = note_i.numero;
  1819.   int midi = note_i.midi;
  1820.   int n_barre =note_i.n_barre;
  1821.   int n_temps =note_i.n_temps;
  1822.   int duree = note_i.duree;
  1823.  
  1824.  
  1825.   int num_ligne = tableWidget_lst_notes->rowCount();
  1826.   tableWidget_lst_notes->setRowCount(num_ligne+1); // ajout une ligne au tableau
  1827.  
  1828.   s1.setNum(numero);
  1829.   complete_case(n, 0, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1830.  
  1831.   s1.setNum(midi);
  1832.   int h1 = calcul_hauteur_note(midi); h1-=3; if(h1<0){h1+=12;} if(h1>11){h1-=12;}
  1833.   QColor couleur1 = liste_couleurs[h1];
  1834.   complete_case(n, 1, s1, "#000000", couleur1, true, tableWidget_lst_notes);
  1835.  
  1836.   s1 = nom_note(midi);
  1837.   complete_case(n, 2, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1838.  
  1839.   s1.setNum(n_barre);
  1840.   complete_case(n, 3, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  1841.  
  1842.   s1.setNum(n_temps);
  1843.   complete_case(n, 4, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1844.  
  1845.   s1.setNum(duree);
  1846.   complete_case(n, 5, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1847.  
  1848.   if (duree == 16) {s1 = "R";} // Ronde
  1849.   if (duree == 12) {s1 = "B.";}
  1850.   if (duree == 8) {s1 = "B";} // blanche
  1851.   if (duree == 4) {s1 = "N";} // noire
  1852.   if (duree == 2) {s1 = "c";} // croche
  1853.   if (duree == 1) {s1 = "db_c";} // double croche
  1854.   if (duree == 0) {s1 = "-";}
  1855.  
  1856.   complete_case(n, 5, s1, "#000000", "#FFFFFF", true, tableWidget_lst_notes);
  1857.   }
  1858. }
  1859. */
  1860.  
  1861.  
  1862. void MainWindow::on_tableWidget_3_cellClicked(int row, int column)
  1863. {
  1864. ligne_TW3 = row;
  1865. QString s1, s2, s3, ACC, cases;
  1866. QString duree_txt;
  1867. int di=0;
  1868. int R;
  1869.  
  1870. //checkBox_not_erase->setChecked(true);
  1871.  
  1872. R = tableWidget_3->currentRow();
  1873. num_ligne_en_cours = row;
  1874. s1.setNum(R+1);
  1875. lineEdit_9->setText(s1);
  1876.  
  1877. encadrement_ligne();
  1878.  
  1879. s2 = tableWidget_3->item(row, column)->text(); // actuellement dans la case cible
  1880. s1 = lineEdit_n_midi->text();
  1881.  
  1882. int m1 = s1.toInt();
  1883. if ((column<3) && mode_depot_note == true)
  1884. {
  1885. mode_depot_note = false;
  1886. statusbar->showMessage("");
  1887. MainWindow::setCursor(Qt::ArrowCursor);
  1888. if(s1 != s2) // alors on inscrit la nouvelle valeur dans la case
  1889. {
  1890. int h1 = calcul_hauteur_note(m1); // h1 = 0..11
  1891. h1-=3;
  1892. if(h1<0){h1+=12;}
  1893. if(h1>11){h1-=12;}
  1894.  
  1895. s3 = " " + gamme_chromatique[h1];
  1896. s1 += s3;
  1897.  
  1898. QColor couleur_case = liste_couleurs[h1];
  1899.  
  1900. complete_case(row, column, s1, "#000000", couleur_case, false, tableWidget_3);
  1901.  
  1902. tableWidget_3->resizeColumnsToContents();
  1903. }
  1904. else // on efface la valeur
  1905. {
  1906. tableWidget_3->setItem(row, column, new QTableWidgetItem ("--") );
  1907. }
  1908. init_TW_T();
  1909. }
  1910.  
  1911.  
  1912. if (column==4) // celle qui contient les petits boutons ( triangles '>' verts)
  1913. {
  1914. //effacer_calque(scene1, calque_notes);
  1915.  
  1916. ACC = tableWidget_3->item(row, 9)->text();
  1917. cases = tableWidget_3->item(row, 10)->text();
  1918. //qDebug() << "ACC" << ACC;
  1919. //qDebug() << "cases" << cases;
  1920.  
  1921. notes_silencieuses = true;
  1922. joue_accord_complet(ACC, cases); // représentation graphique de la position avant de jouer la note
  1923. notes_silencieuses = false;
  1924.  
  1925. joue_1_ligne(row);
  1926.  
  1927. s1 = tableWidget_3->item(row, 11)->text();
  1928. affi_positions_doigts_dans_status(s1);
  1929. }
  1930.  
  1931.  
  1932. if (column==5) { write_Time_line(); }
  1933.  
  1934. if (column==8) // ACC
  1935. {
  1936. s1 = tableWidget_3->item(row, 9)->text();
  1937. s2 = tableWidget_3->item(row, 10)->text();
  1938.  
  1939.  
  1940. if (s1 !=" ")
  1941. {
  1942. notes_silencieuses = true;
  1943. joue_accord_complet(s1, s2);
  1944. notes_silencieuses = false;
  1945. }
  1946. }
  1947.  
  1948. if (column==11)
  1949. {
  1950. QMessageBox msgBox;
  1951. QString s1;
  1952. s1 = "Colonne read only";
  1953. s1 += "\n";
  1954. s1 += "Utiliser le cadre 'de saisie 'Position des doigts'";
  1955. s1 += "\n";
  1956. s1 += "pour saisir les positions.";
  1957. msgBox.setText(s1);
  1958. msgBox.exec();
  1959. }
  1960.  
  1961. s2 = tableWidget_3->item(row, 6)->text();
  1962. s2 = s2.mid(1);
  1963. mesure_a_encadrer = s2.toInt();
  1964.  
  1965. write_Time_line();
  1966.  
  1967. duree_txt = tableWidget_3->item(R, 5)->text();
  1968.  
  1969. di = duree_txt.toInt();
  1970. nb_colonnes_a_encadrer = di;
  1971.  
  1972. int T_note;
  1973. T_note = calcul_T_note(row);
  1974. num_colonne_a_encadrer = T_note;
  1975.  
  1976. encadrement_colonne();
  1977. }
  1978.  
  1979.  
  1980. /*
  1981. void MainWindow::on_tableWidget_3_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
  1982. {
  1983.   if (currentColumn == 5) {gestion_mesures();} // si on change la durée d'une note
  1984. }
  1985. */
  1986.  
  1987.  
  1988.  
  1989. void MainWindow::on_Bt_ACCORD_1_clicked()
  1990. {
  1991. // accord majeur
  1992. //effacer_calque(scene1, calque_notes);
  1993. on_Bt_RAZ_clicked();
  1994. label_44->setText("-");
  1995. label_45->setText("-");
  1996.  
  1997. checkBox_not_erase->setChecked(true);
  1998.  
  1999. QString s1, s2, s3, s4;
  2000. int d = spinBox_2->value();
  2001.  
  2002. s1 = gamme_chromatique[d];
  2003. s2="M";
  2004. s1+=s2;
  2005. lineEdit_10->setText(s1);
  2006.  
  2007. case_min = spinBox_4->value(); s3.setNum(case_min);
  2008. case_max = spinBox_5->value(); s4.setNum(case_max);
  2009. lineEdit_14->setText(s3 + "a" +s4);
  2010.  
  2011. label_43->clear();
  2012. encadre_accord(case_min, case_max);
  2013.  
  2014. //on_Bt_RAZ_clicked();
  2015. execute_note_midi(28 + spinBox_2->value());
  2016. execute_note_midi(31 + spinBox_2->value());
  2017. execute_note_midi(36 + spinBox_2->value());
  2018.  
  2019. execute_note_midi(28+12 + spinBox_2->value());
  2020. execute_note_midi(31+12 + spinBox_2->value());
  2021. execute_note_midi(36+12 + spinBox_2->value());
  2022.  
  2023. execute_note_midi(28+12+12 + spinBox_2->value());
  2024. execute_note_midi(31+12+12 + spinBox_2->value());
  2025. execute_note_midi(36+12+12 + spinBox_2->value());
  2026.  
  2027. execute_note_midi(28+12+12+12 + spinBox_2->value());
  2028. execute_note_midi(31+12+12+12 + spinBox_2->value());
  2029. execute_note_midi(36+12+12+12 + spinBox_2->value());
  2030.  
  2031. type_accords = 1;
  2032. }
  2033.  
  2034.  
  2035.  
  2036. void MainWindow::on_Bt_ACCORD_2_clicked()
  2037. {
  2038. // accord mineur
  2039.  
  2040. effacer_calque(scene1, calque_notes);
  2041. label_44->setText("-");
  2042. label_45->setText("-");
  2043.  
  2044. checkBox_not_erase->setChecked(true);
  2045.  
  2046. QString s1, s2, s3, s4;
  2047. int d = spinBox_2->value();
  2048.  
  2049. s1 = gamme_chromatique[d];
  2050. s2="m";
  2051. s1+=s2;
  2052. lineEdit_10->setText(s1);
  2053.  
  2054. case_min = spinBox_4->value(); s3.setNum(case_min);
  2055. case_max = spinBox_5->value(); s4.setNum(case_max);
  2056. lineEdit_14->setText(s3 + "a" +s4);
  2057.  
  2058.  
  2059. label_43->clear();
  2060. encadre_accord(case_min, case_max);
  2061.  
  2062. //on_Bt_RAZ_clicked();
  2063.  
  2064.  
  2065. execute_note_midi( 31 + spinBox_2->value());
  2066. execute_note_midi( 36 + spinBox_2->value());
  2067. execute_note_midi( 39 + spinBox_2->value());
  2068.  
  2069. execute_note_midi( 31+12 + spinBox_2->value());
  2070. execute_note_midi( 36+12 + spinBox_2->value());
  2071. execute_note_midi( 39+12 + spinBox_2->value());
  2072.  
  2073. execute_note_midi( 31+12+12 + spinBox_2->value());
  2074. execute_note_midi( 36+12+12 + spinBox_2->value());
  2075. execute_note_midi( 39+12+12 + spinBox_2->value());
  2076.  
  2077. execute_note_midi( 31+12+12+12 + spinBox_2->value());
  2078. execute_note_midi( 36+12+12+12 + spinBox_2->value());
  2079. execute_note_midi( 39+12+12+12 + spinBox_2->value());
  2080.  
  2081. type_accords = 2;
  2082. }
  2083.  
  2084.  
  2085. void MainWindow::on_Bt_ACCORD_3_clicked()
  2086. {
  2087. // accord 7eme de dominante
  2088.  
  2089. effacer_calque(scene1, calque_notes);
  2090. label_44->setText("-");
  2091. label_45->setText("-");
  2092. checkBox_not_erase->setChecked(true);
  2093.  
  2094. QString s1, s2, s3, s4;
  2095. int d = spinBox_2->value();
  2096.  
  2097. s1 = gamme_chromatique[d];
  2098. s2="7";
  2099. s1+=s2;
  2100. lineEdit_10->setText(s1);
  2101.  
  2102. case_min = spinBox_4->value(); s3.setNum(case_min);
  2103. case_max = spinBox_5->value(); s4.setNum(case_max);
  2104. lineEdit_14->setText(s3 + "a" +s4);
  2105.  
  2106. label_43->clear();
  2107. encadre_accord(case_min, case_max);
  2108.  
  2109. //on_Bt_RAZ_clicked();
  2110. execute_note_midi( 36 + spinBox_2->value());
  2111. execute_note_midi( 40 + spinBox_2->value());
  2112. execute_note_midi( 43 + spinBox_2->value());
  2113. execute_note_midi( 58 + spinBox_2->value());
  2114.  
  2115. execute_note_midi( 36+12 + spinBox_2->value());
  2116. execute_note_midi( 40+12 + spinBox_2->value());
  2117. execute_note_midi( 43+12 + spinBox_2->value());
  2118. execute_note_midi( 58+12 + spinBox_2->value());
  2119.  
  2120. execute_note_midi( 36+12+12 + spinBox_2->value());
  2121. execute_note_midi( 40+12+12 + spinBox_2->value());
  2122. execute_note_midi( 43+12+12 + spinBox_2->value());
  2123. execute_note_midi( 58+12+12 + spinBox_2->value());
  2124.  
  2125. type_accords = 3;
  2126. }
  2127.  
  2128.  
  2129. void MainWindow::on_Bt_NO_ACCORD_clicked() // note seule
  2130. {
  2131. QString s3, s4;
  2132.  
  2133. effacer_calque(scene1, calque_notes);
  2134.  
  2135. lineEdit_10->clear();
  2136. lineEdit_10->setText("-");
  2137. label_43->clear();
  2138.  
  2139. case_min = spinBox_4->value();
  2140. s3.setNum(case_min);
  2141.  
  2142. case_max = case_min;
  2143.  
  2144. spinBox_5->setValue(case_max);
  2145. s4.setNum(case_max);
  2146.  
  2147. lineEdit_14->setText(s3 + "a" +s4);
  2148.  
  2149. type_accords = 0;
  2150. }
  2151.  
  2152.  
  2153.  
  2154. void MainWindow::joue_accord_complet(QString ACC, QString cases)
  2155. {
  2156. // exemple: (Sol, 3a5) -> c.a.d case 3 à case 5
  2157. QString s1, s2b, s2c, s3, s4;
  2158. //QString degré_txt;
  2159. QString type;
  2160. int p1, p2;
  2161. s1 = ACC; // exemples : Sim, Sibm, Do, Dom, La, Lam, Sol, Solm, Mi7
  2162.  
  2163. if (!checkBox_not_erase->isChecked()) {on_Bt_RAZ_clicked();}
  2164.  
  2165. if ((ACC == "") || (ACC == " ") ) { return; }
  2166.  
  2167. /*
  2168. s1 "La"
  2169. s1 "Fa#"
  2170. s1 "Mi7"
  2171. s1 "Sim"
  2172. s1 "Sibm"
  2173. s1 "Do"
  2174. */
  2175. // détection du degré (0 pour Do , à 11 pour Si)
  2176. // rappel : gamme_chromatique<<"Do"<<"Do#"<<"Ré"<<"Mib"<<"Mi"<<"Fa"<<"Fa#"<<"Sol"<<"Sol#"<<"La"<<"Sib"<<"Si";
  2177.  
  2178. int n=11;
  2179. int deg = -1;
  2180. bool ok = false;
  2181. while ((n>0) && (ok == false))
  2182. {
  2183. QString s2a = gamme_chromatique[n];
  2184. p1 = s1.indexOf(s2a);
  2185. if (p1 != -1) {ok = true;}
  2186. n--;
  2187. }
  2188. if (ok == true) {deg = n+1; }
  2189.  
  2190. p1 = s1.indexOf("b");
  2191. if (p1 != -1) {deg --;} // bémol
  2192.  
  2193. s2b = ACC.right(1); // m, 7, mais aussi # ou la dernière lettre du nom de la note !
  2194.  
  2195. type = "MAJ"; // à priori
  2196. if (s2b == "m") {type = "min";}
  2197. if (s2b == "7") {type = "dom";}
  2198. if (s2b == "-") {type = "-";} // note seule
  2199.  
  2200. // intervalle de cases à jouer :
  2201.  
  2202. s2c = cases; // "0a3" ou "12a14" ...
  2203. p2=s2c.indexOf("a");
  2204.  
  2205. if (p2 != -1)
  2206. {
  2207. s3=s2c.left(p2);
  2208. case_min = s3.toInt();
  2209. spinBox_4->setValue(case_min);
  2210.  
  2211. s4 = s2c.mid(p2+1, 255);
  2212. int v4 = s4.toInt();
  2213.  
  2214. if (v4 >= case_min) // on accepte une case unique (genre "7a7") pour forcer une note unique à sa place
  2215. {
  2216. case_max = v4; // ici on enregistre le numero de la case max
  2217. spinBox_5->setValue(case_max);
  2218. }
  2219. }
  2220.  
  2221. else
  2222. {
  2223. case_min = 0;
  2224. spinBox_4->setValue(case_min);
  2225. case_max = 20; // numéro de la case
  2226. spinBox_5->setValue(case_max); // nombre de cases
  2227. }
  2228.  
  2229. notes_pleines = false; // ne représentera qu'un cercle
  2230.  
  2231. if (type=="MAJ") // accord majeur
  2232. {
  2233. spinBox_2->setValue(deg); // spinBox dans le cadre 'Configurateur d'Accords'
  2234. on_Bt_ACCORD_1_clicked();
  2235. }
  2236.  
  2237.  
  2238.  
  2239. if (type=="min") // accord mineur
  2240. {
  2241. spinBox_2->setValue(deg);
  2242. on_Bt_ACCORD_2_clicked();
  2243. }
  2244.  
  2245.  
  2246. if (type=="dom") // 7eme de dominante
  2247. {
  2248. spinBox_2->setValue(deg);
  2249. on_Bt_ACCORD_3_clicked();
  2250. }
  2251.  
  2252.  
  2253. if (type=="-") // note seule
  2254. {
  2255. // spinBox_2->setValue(D);
  2256. // on_Bt_ACCORD_3_clicked();
  2257.  
  2258. on_Bt_RAZ_clicked();
  2259. }
  2260.  
  2261. /*
  2262.   case_min = 0;
  2263.   spinBox_4->setValue(case_min);
  2264.   case_max = 20;
  2265.   spinBox_5->setValue(case_max);
  2266. */
  2267. notes_pleines = true;
  2268.  
  2269. s1 = type;
  2270. if (s1 == "dom") {s1 = "7e dom";}
  2271. label_43->setText(lineEdit_8->text() + " " +s1);
  2272.  
  2273.  
  2274. }
  2275.  
  2276.  
  2277. void MainWindow::affiche_details_note(uint midi)
  2278. {
  2279. QString s1;
  2280. s1.setNum(midi);
  2281. s1 = "m" + s1;
  2282. lineEdit_7->setText(s1);
  2283.  
  2284. affi_txt_en_couleur(midi, lineEdit_7b);
  2285. lineEdit_7b->setText(nom_note_FR(midi));
  2286.  
  2287. affi_txt_en_couleur(midi, lineEdit_7e);
  2288.  
  2289. s1=nom_note_GB(midi);
  2290. s1+=nom_octave_GB(midi);
  2291. lineEdit_7e->setText(s1);
  2292. }
  2293.  
  2294.  
  2295. void MainWindow::mousePressEvent(QMouseEvent *event)
  2296. {
  2297. QString s1, s2, s3;
  2298. int x_min, x_max, y_min, y_max;
  2299.  
  2300. x_min = graphicsView1->x();
  2301. x_max = x_min + graphicsView1->width();
  2302. y_min = graphicsView1->y();
  2303. y_max = y_min + graphicsView1->height();
  2304.  
  2305. x_clic_ecran = event->position().x();
  2306. y_clic_ecran = event->position().y();
  2307.  
  2308. if (x_clic_ecran > x_min && x_clic_ecran < x_max && y_clic_ecran > y_min && y_clic_ecran < y_max)
  2309. {
  2310.  
  2311. // suite à un clic sur le manche :
  2312. detecte_note_xy(x_clic_ecran, y_clic_ecran, &corde_jouee, &case_jouee); // actualise les variables globales
  2313.  
  2314. s1.setNum(case_jouee); lineEdit_case_i->setText(s1);
  2315. s1.setNum(corde_jouee); lineEdit_corde_i->setText(s1);
  2316.  
  2317. if (corde_jouee>0)
  2318. {
  2319. case_min = 0;
  2320. case_max = 20;
  2321. // checkBox_not_erase->setChecked(false);
  2322.  
  2323. if (!checkBox_not_erase->isChecked()) {on_Bt_RAZ_clicked();}
  2324.  
  2325. s2.setNum(corde_jouee);
  2326. label_44->setText("corde " + s2);
  2327. s3.setNum(case_jouee);
  2328. label_45->setText("case " + s3);
  2329.  
  2330. n_midi_jouee = calcul_midi(corde_jouee, case_jouee);
  2331.  
  2332. //affiche_details_note(n_midi_jouee);
  2333.  
  2334. calcul_hauteur_note(n_midi_jouee);
  2335. execute_note_midi( n_midi_jouee);
  2336. }
  2337. }
  2338. else
  2339. {
  2340. mode_depot_note = false;
  2341. statusbar->showMessage("");
  2342. MainWindow::setCursor(Qt::ArrowCursor);
  2343. }
  2344. }
  2345.  
  2346.  
  2347. void MainWindow::on_spinBox_2_valueChanged(int arg1)
  2348. {
  2349. int n=arg1;
  2350. lineEdit_8->setText(gamme_chromatique[n]);
  2351.  
  2352. lineEdit_10->clear();
  2353. lineEdit_14->clear();
  2354.  
  2355. }
  2356.  
  2357.  
  2358.  
  2359. void MainWindow::save_fichier_lst()
  2360. {
  2361. // enregisterment incrémentiel sur HDD (nom de fichier = 1..2...3...)
  2362.  
  2363. QString s1;
  2364. //QString ligne_i;
  2365. int numero=0;
  2366. QString s2;
  2367. QString chemin_out;
  2368.  
  2369. lecture_pause = 1;
  2370. Bt_lecture_2->setText(">");
  2371. Bt_lecture_2->setStyleSheet("QPushButton{background-color:#50FF1B;}");
  2372. lecture_pause =0;
  2373. s1.setNum(num_ligne_en_cours);// conversion num -> txt
  2374. Timer2->stop();
  2375.  
  2376. chemin_out = string_currentDir; //QDir::homePath() + "/GUITARE/ACCORDS/";
  2377.  
  2378.  
  2379. /*
  2380.   if (!dossier_out.exists())
  2381.   {
  2382.   QMessageBox msgBox;
  2383.   msgBox.setText("Le dossier : " + dossier_out.dirName() + " n'éxiste pas, je le crée");
  2384.   msgBox.exec();
  2385.   }
  2386. */
  2387. bool existe =1;
  2388. while(existe)
  2389. {
  2390. numero++;
  2391. s2.setNum(numero);
  2392. existe = QFile::exists(chemin_out + s2 + ".lst");
  2393.  
  2394.  
  2395. /*
  2396.   QMessageBox msgBox;
  2397.   QString s1;
  2398.   s1 = "Le fichier de destination (" + chemin_out + s2 + ".lst ) existe déjà";
  2399.   msgBox.setText(s1);
  2400.   msgBox.exec();
  2401. */
  2402. }
  2403.  
  2404. s2.setNum(numero);
  2405. int nb_lignes;
  2406.  
  2407. QFile file1(chemin_out + s2 + ".lst");
  2408. //file1.remove();
  2409.  
  2410. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2411. {
  2412. QTextStream file_out(&file1);
  2413.  
  2414. int vitesse = doubleSpinBox_vitesse->value();
  2415. QString s1;
  2416. s1.setNum(vitesse);
  2417. file_out << "v=" + s1 + ";";
  2418. file_out << char(10);
  2419. nb_lignes = liste_accords.length();
  2420. for (int i=0; i<nb_lignes; i++)
  2421. {
  2422. file_out << liste_accords[i]; // << char(10);
  2423. }
  2424. }
  2425. file1.close();
  2426.  
  2427. QMessageBox msgBox;
  2428. s1="Fichier enregistré: " + chemin_out + s2 + ".lst";
  2429. msgBox.setText(s1);
  2430. msgBox.exec();
  2431. }
  2432.  
  2433.  
  2434. int MainWindow::constitue_liste_accords() // en vue de l'enregistrement sur le HDD (par la fonction 'save_fichier_lst()' ci-dessus)
  2435. {
  2436. // remarque: les codes midi sont 40..84 qui correspondent à des caractères ASCII classiques.
  2437. // la valeur 100 est utilisée (ici) pour coder les barres de mesure
  2438. // plus exactement, les codes ascii 32..126 codents poue des caratères classiques.
  2439. // on peut donc les encoder dans des QString qui eux sont facilement recordables...
  2440. QString s1, s2, s3, s4; // les 4 valeurs midi d'un accord sous forme de texte
  2441. QString ligne_i;
  2442. int m1, p1;
  2443.  
  2444. liste_accords.clear();
  2445. int RC=tableWidget_3->rowCount();
  2446.  
  2447. int L_save_min = lineEdit_12->text().toInt() -1;
  2448. int L_save_max = lineEdit_13->text().toInt();
  2449.  
  2450. if (L_save_min < 0) {L_save_min = 0;}
  2451. if (L_save_max > RC) {L_save_max = RC;}
  2452.  
  2453. if ((L_save_max-L_save_min) < 2)
  2454. {
  2455. QMessageBox msgBox;
  2456. msgBox.setText("Le tableau doit contenir au minimum 2 lignes !");
  2457. msgBox.exec();
  2458. return 1;
  2459. }
  2460.  
  2461. for(int L=L_save_min; L<L_save_max; L++)
  2462. {
  2463. ligne_i.clear();
  2464. s1 = tableWidget_3->item(L, 0)->text(); s1 = s1.left(2);
  2465. m1 = s1.toInt(); if ((m1<40)||(m1>84)) {s1="";} // code midi de la note
  2466.  
  2467. s1 = "m1=" +s1 + ";";
  2468. ligne_i += s1;
  2469.  
  2470. s1 = tableWidget_3->item(L, 1)->text(); s1 = s1.left(2);
  2471. m1 = s1.toInt(); if ((m1<40)||(m1>84)) {s1="";}
  2472. s1 = "m2=" +s1 + ";";
  2473. ligne_i += s1;
  2474.  
  2475. s1 = tableWidget_3->item(L, 2)->text(); s1 = s1.left(2);
  2476. m1 = s1.toInt(); if ((m1<40)||(m1>84)) {s1="";}
  2477. s1 = "m3=" +s1 + ";";
  2478. ligne_i += s1;
  2479.  
  2480. s1 = tableWidget_3->item(L, 3)->text(); // commentaire
  2481. s1 = "cmt=" +s1 + ";";
  2482. ligne_i += s1;
  2483.  
  2484. s1 = tableWidget_3->item(L, 5)->text(); // DUREE
  2485. s1 = " " + s1; s1=s1.right(2); // ajoute 1 espace si nombre<10
  2486.  
  2487. s1 = "d=" +s1 + ";"; // durée
  2488. ligne_i += s1;
  2489.  
  2490. s1 = tableWidget_3->item(L, 6)->text(); // MESURE
  2491. s1 = "M=" +s1 + ";";
  2492. ligne_i += s1;
  2493.  
  2494. s1 = tableWidget_3->item(L, 7)->text(); // tps
  2495. s1 = "T=" +s1 + ";";
  2496. ligne_i += s1;
  2497.  
  2498. //s1 = tableWidget_3->item(L, 8)->text(); // disponible
  2499. //s1 = "x=" +s1 + ";";
  2500. //ligne_x += s1;
  2501.  
  2502. s1 = tableWidget_3->item(L, 9)->text(); // ACC // "11min
  2503. s1 = "a=" + s1 + ";";
  2504. ligne_i += s1;
  2505.  
  2506. s1 = tableWidget_3->item(L, 10)->text(); ; // "7a9"
  2507. s1 = "cases=" + s1 + ";";
  2508. ligne_i += s1;
  2509.  
  2510. s1 = tableWidget_3->item(L, 11)->text(); // doigts (la case contient toute le string en question),
  2511. // voir la fonction : 'on_Bt_copie_doigts_to_TW3_clicked()' qui constitue ce string à partir du 'tableWidget_doigts.'
  2512.  
  2513. qDebug() << "" << s1;
  2514. qDebug() << "______________";
  2515.  
  2516. ligne_i += s1;
  2517.  
  2518. ligne_i += '\n';
  2519.  
  2520. liste_accords << ligne_i;
  2521. }
  2522. return 0;
  2523. }
  2524.  
  2525.  
  2526.  
  2527. void MainWindow::on_Bt_save_clicked()
  2528. {
  2529. int R = constitue_liste_accords();
  2530. if (R == 0) { save_fichier_lst(); }
  2531.  
  2532. }
  2533.  
  2534.  
  2535. int MainWindow::dechiffre_note(QString label_i, int L, int c)
  2536. {
  2537.  
  2538. int p1a, p1b, m1, h1;
  2539. QString ligne_i=liste_accords[L];
  2540. QString s1, s2;
  2541. QColor couleur1;
  2542.  
  2543. p1a=ligne_i.indexOf(label_i);
  2544. p1b=ligne_i.indexOf(";",p1a);
  2545. s1 = ligne_i.mid(p1a+3, p1b-(p1a+3));
  2546.  
  2547. if (s1=="") { return 0; }
  2548.  
  2549. m1 = s1.toInt();
  2550.  
  2551. if (m1==0) {return 0;}
  2552.  
  2553. h1 = calcul_hauteur_note(m1); // h1 = 0..11
  2554. h1-=3;
  2555. while(h1<0){h1+=12;}
  2556. if(h1>11){h1-=12;}
  2557. couleur1 = liste_couleurs[h1];
  2558. s2 = " " + gamme_chromatique[h1];
  2559.  
  2560. s1 += s2;
  2561.  
  2562. complete_case(L, c, s1, "#000000", couleur1, false, tableWidget_3);
  2563. return p1a;
  2564. }
  2565.  
  2566.  
  2567.  
  2568. int MainWindow::open_fichier_lst() // cette fonction est appelée par la fonction 'write_Tableau_vertical()'
  2569. {
  2570. QString ligne_i, str1;
  2571. QString s1;
  2572. int p1a, p1b;
  2573.  
  2574. // stop execution en cours
  2575. lecture_pause = 1;
  2576. Bt_lecture_2->setText("joue > debut");
  2577. Bt_lecture_2->setStyleSheet("QPushButton{background-color:#50FF1B;}");
  2578. lecture_pause =0;
  2579.  
  2580. s1.setNum(num_ligne_en_cours);// conversion num -> txt
  2581. Timer2->stop();
  2582.  
  2583. string_currentFile = QFileDialog::getOpenFileName(this, tr("Ouvrir Fichier accords..."), string_currentDir,
  2584. tr("Fichiers lst (*.lst);;All Files (*)"));
  2585.  
  2586. // qDebug() << "string_currentFile" << string_currentFile;
  2587.  
  2588. if (string_currentFile != "")
  2589. {
  2590. save_fichier_ini();
  2591. liste_str_in.clear();
  2592. liste_accords.clear();
  2593. }
  2594. else {return 0;}
  2595.  
  2596. int p1 = string_currentFile.lastIndexOf("/");
  2597.  
  2598. string_currentDir =string_currentFile.left(p1+1);
  2599.  
  2600. if (!string_currentFile.isEmpty())
  2601. {
  2602. lineEdit_1->setText(string_currentFile);
  2603. }
  2604. else {return 0;}
  2605.  
  2606. QFile file1(string_currentFile);
  2607. if (!file1.open(QIODevice::ReadOnly | QIODevice::Text)) return 1;
  2608. QTextStream TextStream1(&file1);
  2609.  
  2610. int num_ligne = 0;
  2611. ligne_i = TextStream1.readLine(); // vitesse
  2612.  
  2613. p1a=ligne_i.indexOf("v="); // duree
  2614. p1b=ligne_i.indexOf(";",p1a);
  2615. s1 = ligne_i.mid(p1a+2, p1b-(p1a+2));
  2616.  
  2617. int v1;
  2618. v1 = s1.toFloat();
  2619. doubleSpinBox_vitesse->setValue(v1);
  2620.  
  2621. while ( !TextStream1.atEnd() )
  2622. {
  2623. ligne_i = TextStream1.readLine();
  2624. liste_accords += ligne_i;
  2625. num_ligne++;
  2626. }
  2627.  
  2628. file1.close();
  2629.  
  2630. str1.setNum(num_ligne);
  2631. lineEdit_2->setText(str1 + " lignes");
  2632.  
  2633. int nb_de_lignes = num_ligne;
  2634.  
  2635. L_save_max = nb_de_lignes;
  2636.  
  2637. s1.setNum(0);
  2638. lineEdit_12->setText(s1);
  2639.  
  2640. s1.setNum(nb_de_lignes);
  2641. lineEdit_13->setText(s1);
  2642.  
  2643. return nb_de_lignes;
  2644. }
  2645.  
  2646.  
  2647. //---------------------------------------------------------------------------------------
  2648.  
  2649.  
  2650. void MainWindow::write_Time_line()
  2651. {
  2652.  
  2653. int m1;
  2654. int R;
  2655. QColor couleur1;
  2656. int duree_note, intervalle_t, Ti1, Ti2, numero_mesure;
  2657. QString s1, s2, s3, sm;
  2658. intervalle_t=0;
  2659. Ti1=0;
  2660.  
  2661. int Rmax= tableWidget_3->rowCount();
  2662. if (Rmax > 100) {Rmax =100;} // évite de saturer la mémoire RAM de l'ordi sur de morceaux trops longs!!
  2663.  
  2664. // ------------- colorie les cases horizontales (notes) ---------------------------
  2665. Ti2=0;
  2666.  
  2667. R=0;
  2668. while ((R < Rmax) && Ti2 < 300)
  2669. {
  2670. s1 = tableWidget_3->item(R, 5)->text();
  2671. duree_note = s1.toInt();
  2672.  
  2673. for (int dt=0; dt<duree_note; dt++)
  2674. {
  2675. s1 = tableWidget_3->item(R, 0)->text();
  2676. s1 = s1.left(2);
  2677. m1 = s1.toInt();
  2678. if ((m1 > 51) && (m1 < 97)) // si présence d'un code midi
  2679. {
  2680. couleur1 = tableWidget_3->item(R, 0)->background().color();
  2681. if(couleur1 != "#000000") { complete_case(1, Ti2, " ", "#CECECE", couleur1, false, tableWidget_T);}
  2682. }
  2683.  
  2684. s1 = tableWidget_3->item(R, 1)->text();
  2685. s1 = s1.left(2);
  2686. m1 = s1.toInt();
  2687.  
  2688. if ((m1 > 51) && (m1 < 97))
  2689. {
  2690. couleur1 = tableWidget_3->item(R, 1)->background().color();
  2691. if(couleur1 != "#000000") { complete_case(2, Ti2, " ", "#CECECE", couleur1, false, tableWidget_T);}
  2692. }
  2693.  
  2694. s1 = tableWidget_3->item(R, 2)->text();
  2695. s1 = s1.left(2);
  2696. m1 = s1.toInt();
  2697. if ((m1 > 51) && (m1 < 97))
  2698. {
  2699. couleur1 = tableWidget_3->item(R, 2)->background().color();
  2700. if(couleur1 != "#000000") { complete_case(3, Ti2, " ", "#CECECE", couleur1, false, tableWidget_T);}
  2701. }
  2702.  
  2703. s1 = tableWidget_3->item(R, 3)->text();
  2704. s1 = s1.left(2);
  2705. m1 = s1.toInt();
  2706. if ((m1 > 51) && (m1 < 97))
  2707. {
  2708. couleur1 = tableWidget_3->item(R, 3)->background().color();
  2709. if(couleur1 != "#000000") {complete_case(4, Ti2, " ", "#CECECE", couleur1, false, tableWidget_T);}
  2710. }
  2711. Ti2 ++;
  2712. }
  2713. R++;
  2714. }
  2715. // ----------------------------------------
  2716. numero_mesure =1; // DEPART
  2717.  
  2718. R=0;
  2719. while ((R < Rmax) && Ti1 < 300)
  2720. {
  2721. sm =tableWidget_3->item(R, 6)->text();
  2722.  
  2723. couleur1 = tableWidget_3->item(R, 6)->background().color();
  2724. if(couleur1 == "#888888")
  2725. {
  2726. s2.setNum(intervalle_t);
  2727.  
  2728. complete_case(0, Ti1-1, s2, "#000000", "#FFFFFF", false, tableWidget_T);
  2729. intervalle_t=0;
  2730.  
  2731. s3.setNum(numero_mesure);
  2732. complete_case(0, Ti1, s3, "#FFFFFF", "#555555", false, tableWidget_T);
  2733.  
  2734. trace_ligne_V(Ti1, numero_mesure);
  2735. s1 = tableWidget_3->item(R, 5)->text();
  2736. duree_note = s1.toInt();
  2737. intervalle_t += duree_note;
  2738. Ti1 += duree_note;
  2739. numero_mesure++;
  2740. }
  2741. else
  2742. {
  2743. s1 = tableWidget_3->item(R, 5)->text(); // durée de la note
  2744. duree_note = s1.toInt();
  2745. intervalle_t += duree_note;
  2746. Ti1 += duree_note;
  2747. }
  2748. R++;
  2749. }
  2750. }
  2751.  
  2752.  
  2753. //---------------------------------------------------------------------------------------
  2754. /*
  2755. void MainWindow::gestion_mesures()
  2756. {
  2757.  
  2758. // sur le tableau vertical
  2759.   QString s1, s2;
  2760.   int numero_mesure=0;
  2761.   int memo_numero_mesure=0;
  2762.   int temps=0;
  2763.   int duree_i=0;
  2764.   int total=0;
  2765.  
  2766.   for (int L=0; L<tableWidget_3->rowCount(); L++)
  2767.   {
  2768.   s1=tableWidget_3->item(L,5)->text();
  2769.   duree_i = s1.toInt();
  2770.  
  2771.   if (numero_mesure == memo_numero_mesure)
  2772.   {
  2773.   s2.setNum(total);
  2774.   complete_case(L-1, 7, s2, "#000000", "#C4F6FC", false, tableWidget_3); // BLEU CLAIR
  2775.   total += duree_i;
  2776.   }
  2777.  
  2778.  
  2779.   s1=tableWidget_3->item(L,6)->text();
  2780.   numero_mesure = s1.toInt();
  2781.   if ( (numero_mesure % 2) == 0)
  2782.   { complete_case(L, 6, s1, "#000000", "#C4F6FC", false, tableWidget_3); }// BLEU CLAIR
  2783.   else { complete_case(L, 6, s1, "#000000", "#3AE0F5", false, tableWidget_3); } //BLEU FONCE
  2784.  
  2785.  
  2786.   if (numero_mesure != memo_numero_mesure)
  2787.   {
  2788.   memo_numero_mesure = numero_mesure;
  2789.   complete_case(L, 6, s1, "#000000", "#F57900", true, tableWidget_3); // ORANGE
  2790.   complete_case(L-1, 7, s2, "#000000", "#C4F6FC", true, tableWidget_3); // BLEU CLAIR
  2791.   total = duree_i;
  2792.   }
  2793.   }
  2794. }
  2795. */
  2796.  
  2797. int MainWindow::calcul_T_note(int R)
  2798. {
  2799. // temps du début de la note en fonction du num de ligne (row) de la cellule cliquée dans le tableau3
  2800. int i, di, dT;
  2801. QString s1, duree_txt;
  2802.  
  2803. dT=0;
  2804. for(i=0 ; i<R ; i++)
  2805. {
  2806. duree_txt = tableWidget_3->item(i, 5)->text();
  2807. di = duree_txt.toInt();
  2808. dT += di;
  2809. }
  2810. return dT;
  2811. }
  2812.  
  2813.  
  2814. QString MainWindow::extraction_data(QString ligne_i, QString label)
  2815. {
  2816. int p1, p2, nb;
  2817. QString s1;
  2818.  
  2819. p1=ligne_i.indexOf(label);
  2820. if(p1 == -1) {return "";} // (pas trouvé)
  2821.  
  2822. p2=ligne_i.indexOf(";",p1);
  2823. nb = label.length();
  2824. s1 = ligne_i.mid(p1+nb, p2-(p1+nb));
  2825.  
  2826. return s1;
  2827. }
  2828.  
  2829.  
  2830. void MainWindow::calcul_tps()
  2831. {
  2832. int duree;
  2833. int total=0;
  2834. QString s1;
  2835.  
  2836. int nb_de_lignes=tableWidget_3->rowCount();
  2837. for (int L=0; L<nb_de_lignes-1; L++)
  2838. {
  2839. duree = tableWidget_3->item(L, 5)->text().toInt();
  2840.  
  2841. s1.setNum(total);
  2842.  
  2843. tableWidget_3->setItem(L, 8, new QTableWidgetItem (s1) );
  2844. total += duree;
  2845. //if (total == 32) {total=0;}
  2846. }
  2847. }
  2848.  
  2849.  
  2850.  
  2851. int MainWindow::write_Tableau_vertical() // décrypte la 'liste_accords[]'
  2852. {
  2853. QString s1, s2;
  2854. int dt;
  2855. int temps=0;
  2856. int total =0;
  2857.  
  2858. //liste_accords.clear();
  2859. int nb_de_lignes = open_fichier_lst(); // appel de la fonction qui peuple la variable (QString) 'liste_accords'
  2860. if (nb_de_lignes == 0) {return 1;}
  2861.  
  2862. init_TW_3();
  2863. tableWidget_3->setRowCount(0);
  2864.  
  2865. mode_depot_note = false;
  2866.  
  2867. // -------------------------------------------------------------------------------
  2868. // on va transcrire ce contenu du String "liste_accords" dans le tableWidget_3
  2869.  
  2870. QString ligne_i;
  2871. for (int L=0; L<nb_de_lignes; L++)
  2872. {
  2873. on_Bt_AddLine_clicked();
  2874.  
  2875. ligne_i=liste_accords[L];
  2876.  
  2877. dechiffre_note("m1=", L, 0);
  2878. dechiffre_note("m2=", L, 1);
  2879. dechiffre_note("m3=", L, 2);
  2880. //dechiffre_note("m4=", L, 3);
  2881.  
  2882. s1= extraction_data(ligne_i, "cmt=");
  2883.  
  2884. complete_case(L, 3, s1, "#000000", "#FFFCDD", false, tableWidget_3);
  2885.  
  2886. // la colonne 4 est un bouton
  2887.  
  2888. s1= extraction_data(ligne_i, "d="); // durée
  2889. tableWidget_3->setItem(L, 5, new QTableWidgetItem (s1) ); // dt
  2890. dt = s1.toInt();
  2891.  
  2892.  
  2893. s1= extraction_data(ligne_i, "M="); // mesure
  2894. if (s1 != " ")
  2895. {
  2896. complete_case(L, 6, s1, "#FFFFFF", "#888888", false, tableWidget_3); // 'M' (mesure)
  2897.  
  2898. s1.setNum(temps);
  2899. complete_case(L, 7, s1, "#000000", "#FFFCDD", false, tableWidget_3); // tps
  2900. temps =0;
  2901. }
  2902. else
  2903. {
  2904. s1.setNum(temps);
  2905. complete_case(L, 7, s1, "#000000", "#CECECE", false, tableWidget_3); // 'M' (mesure)
  2906. }
  2907. temps += dt;
  2908.  
  2909. tableWidget_3->setItem(L, 8, new QTableWidgetItem (" "));
  2910.  
  2911.  
  2912. s1= extraction_data(ligne_i, "a="); // ACC
  2913. tableWidget_3->setItem(L, 9, new QTableWidgetItem (s1));
  2914.  
  2915. s1= extraction_data(ligne_i, "cases=");
  2916. complete_case(L, 10, s1, "#000000", "#FFFFFF", false, tableWidget_3);
  2917.  
  2918. s2="";
  2919. bool ok = false;
  2920.  
  2921. s1= extraction_data(ligne_i, "D0v="); // corde à vide
  2922. if ((s1 != "") && (s1 != "-")) { s2 += "D0v=" + s1 + ";"; ok = true; }
  2923.  
  2924. s1= extraction_data(ligne_i, "D0h="); // corde à vide
  2925. if ((s1 != "") && (s1 != "-")) { s2 += "D0h=" + s1 + ";"; ok = true; }
  2926.  
  2927. s1= extraction_data(ligne_i, "D1v="); // posiion "verticale" (c.d corde) du doigt 1 (index)
  2928. if ((s1 != "") && (s1 != "-")) { s2 += "D1v=" + s1 + ";"; ok = true; }
  2929.  
  2930. s1= extraction_data(ligne_i, "D1h="); // posiion "horizontale" (case) du doigt 1 (index)
  2931. if ((s1 != "") && (s1 != "-")) { s2 += "D1h=" + s1 + ";"; ok = true; }
  2932.  
  2933. s1= extraction_data(ligne_i, "D2v=");
  2934. if ((s1 != "") && (s1 != "-")) { s2 += "D2v=" + s1 + ";"; ok = true; }
  2935.  
  2936. s1= extraction_data(ligne_i, "D2h=");
  2937. if ((s1 != "") && (s1 != "-")) { s2 += "D2h=" + s1 + ";"; ok = true; }
  2938.  
  2939. s1= extraction_data(ligne_i, "D3v=");
  2940. if ((s1 != "") && (s1 != "-")) { s2 += "D3v=" + s1 + ";"; ok = true; }
  2941.  
  2942. s1= extraction_data(ligne_i, "D3h=");
  2943. if ((s1 != "") && (s1 != "-")) { s2 += "D3h=" + s1 + ";"; ok = true; }
  2944.  
  2945. s1= extraction_data(ligne_i, "D4v=");
  2946. if ((s1 != "") && (s1 != "-")) { s2 += "D4v=" + s1 + ";"; ok = true; }
  2947.  
  2948. s1= extraction_data(ligne_i, "D4h=");
  2949. if ((s1 != "") && (s1 != "-")) { s2 += "D4h=" + s1 + ";"; ok = true; }
  2950.  
  2951. if (ok != true) {s2=" ";}
  2952. QTableWidgetItem *item1 = new QTableWidgetItem();
  2953. item1->setText(s2);
  2954. item1->setFlags(item1->flags() & ~Qt::ItemIsEditable); // passe en read only
  2955. tableWidget_3->setItem(L, 11, item1);
  2956. }
  2957. tableWidget_3->resizeColumnsToContents();
  2958. return 0;
  2959. }
  2960.  
  2961.  
  2962. void MainWindow::on_Bt_Load_lst_clicked()
  2963. {
  2964. set_zoom2();
  2965. int w = write_Tableau_vertical();
  2966. if (w==0)
  2967. {
  2968. //checkBox_not_erase->setChecked(true);
  2969. //gestion_mesures();
  2970. write_Time_line();
  2971. }
  2972. }
  2973.  
  2974.  
  2975. void MainWindow::on_Bt_Supp_line_clicked()
  2976. {
  2977. int R= tableWidget_3->currentRow();
  2978. tableWidget_3->removeRow(R);
  2979. }
  2980.  
  2981.  
  2982.  
  2983. void MainWindow::complete_ligne(int R)
  2984. {
  2985. tableWidget_3->setItem(R, 0, new QTableWidgetItem (" ") ); // note1
  2986. tableWidget_3->setItem(R, 1, new QTableWidgetItem (" ") ); // note2
  2987. tableWidget_3->setItem(R, 2, new QTableWidgetItem (" ") ); // note3
  2988.  
  2989. tableWidget_3->setItem(R, 3, new QTableWidgetItem (" ") ); // cmt
  2990.  
  2991. QTableWidgetItem *Item1 = new QTableWidgetItem();
  2992. Item1->setIcon(QIcon("../images/01.png" ));
  2993. tableWidget_3->setItem(R, 4, Item1 ); // bouton
  2994.  
  2995. tableWidget_3->setItem(R, 5, new QTableWidgetItem (" ") ); // dt
  2996. tableWidget_3->setItem(R, 6, new QTableWidgetItem (" ") ); // M
  2997. tableWidget_3->setItem(R, 7, new QTableWidgetItem (" ") ); // tps
  2998. tableWidget_3->setItem(R, 8, new QTableWidgetItem (" ") ); // tot
  2999. tableWidget_3->setItem(R, 9, new QTableWidgetItem (" ") ); // ACC (accord type)
  3000. tableWidget_3->setItem(R, 10, new QTableWidgetItem (" ") ); // intervalle de cases (sur le manche) à jouer
  3001. tableWidget_3->setItem(R, 11, new QTableWidgetItem (" ") ); // doigts
  3002. }
  3003.  
  3004.  
  3005.  
  3006. void MainWindow::on_Bt_AddLine_clicked() // à la fin
  3007. {
  3008. int R=tableWidget_3->rowCount();
  3009.  
  3010. tableWidget_3->setRowCount(R+1);
  3011. complete_ligne(R);
  3012. }
  3013.  
  3014.  
  3015. void MainWindow::on_Bt_AddLine_ici_clicked() // ici
  3016. {
  3017. int R= tableWidget_3->currentRow();
  3018. tableWidget_3->insertRow(R);
  3019. complete_ligne(R);
  3020. }
  3021.  
  3022.  
  3023.  
  3024.  
  3025. void MainWindow::on_pushButton_2_clicked()
  3026. {
  3027. on_Bt_save_clicked();
  3028. init_TW_3();
  3029. lineEdit_2->clear();
  3030. lineEdit_12->clear();
  3031. lineEdit_13->clear();
  3032. }
  3033.  
  3034.  
  3035. void MainWindow::joue_morceau_debut()
  3036. {
  3037. //if(nb_lignes ==0){return;}
  3038. if (lecture_pause == 1)
  3039. {
  3040. Bt_lecture_2->setText("joue > debut");
  3041. //Bt_lecture_2->setStyleSheet("QPushButton{background-color:#50FF1B;}");
  3042. lecture_pause =0;
  3043. QString s1;
  3044. s1.setNum(num_ligne_en_cours);// conversion num -> txt
  3045. Timer2->stop();
  3046. }
  3047. else
  3048. {
  3049. nb_notes_jouees_max = 10000;
  3050. // Bt_lecture_2->setText("[]");
  3051. //Bt_lecture_2->setStyleSheet("QPushButton{background-color:yellow;}");
  3052. lecture_pause = 1;
  3053. //num_note_stop=10000;
  3054. Tp1=0;
  3055. temps1=0;
  3056. Timer2->start(10);
  3057. }
  3058. }
  3059.  
  3060.  
  3061. void MainWindow::joue_morceau_ici(int R, int nb_notes)
  3062. {
  3063. //if(nb_lignes ==0){return;}
  3064.  
  3065.  
  3066. num_ligne_en_cours = R-1;
  3067. //num_colonne_a_encadrer = R;
  3068. nb_notes_jouees_max = nb_notes-1;
  3069. nb_notes_jouees = 0;
  3070.  
  3071. //tableWidget_3->selectRow(lineEdit_7->text().toInt());
  3072. //R = tableWidget_3->currentRow();
  3073. R = lineEdit_9->text().toInt();
  3074. int T1 = calcul_T_note(R-1);
  3075. // num_colonne_a_encadrer = 3; //T1;
  3076. Tp1=T1;
  3077. temps1=T1;
  3078.  
  3079.  
  3080. if (lecture_pause == 1)
  3081. {
  3082. //Bt_lecture_1->setText("joue > ici");
  3083. //Bt_lecture_1->setStyleSheet("QPushButton{background-color:#50FF1B;}");
  3084. lecture_pause =0;
  3085. // QString s1;
  3086. // s1.setNum(num_ligne_en_cours);// conversion num -> txt
  3087. Timer2->stop();
  3088. //Edit_1->setText(s1);
  3089. }
  3090. else
  3091. {
  3092. //Bt_lecture_1->setText("[]");
  3093. //Bt_lecture_1->setStyleSheet("QPushButton{background-color:yellow;}");
  3094. lecture_pause = 1;
  3095. //num_note_stop=10000;
  3096. Timer2->start(300);
  3097. }
  3098. }
  3099.  
  3100.  
  3101. void MainWindow::on_Bt_lecture_1_clicked() // joue ici
  3102. {
  3103. int R=lineEdit_9->text().toInt();
  3104. nb_notes_jouees_max = spinBox_nb_notes->value();
  3105. joue_morceau_ici(R, nb_notes_jouees_max);
  3106. }
  3107.  
  3108.  
  3109.  
  3110. void MainWindow::on_Bt_lecture_2_clicked() // joue depuis le début
  3111. {
  3112. num_ligne_en_cours =0;
  3113. // num_note_max = liste_NOTES_importees.length()-1;
  3114.  
  3115. num_note_max = tableWidget_3->rowCount();
  3116. if (num_note_max < 1) {return;}
  3117. joue_morceau_debut();
  3118. }
  3119.  
  3120.  
  3121. void MainWindow::on_Bt_lecture_3_clicked() // joue 1 note
  3122. {
  3123. int n0 = num_ligne_en_cours;
  3124. //QString s1;
  3125. //s1.setNum(n0);
  3126. //lineEdit_9->setText(s1);
  3127. //int R=lineEdit_9->text().toInt();
  3128. joue_morceau_ici(n0, 1);
  3129. num_ligne_en_cours ++;
  3130. }
  3131.  
  3132.  
  3133. void MainWindow::on_Bt_STOP_clicked()
  3134. {
  3135. Bt_lecture_2->setText("joue > debut");
  3136. lecture_pause =0;
  3137. QString s1;
  3138. s1.setNum(num_ligne_en_cours);
  3139. Timer2->stop();
  3140. }
  3141.  
  3142.  
  3143.  
  3144. void MainWindow::create_100_lignes_V()
  3145. {
  3146. for (int n=0; n<100; n++)
  3147. {
  3148. lst_frames.append(new QFrame(this));
  3149. lst_frames[n]->setGeometry(0, 0, 1, 1);
  3150. //lst_frames[n]->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 0, 0);"));
  3151. lst_frames[n]->setStyleSheet("background-color: blue");
  3152. lst_frames[n]->hide();
  3153. }
  3154. }
  3155.  
  3156.  
  3157. void MainWindow::trace_ligne_V(int num_colonne, int num_mesure)
  3158. {
  3159. //sur le tableau horizontal (TimeLine)
  3160.  
  3161. if (num_mesure >=100) {return;} // nb max de lignes instanciées, voir fonction ci-dessus
  3162.  
  3163. int x;
  3164. int dy=140;
  3165. int LC=10; // largeur colonnes
  3166. int H_diff;
  3167. int x0=tableWidget_T->x();
  3168. int y0=tableWidget_T->y();
  3169.  
  3170. if (zoom==1) {LC=10;}
  3171. if (zoom==2) {LC=20;}
  3172.  
  3173. QScrollBar *H_Scroll = tableWidget_T->horizontalScrollBar();
  3174.  
  3175. H_diff = num_colonne - H_Scroll->value();
  3176. x = x0 + LC * H_diff;
  3177.  
  3178. if (H_diff>=0)
  3179. {
  3180. lst_frames[num_mesure+8]->setGeometry(QRect(x, y0, 2, dy));
  3181. lst_frames[num_mesure+8]->setStyleSheet("background-color: gray");
  3182. lst_frames[num_mesure+8]->show();
  3183. }
  3184. }
  3185.  
  3186.  
  3187.  
  3188. void MainWindow::trace_rectangle1(int x, int y, int dx, int dy)
  3189. {
  3190. lst_frames[1]->setGeometry(QRect(x, y, dx, 2)); lst_frames[1]->show();
  3191. lst_frames[2]->setGeometry(QRect(x, y+dy, dx, 2)); lst_frames[2]->show();
  3192.  
  3193. lst_frames[3]->setGeometry(QRect(x, y, 2, dy)); lst_frames[3]->show();
  3194. lst_frames[4]->setGeometry(QRect(x+dx, y, 2, dy)); lst_frames[4]->show();
  3195. }
  3196.  
  3197.  
  3198.  
  3199. void MainWindow::trace_rectangle2(int x, int y, int dx, int dy)
  3200. {
  3201. // l'objet QRect doit s'utiliser sur un QPainter
  3202. // d'où cette fonction qui trace directement sur le mainwindow
  3203. // sans masquage du fond (ne confisque pas les clics souris sur les widgets en particulier !!!)
  3204. lst_frames[5]->setGeometry(QRect(x, y, dx, 2)); lst_frames[5]->show();
  3205. lst_frames[6]->setGeometry(QRect(x, y+dy, dx, 2)); lst_frames[6]->show();
  3206.  
  3207. lst_frames[7]->setGeometry(QRect(x, y, 2, dy)); lst_frames[7]->show();
  3208. lst_frames[8]->setGeometry(QRect(x+dx, y, 2, dy)); lst_frames[8]->show();
  3209. }
  3210.  
  3211.  
  3212.  
  3213.  
  3214. void MainWindow::encadrement_colonne() // de la timeline en bas (tableWidget_T)
  3215. {
  3216. // rappel : label_timeline->setGeometry(10, 830, 100, 30);
  3217.  
  3218. int x0=tableWidget_T->x();
  3219. int y0=tableWidget_T->y();
  3220. int x;
  3221. int dx;
  3222. int dy=120; //tableWidget_T->height();
  3223. int LC=10; // largeur colonnes, doit coincider avec la valeur inscrite dans l'ui
  3224. int HSB;
  3225. int H_diff;
  3226.  
  3227. //num_colonne_a_encadrer=5;
  3228. //nb_colonnes_a_encadrer=3;
  3229.  
  3230. if (zoom==1) {LC=10;}
  3231. if (zoom==2) {LC=20;}
  3232. // nb_colonnes_a_encadrer -> variable globale
  3233.  
  3234. QScrollBar *H_Scroll = tableWidget_T->horizontalScrollBar();
  3235.  
  3236. HSB = H_Scroll->value();
  3237. H_diff = num_colonne_a_encadrer - HSB;
  3238.  
  3239. x = x0 + LC * H_diff;
  3240. dx = LC * nb_colonnes_a_encadrer;
  3241.  
  3242. if (H_diff>=0)
  3243. {
  3244. trace_rectangle2(x, y0, dx, dy);
  3245. }
  3246. else
  3247. {
  3248. ;
  3249. }
  3250. }
  3251.  
  3252.  
  3253.  
  3254. void MainWindow::encadrement_ligne() // du tableWidget_3
  3255. {
  3256. int x0=tableWidget_3->x();
  3257. int y0=tableWidget_3->y() + 22;
  3258. int y_max = y0 + tableWidget_3->height();
  3259.  
  3260. int x, y;
  3261. int largeur = tableWidget_3->width()-18;
  3262. int HL = tableWidget_3->verticalHeader()->defaultSectionSize();
  3263. int V_SB;
  3264. int V_diff;
  3265.  
  3266. // encadrement de la ligne sélectionnée
  3267. int num_ligne = tableWidget_3->currentRow();
  3268. QScrollBar *V_Scroll = tableWidget_3->verticalScrollBar();
  3269.  
  3270. V_SB = V_Scroll->value();
  3271. V_diff = num_ligne - V_SB;
  3272.  
  3273. x = x0;
  3274. y = y0 + HL * V_diff;
  3275.  
  3276. if ((V_diff>=0) && (y < y_max - HL))
  3277. {
  3278. trace_rectangle1(x, y, largeur, HL);
  3279. }
  3280. else { trace_rectangle1(x,y, 1, 1); }
  3281. }
  3282.  
  3283.  
  3284. void MainWindow::TW_T_scroll(int H)
  3285. {
  3286.  
  3287. write_Time_line();
  3288. encadrement_colonne();
  3289.  
  3290. }
  3291.  
  3292. void MainWindow::TW_3_scroll(int H)
  3293. {
  3294.  
  3295. //write_Time_line();
  3296. encadrement_ligne();
  3297.  
  3298. }
  3299.  
  3300.  
  3301.  
  3302. void MainWindow::on_Bt_refresh_clicked()
  3303. {
  3304. init_TW_T();
  3305. create_100_lignes_V();
  3306. }
  3307.  
  3308.  
  3309. void MainWindow::set_zoom1()
  3310. {
  3311. zoom=1;
  3312.  
  3313. QFont fnt;
  3314. fnt.setFamily("Ubuntu");
  3315. fnt.setPointSize(6);
  3316. tableWidget_T->setFont(fnt);
  3317.  
  3318. for(int n=0; n<100; n++)
  3319. {
  3320. tableWidget_T->setColumnWidth(n, 10);
  3321. }
  3322. }
  3323.  
  3324.  
  3325. void MainWindow::set_zoom2()
  3326. {
  3327. zoom=2;
  3328.  
  3329. QFont fnt;
  3330. int n_max = tableWidget_T->columnCount();
  3331.  
  3332. fnt.setFamily("Ubuntu");
  3333. fnt.setPointSize(8);
  3334. tableWidget_T->setFont(fnt);
  3335.  
  3336. for(int n=0; n<n_max; n++)
  3337. {
  3338. tableWidget_T->setColumnWidth(n, 20);
  3339. }
  3340.  
  3341. }
  3342.  
  3343. void MainWindow::on_radioButton_Z1_clicked()
  3344. {
  3345. set_zoom1();
  3346. }
  3347.  
  3348.  
  3349. void MainWindow::on_radioButton_Z2_clicked()
  3350. {
  3351. set_zoom2();
  3352. }
  3353.  
  3354.  
  3355.  
  3356.  
  3357. void MainWindow::on_Bt_open_dossier_clicked()
  3358. {
  3359. QString s1, path1;
  3360. int p1;
  3361. /*
  3362.   s1 = lineEdit_1->text();
  3363.   p1 = s1.lastIndexOf("/");
  3364.   s1.remove(p1, 255);
  3365.   path1 = s1;
  3366. */
  3367. path1 = string_currentDir;
  3368.  
  3369. QProcess process1;
  3370. process1.setProgram("caja");
  3371. process1.setArguments({path1});
  3372. process1.startDetached();
  3373. }
  3374.  
  3375.  
  3376.  
  3377.  
  3378.  
  3379. void MainWindow::on_spinBox_4_valueChanged(int arg1)
  3380. {
  3381. QString s3, s4;
  3382. case_min = arg1;
  3383.  
  3384. if (arg1 > case_max) {spinBox_5->setValue(arg1);}
  3385. s3.setNum(case_min);
  3386.  
  3387. case_max = spinBox_5->value();
  3388. s4.setNum(case_max);
  3389. lineEdit_14->setText(s3 + "a" +s4);
  3390.  
  3391. encadre_accord(case_min, case_max);
  3392.  
  3393. //complete_accord(case_min, case_max); // NON !! pas ici !!!!
  3394.  
  3395. }
  3396.  
  3397.  
  3398. void MainWindow::on_spinBox_5_valueChanged(int arg1)
  3399. {
  3400. QString s3, s4;
  3401.  
  3402. case_min = spinBox_4->value();
  3403.  
  3404. if (arg1 < case_min) {spinBox_5->setValue(case_min);}
  3405.  
  3406. s3.setNum(case_min);
  3407.  
  3408. case_max = arg1;
  3409. s4.setNum(case_max);
  3410.  
  3411. lineEdit_14->setText(s3 + "a" +s4);
  3412.  
  3413. encadre_accord(case_min, case_max);
  3414.  
  3415. //complete_accord(case_min, case_max); // NON !! pas ici !!!!
  3416. }
  3417.  
  3418.  
  3419. void MainWindow::on_pushButton_4_clicked()
  3420. {
  3421. QString s1;
  3422.  
  3423. int R = tableWidget_3->currentRow();
  3424.  
  3425.  
  3426. s1=lineEdit_10->text();
  3427. if (s1 != "")
  3428. {
  3429. tableWidget_3->setItem(R, 9, new QTableWidgetItem (s1) );
  3430.  
  3431. s1=lineEdit_14->text();
  3432. tableWidget_3->setItem(R, 10, new QTableWidgetItem (s1) );
  3433. }
  3434. else
  3435. {
  3436. QMessageBox msgBox;
  3437. msgBox.setText("Choisir le type (Maj, Min, 7e de dom... au préalable)");
  3438. msgBox.exec();
  3439. }
  3440. }
  3441.  
  3442.  
  3443. /* RAPPEL :
  3444. struct NOTE_importee
  3445. {
  3446.   uint16_t numero; // 2 octets
  3447.   uint8_t midi; // 1 octet
  3448.   uint16_t n_barre; // 2 octets ; numéro de la barre temporelle sur laquelle est posée la note
  3449.   uint8_t n_temps; // 1 octet ; 1..16 numéro du temps (temps fort, temps faible) au sein de la mesure
  3450.   uint8_t duree; // 1 octet ; en nb d'intervalles de barres
  3451. // total 7 octets
  3452. };
  3453.  
  3454. */
  3455.  
  3456. void MainWindow::analyse_notes_importees() // (depuis le prog FFT) et garnit le TW3
  3457. {
  3458. NOTE_importee note_i1, note_i2;
  3459. // int midi_i;
  3460. //int b1, b2;
  3461. int n_barre_1;
  3462. int n_barre_2;
  3463. int temps=0;
  3464. int total=0;
  3465. float dt_b;
  3466. // int nb_notes;
  3467. QString s1;
  3468.  
  3469. uint8_t midi_note1;
  3470. uint8_t midi_note2;
  3471. // int R=0;
  3472.  
  3473. // int numero_note;
  3474. uint32_t t=0;
  3475. //int duree_note;
  3476.  
  3477. int num_case=0;
  3478. int num_ligne=0;
  3479. int num_mesure=0;
  3480. QString nom_note;
  3481.  
  3482. int n_max = liste_NOTES_importees.length();
  3483.  
  3484.  
  3485. //on_Bt_AddLine_clicked();
  3486. // num_ligne++;
  3487.  
  3488. for(int n=0; n<n_max; n++)
  3489. {
  3490. // QMessageBox msgBox; QString s1; s1 = "..."; msgBox.setText(s1); msgBox.exec();
  3491.  
  3492. note_i1 = liste_NOTES_importees[n];
  3493. note_i2 = liste_NOTES_importees[n+1];
  3494.  
  3495. n_barre_1 = note_i1.n_barre;
  3496. n_barre_2 = note_i2.n_barre;
  3497.  
  3498. dt_b = n_barre_2 - n_barre_1;
  3499. if (dt_b <0) {dt_b = 8;}
  3500.  
  3501. midi_note1 = liste_NOTES_importees[n].midi;
  3502. midi_note2 = liste_NOTES_importees[n+1].midi;
  3503.  
  3504. nom_note.setNum(midi_note1);
  3505. int h1 = calcul_hauteur_note(midi_note1);
  3506. h1-=3;
  3507. if(h1<0){h1+=12;}
  3508. if(h1>11){h1-=12;}
  3509. QColor couleur1 = liste_couleurs[h1];
  3510.  
  3511. if (h1>=0)
  3512. {
  3513. nom_note += " ";
  3514. nom_note += gamme_chromatique[h1];
  3515. }
  3516.  
  3517. if (dt_b == 0)
  3518. {
  3519. complete_case(num_ligne, num_case, nom_note, "#000000", couleur1, false, tableWidget_3);
  3520. num_case++;
  3521. if (num_case >3) {num_case = 3;}
  3522. }
  3523.  
  3524. if (dt_b != 0)
  3525. {
  3526. complete_case(num_ligne, num_case, nom_note, "#000000", couleur1, false, tableWidget_3);
  3527. s1.setNum(dt_b);
  3528. tableWidget_3->setItem(num_ligne, 5, new QTableWidgetItem(s1)); // dur (durée)
  3529.  
  3530. temps = note_i1.n_temps;
  3531. s1.setNum(temps);
  3532. tableWidget_3->setItem(num_ligne-1, 7, new QTableWidgetItem(s1)); // tps
  3533. on_Bt_AddLine_clicked();
  3534. num_ligne++;
  3535. num_case=0;
  3536. }
  3537.  
  3538. s1.setNum(temps);
  3539. tableWidget_3->setItem(num_ligne-1, 7, new QTableWidgetItem(s1)); // tps
  3540.  
  3541.  
  3542. if ((temps == 32) && (dt_b !=0))
  3543. {
  3544. num_mesure++;
  3545. s1.setNum(num_mesure);
  3546. complete_case(num_ligne-1, 6, s1, "#000000", "#FFFCDD", false, tableWidget_3); // M
  3547. }
  3548. }
  3549.  
  3550. tableWidget_3->resizeColumnsToContents();
  3551.  
  3552. s1.setNum(0);
  3553. lineEdit_12->setText(s1);
  3554.  
  3555. s1.setNum(num_ligne);
  3556. lineEdit_13->setText(s1);
  3557. }
  3558.  
  3559.  
  3560. void MainWindow::supprime_note(int n)
  3561. {
  3562. //int z1= liste_NOTES.length();
  3563.  
  3564. liste_NOTES_importees.remove(n);
  3565. //effacer_calque(scene4,calque_notes);
  3566. //tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  3567. // numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  3568. //affiche_liste_notes();
  3569. //trace_liste_notes();
  3570.  
  3571. //int z2= liste_NOTES_importees.length();
  3572. }
  3573.  
  3574.  
  3575.  
  3576. void MainWindow::suppression_notes_invalides()
  3577. {
  3578. int midi;
  3579. int n_max = liste_NOTES_importees.length();
  3580. int nb = 0;
  3581.  
  3582. bool boucler=true;
  3583. do
  3584. {
  3585. nb=0;
  3586. for(int n=0; n<n_max; n++)
  3587. {
  3588. midi = liste_NOTES_importees[n].midi;
  3589. if ((midi <40) || (midi>82)) // midi=100 code pour les barres de mesures
  3590. {
  3591. supprime_note(n);
  3592. n_max --;
  3593. nb++;
  3594. }
  3595. }
  3596. if (nb==0) {boucler=false;}
  3597. }
  3598. while (boucler == true);
  3599. }
  3600.  
  3601.  
  3602. void MainWindow::import_fichier_NOTES() // généré par le programme FFT
  3603. {
  3604. QString filename1;
  3605. QString s1;
  3606.  
  3607. //int p1= string_currentFile.lastIndexOf('/');
  3608. //string_currentDir = string_currentFile.left(p1);
  3609.  
  3610. filename1 = QFileDialog::getOpenFileName(this,
  3611. tr("Ouvrir Fichier nts"), string_currentDir+"/", tr("Fichiers nts (*.nts)"));
  3612.  
  3613. file_dat.setFileName(filename1);
  3614. if (!file_dat.open(QIODevice::ReadOnly))
  3615. {
  3616. data_ok = false;
  3617. return ;
  3618. }
  3619. else
  3620. {
  3621. binStream1.setDevice(&file_dat); // accès à la totalité du fichier dat
  3622. binStream1.setVersion(QDataStream::Qt_6_8);
  3623. data_ok = true;
  3624. }
  3625.  
  3626. // int z = sizeof(NOTE); // ATTENTION ! ne PAS utiliser cette valeur qui tient en compte l'alignement en RAM
  3627. long n_max = file_dat.bytesAvailable() / 7; // 7 bits par enr; voir la def de 'NOTE' dans le .h
  3628.  
  3629. double x;
  3630. double dx;
  3631. double vts;
  3632.  
  3633. // lecture entête -----------------
  3634. binStream1 >> x >> dx >> vts; // 8+8+8=24 octets au début du fichiers
  3635.  
  3636. // qDebug() << "vts" << vts;
  3637.  
  3638. uint8_t xx;
  3639. for (int i=0; i<(64-24); i++) {binStream1 >> xx;} // lit en tout à 64 octets
  3640. //---------------------------------
  3641.  
  3642. doubleSpinBox_vitesse->setValue(vts);
  3643. s1.setNum(x);
  3644. lineEdit_x->setText(s1);
  3645. s1.setNum(dx);
  3646. lineEdit_dx->setText(s1);
  3647.  
  3648. NOTE_importee note_i;
  3649. for(int n=0; n<n_max; n++)
  3650. {
  3651. binStream1 >> note_i.numero >> note_i.midi >> note_i.n_barre >> note_i.n_temps >> note_i.duree;
  3652. note_i.midi += spinBox_transposition->value();
  3653. liste_NOTES_importees << note_i;
  3654. }
  3655. file_dat.close();
  3656. }
  3657.  
  3658.  
  3659.  
  3660.  
  3661. void MainWindow::on_Bt_copie_doigts_to_TW3_clicked()
  3662. {
  3663. // le 'tableWidget_doigts' c'est le tableau de saisie dans le cadre 'Position des doigts'
  3664.  
  3665. QString s1, s_out;;
  3666. s1 = tableWidget_doigts->item(0,0) ->text();
  3667. if (s1 != "-") {s_out += "D0v=" + s1 + ";";}
  3668. s1 = tableWidget_doigts->item(0,1) ->text();
  3669. if (s1 != "-") {s_out += "D0h=" + s1 + ";";}
  3670.  
  3671. s1 = tableWidget_doigts->item(1,0) ->text();
  3672. if (s1 != "-") {s_out += "D1v=" + s1 + ";";}
  3673. s1 = tableWidget_doigts->item(1,1) ->text();
  3674. if (s1 != "-") {s_out += "D1h=" + s1 + ";";}
  3675.  
  3676. s1 = tableWidget_doigts->item(2,0) ->text();
  3677. if (s1 != "-") {s_out += "D2v=" + s1 + ";";}
  3678. s1 = tableWidget_doigts->item(2,1) ->text();
  3679. if (s1 != "-") {s_out += "D2h=" + s1 + ";";}
  3680.  
  3681. s1 = tableWidget_doigts->item(3,0) ->text();
  3682. if (s1 != "-") {s_out += "D3v=" + s1 + ";";}
  3683. s1 = tableWidget_doigts->item(3,1) ->text();
  3684. if (s1 != "-") {s_out += "D3h=" + s1 + ";";}
  3685.  
  3686. s1 = tableWidget_doigts->item(4,0) ->text();
  3687. if (s1 != "-") {s_out += "D4v=" + s1 + ";";}
  3688. s1 = tableWidget_doigts->item(4,1) ->text();
  3689. if (s1 != "-") {s_out += "D4h=" + s1 + ";";}
  3690.  
  3691. QTableWidgetItem *item1 = new QTableWidgetItem();
  3692. item1->setText(s_out);
  3693. item1->setFlags(item1->flags() & ~Qt::ItemIsEditable);
  3694. tableWidget_3->setItem(ligne_TW3, 11, item1); // recopie le résultat dans le grand tableau TW3 de droite
  3695.  
  3696. affi_positions_doigts_dans_status(s_out);
  3697. }
  3698.  
  3699.  
  3700. void MainWindow::on_pushButton_6_clicked()
  3701. {
  3702. QMessageBox msgBox;
  3703. QString s1;
  3704.  
  3705. s1 = "POSITION DES DOIGTS main gauche (sur le manche)";
  3706. s1 += "\n";
  3707. s1 += "\n";
  3708. s1 += "La première ligne (0) désigne la corde à vide";
  3709. s1 += "\n";
  3710.  
  3711. s1 += "Chacune des 4 lignes suivantes (1 à 4) représente un doigt :";
  3712. s1 += "\n";
  3713. s1 += "le numéro de la ligne désigne le doigt :";
  3714. s1 += "\n";
  3715. s1 += "doigt 1 = index, 2 = majeur...";
  3716. s1 += "\n";
  3717. s1 += "Pour écrire dans le tableau cliquer au préalable sur une note (sur le manche)";
  3718. s1 += "\n";
  3719. s1 += "... puis ici sur une ligne (sur une des 4 petites flèches vertes)";
  3720. s1 += "\n";
  3721. s1 += "( corde 1 = mi aigü...)";
  3722. s1 += "\n";
  3723. s1 += "\n";
  3724. s1 += "Le tableau s'actualise également lorsqu'une note est jouée depuis la liste TW3";
  3725. s1 += "\n";
  3726. s1 += "\n";
  3727. s1 += "Dès lors, sur le manche, les numéros des doigts s'afficheront au centre des notes "
  3728. "pressées dans les cases (et pas forcément jouées, on peut très bien plaquer tout un "
  3729. "accord et ne jouer qu'une note à la fois, en arpège )";
  3730.  
  3731. msgBox.setText(s1);
  3732. msgBox.exec();
  3733.  
  3734.  
  3735. }
  3736.  
  3737.  
  3738. void MainWindow::on_tableWidget_doigts_cellClicked(int row, int column)
  3739. {
  3740. QString s1, s2;
  3741.  
  3742. if(case_jouee == 0)
  3743. {
  3744. s1.setNum(corde_jouee);
  3745. tableWidget_doigts->item(0, 0)->setText(s1);
  3746. return ;
  3747. }
  3748.  
  3749. if (column==2)
  3750. {
  3751. s1.setNum(corde_jouee);
  3752. tableWidget_doigts->item(row, 0)->setText(s1);
  3753. s2.setNum(case_jouee);
  3754. tableWidget_doigts->item(row, 1)->setText(s2);
  3755.  
  3756. }
  3757. }
  3758.  
  3759.  
  3760. void MainWindow::on_Bt_RAZ_doigts_clicked()
  3761. {
  3762. //tableWidget_doigts->clear();
  3763. init_tableWidget_doigts();
  3764. }
  3765.  
  3766.  
  3767. void MainWindow::on_pushButton_7_clicked()
  3768. {
  3769. QMessageBox msgBox;
  3770. QString s1;
  3771. s1 = "AIDE GENERALE";
  3772. s1 += "\n";
  3773. s1 += "\n";
  3774. s1 += "1- Ouvrir un 'fichier accords' préalablement sauvegardé avec ce logiciel 'Guitare'";
  3775. s1 += "\n";
  3776. s1 += "Variante : Importer la liste des notes créée avec le logiciel 'FFT'";
  3777. s1 += "\n";
  3778. s1 += "2- vérifier la durée (calculée) des mesures et modifier la durée des notes si nécessaire";
  3779. s1 += "\n";
  3780. s1 += "3- Pour chaque ligne, configurer un accord type ou une 'note seule'";
  3781. s1 += "(utiliser pour cela le 'Configurateur d'accords')";
  3782. s1 += " puis envoyer la configuration obtenue vers le tableau TW3, avec le bouton 'to TW3 -->' du 'configurateur d'Accords'";
  3783. s1 += "\n";
  3784. s1 += "4- Reste à choisir les doigts pour chaque note. Voir l'aide du cadre 'Position des doigts'";
  3785. s1 += "\n";
  3786. s1 += "\n";
  3787. s1 += "VARIANTE :";
  3788. s1 += "\n";
  3789. s1 += "\n";
  3790. s1 += "On peut aussi partir de zéro et entrer les notes une à une manuellement dans TW3 (TableWidget 3)";
  3791. s1 += "\n";
  3792. s1 += "Il est fortement conseillé de cliquer les notes sur le manche au préalable (voir l'aide du manche) ";
  3793. s1 += "plutôt que de saisir les libellés au clavier, afin d'éviter les saisies incorrectes";
  3794. msgBox.setText(s1);
  3795. msgBox.exec();
  3796. }
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802. void MainWindow::contextMenuEvent(QContextMenuEvent *event) // menu contextuel (c.a.d déclenché par le clic de droite)
  3803. {
  3804. // statusbar->showMessage("clic de droite");
  3805. int x_min, x_max;
  3806. int y_min, y_max;
  3807.  
  3808. x_min = graphicsView1->x();
  3809. x_max = x_min + graphicsView1->width();
  3810.  
  3811. y_min = graphicsView1->y();
  3812. y_max = y_min + graphicsView1->height();
  3813.  
  3814. if (x_clic_ecran > x_min && x_clic_ecran < x_max && y_clic_ecran > y_min && y_clic_ecran < y_max)
  3815. {
  3816. QString s1, s2;
  3817. s1.setNum(n_midi_jouee);
  3818.  
  3819. s2 = "mode: DEPOT NOTE ("+ s1 + ") -> ";
  3820. s2 += lineEdit_note->text();
  3821. s2 += " cliquez maintenant dans une case de TW3 pour placer la note";
  3822.  
  3823. mode_depot_note = true;
  3824. statusbar->showMessage(s2);
  3825. MainWindow::setCursor(Qt::CrossCursor);
  3826. }
  3827. }
  3828.  
  3829.  
  3830. void MainWindow::on_pushButton_8_clicked()
  3831. {
  3832. QMessageBox msgBox;
  3833. QString s1;
  3834. s1 = "COPIE d'une note vers le tableau TW3 -->";
  3835. s1 += "\n";
  3836. s1 += "\n";
  3837. s1 += "1- clic-droit sur une note (sur le manche)";
  3838. s1 += "\n";
  3839. s1 += "Le curseur de la souris devient une croix";
  3840. s1 += "\n";
  3841. s1 += "2- cliquer_gauche alors dans une case de TW3 (colonnes 1 à 3)";
  3842. s1 += "\n";
  3843. s1 += "La note est alors collée dans le tableau";
  3844. s1 += "\n";
  3845. s1 += "\n";
  3846. s1 += "Si clic en dehors du tableau, l'opéraion est annulée";
  3847. s1 += "\n";
  3848.  
  3849. msgBox.setText(s1);
  3850. msgBox.exec();
  3851. }
  3852.  
  3853. void MainWindow::on_pushButton_9_clicked()
  3854. {
  3855. QMessageBox msgBox;
  3856. QString s1;
  3857. s1 = "Les numéros qui s'affichent au centre des notes jouées sont ceux des doigts de la main gauche";
  3858. s1 += "\n";
  3859. s1 += "1=index, 2=majeur, 3=annulaire, 4=auriculaire";
  3860.  
  3861.  
  3862. msgBox.setText(s1);
  3863. msgBox.exec();
  3864. }
  3865.  
  3866.  
  3867.  
  3868.  
  3869. void MainWindow::on_pushButton_10_clicked()
  3870. {
  3871. QMessageBox msgBox;
  3872. QString s1;
  3873. s1 = "Les fichiers sont enregistrés au format texte";
  3874. s1 += "\n";
  3875. s1 += "Il peuvent être facilement concaténés avec un éditeur de texte";
  3876. s1 += "\n";
  3877. s1 += "pour obtenir un morceau complet à partir de petites séquences.";
  3878.  
  3879. msgBox.setText(s1);
  3880. msgBox.exec();
  3881. }
  3882.  
  3883.  
  3884. void MainWindow::on_Bt_import_notes_clicked()
  3885. {
  3886. init_TW_3();
  3887. liste_NOTES_importees.clear();
  3888. import_fichier_NOTES();
  3889. suppression_notes_invalides();
  3890. affiche_liste_notes();
  3891. analyse_notes_importees(); // et garnit le TW3
  3892. }
  3893.  
  3894.  
  3895. void MainWindow::complete_accord(int c_min, int c_max)
  3896. {
  3897. spinBox_4->setValue(c_min);
  3898. case_min = c_min;
  3899.  
  3900. spinBox_5->setValue(c_max);
  3901. case_max = c_max;
  3902.  
  3903. if (type_accords == 1) {on_Bt_ACCORD_1_clicked();}
  3904. if (type_accords == 2) {on_Bt_ACCORD_2_clicked();}
  3905. if (type_accords == 3) {on_Bt_ACCORD_3_clicked();}
  3906. }
  3907.  
  3908.  
  3909.  
  3910. void MainWindow::on_pushButton_3_clicked()
  3911. {
  3912. complete_accord(0, 20);
  3913. }
  3914.  
  3915.  
  3916.  
  3917. void MainWindow::on_pushButton_3a_clicked()
  3918. {
  3919. complete_accord(9, 12);
  3920. }
  3921.  
  3922.  
  3923. void MainWindow::on_pushButton_3b_clicked()
  3924. {
  3925. complete_accord(7, 10);
  3926. }
  3927.  
  3928.  
  3929. void MainWindow::on_pushButton_3c_clicked()
  3930. {
  3931. complete_accord(5, 8);
  3932. }
  3933.  
  3934.  
  3935. void MainWindow::on_pushButton_3d_clicked()
  3936. {
  3937. complete_accord(3, 6);
  3938. }
  3939.  
  3940.  
  3941. void MainWindow::on_pushButton_3e_clicked()
  3942. {
  3943. complete_accord(0, 3);
  3944. }
  3945.  
  3946.  
  3947. void MainWindow::on_pushButton_11_clicked()
  3948. {
  3949. QMessageBox msgBox;
  3950. QString s1;
  3951. s1 = "Cliquer sur bouton vert 'Import notes' pour remplir le tableau";
  3952. s1 += "\n";
  3953. s1 += "\n";
  3954. s1 += "n° barre (de fraction 1/16 de mesure) est comptée depuis le début.";
  3955. s1 += "\n";
  3956. s1 += "'temps'= numéro de barre au sein de chaque mesure.";
  3957. s1 += "\n";
  3958. s1 += "'durée' est exprimée en nb de barres.";
  3959. s1 += "\n";
  3960.  
  3961. msgBox.setText(s1);
  3962. msgBox.exec();
  3963. }
  3964.  
  3965.  
  3966. void MainWindow::on_tableWidget_3_cellChanged(int row, int column)
  3967. {
  3968. if (column==5) {calcul_tps();}
  3969. }
  3970.  
  3971.  
  3972. void MainWindow::choix_dossier_de_travail()
  3973. {
  3974.  
  3975. QString currentDir_actuel = string_currentDir;
  3976. string_currentDir = QFileDialog::getExistingDirectory
  3977. (this, tr("Open Directory"), currentDir_actuel, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  3978.  
  3979. if (string_currentDir != "")
  3980. {
  3981. string_currentDir += "/";
  3982. dossier_de_travail_ok = true;
  3983. save_fichier_ini();
  3984. lineEdit_current_dir->setText(string_currentDir);
  3985. }
  3986. else
  3987. {
  3988. string_currentDir = currentDir_actuel;
  3989. dossier_de_travail_ok = false;
  3990. } // -> si on clique sur le bouton 'cancel'
  3991. }
  3992.  
  3993.  
  3994.  
  3995. void MainWindow::on_Bt_choix_current_dir_clicked()
  3996. {
  3997. choix_dossier_de_travail();
  3998. }
  3999.  
  4000.  
  4001.  
  4002.  
  4003. void MainWindow::on_Bt_save_ACD_clicked()
  4004. {
  4005. QString chemin_out;
  4006. chemin_out = string_currentDir;
  4007. QFile file1(chemin_out + "ACD" + ".txt");
  4008. QString sA, sC, sD;
  4009. int n_max = tableWidget_3->rowCount();
  4010.  
  4011. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  4012. {
  4013. QTextStream file_out(&file1);
  4014.  
  4015. for (int n=0; n<n_max; n++)
  4016. {
  4017. sA = tableWidget_3->item(n, 9)->text(); // accords
  4018. sC = tableWidget_3->item(n, 10)->text(); // cases
  4019. sD = tableWidget_3->item(n, 11)->text(); // doigts
  4020.  
  4021. file_out << "A=" + sA + ";" + "C=" + sC + ";" + "D=" + sD + ";";
  4022. file_out << char(10);
  4023. }
  4024.  
  4025. }
  4026. file1.close();
  4027.  
  4028. QMessageBox msgBox;
  4029. QString s1="Fichier enregistré: " + chemin_out + "ACD" + ".txt";
  4030. msgBox.setText(s1);
  4031. msgBox.exec();
  4032. }
  4033.  
  4034.  
  4035. int MainWindow::on_Bt_load_ACD_clicked()
  4036. {
  4037. QString chemin_in;
  4038. chemin_in = string_currentDir;
  4039. QFile file1(chemin_in + "ACD" + ".txt");
  4040. QString sA, sC, sD;
  4041. QString ligne_i;
  4042. int num_ligne=0;
  4043.  
  4044. if (!file1.open(QIODevice::ReadOnly | QIODevice::Text)) return 1;
  4045. QTextStream TextStream1(&file1);
  4046.  
  4047. while ( !TextStream1.atEnd() )
  4048. {
  4049. ligne_i = TextStream1.readLine();
  4050. tableWidget_3->item(num_ligne, 8)->setText(" ");
  4051. sA= extraction_data(ligne_i, "A="); tableWidget_3->item(num_ligne, 9)->setText(sA);
  4052. sC= extraction_data(ligne_i, "C="); tableWidget_3->item(num_ligne, 10)->setText(sC);
  4053. sD= extraction_data(ligne_i, "D="); tableWidget_3->item(num_ligne, 11)->setText(sD);
  4054. num_ligne++;
  4055. }
  4056. file1.close();
  4057.  
  4058. return 0;
  4059. }
  4060.  
  4061.  
  4062. void MainWindow::on_Bt_calcul_tps_clicked()
  4063. {
  4064. calcul_tps();
  4065. }
  4066.  
  4067.  
  4068. void MainWindow::on_pushButton_12_clicked()
  4069. {
  4070. QMessageBox msgBox;
  4071. QString s1;
  4072. s1 = "ABBREVIATIONS, sigles utilisés"; s1 += "\n";
  4073. s1 += "dans la colonne Cmt ->"; s1 += "\n";
  4074. s1 += "\n";
  4075. s1 += "(GL = début glissendo"; s1 += "\n";
  4076. s1 += "GL) = fin glissendo"; s1 += "\n";
  4077. s1 += "HO = Hammer-On"; s1 += "\n";
  4078. s1 += "PO = Pull-Off"; s1 += "\n";
  4079. s1 += "pB = petit Barré (cordes 1-2-3)"; s1 += "\n";
  4080. msgBox.setText(s1);
  4081. msgBox.exec();
  4082. }
  4083.  
  4084.  
  4085. void MainWindow::on_Bt_sigle_1_clicked()
  4086. {
  4087. complete_case(num_ligne_en_cours, 3, "(GL", "#000000","#FFFCDD", false, tableWidget_3);
  4088. }
  4089.  
  4090.  
  4091. void MainWindow::on_Bt_sigle_2_clicked()
  4092. {
  4093. complete_case(num_ligne_en_cours, 3, "GL)", "#000000","#FFFCDD", false, tableWidget_3);
  4094. }
  4095.  
  4096.  
  4097. void MainWindow::on_Bt_sigle_3_clicked()
  4098. {
  4099. complete_case(num_ligne_en_cours, 3, "(HO", "#000000","#FFFCDD", false, tableWidget_3);
  4100. }
  4101.  
  4102.  
  4103. void MainWindow::on_Bt_sigle_4_clicked()
  4104. {
  4105. complete_case(num_ligne_en_cours, 3, "HO)", "#000000","#FFFCDD", false, tableWidget_3);
  4106. }
  4107.  
  4108.  
  4109. void MainWindow::on_Bt_sigle_5_clicked()
  4110. {
  4111. complete_case(num_ligne_en_cours, 3, "Ba", "#000000","#FFFCDD", false, tableWidget_3);
  4112. }
  4113.  
  4114.  
  4115. void MainWindow::on_Bt_sigle_9_clicked()
  4116. {
  4117. complete_case(num_ligne_en_cours, 3, "PO", "#000000","#FFFCDD", false, tableWidget_3);
  4118. }
  4119.  
  4120.  
  4121. void MainWindow::on_Bt_sigle_10_clicked()
  4122. {
  4123. complete_case(num_ligne_en_cours, 3, "Ba", "#000000","#FFFCDD", false, tableWidget_3);
  4124. }
  4125.  
  4126.  
  4127. void MainWindow::on_pushButton_clicked()
  4128. {
  4129. encadre_accord(spinBox_4->value(), spinBox_5->value());
  4130. }
  4131.  
  4132.  

12 Documents

Important : Le dossier 'notes' contenant les échantillons audios des notes midi (midi 52 à 94) doit être placé dans le dossier de l’exécutable. (Ce dossier de l’exécutable (= Répertoire de compilation) étant choisi lors de la configuration du projet sous Qt Creator). Ces notes servent à rejouer la musique à partir des codes midi fournis par la transformée de Fourier.

13 -

Liens...

525