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-06-09 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. const int _nb_ech = 2048;
  93.  
  94. Complexe ech[_nb_ech]; // nb_ech echantillons
  95. Complexe tab_X[_nb_ech]; // nb_ech valeurs traitées
  96. Complexe tab_W[_nb_ech];
  97. bool tableau_w_plein = false;
  98.  
  99. uint8_t table_FREQ_midi[2000][1]; // [t][num_raie]
  100. double table_integration_amplitudes[83];// [code midi]
  101.  
  102. uint16_t table_histogramme_durees[35]; // [valeur_duree] = nb d'occurences
  103. const uint16_t _Hmax =42;
  104. uint16_t table_histogramme_midi[_Hmax]; // [num_midi] = nb d'occurences
  105. uint16_t table_histogramme_degre[12]; //[n°degre = 1..12] = nb d'occurences
  106.  
  107. double facteur_compression=1.0;
  108.  
  109. //double frequence1=400; // Hz
  110. //double frequence2=400; // Hz
  111. //double frequence3=100; // Hz
  112.  
  113. uint nb_etapes=10; // 10
  114. uint nb_ech = pow (2, nb_etapes); // nombre d'échantillons = 2 puissance(nb_etapes) ->2^10 = 1024
  115.  
  116. double table_modules_FFT[_nb_ech /2]; // = 2^10
  117.  
  118. double x_clic_ecran, y_clic_ecran;
  119. double x_clic_GRV4, y_clic_GRV4; // relatif à graphicsView4
  120.  
  121. double x0_boite, x1_boite, y0_boite, y1_boite;
  122.  
  123. int nb_tics;
  124. int nb_tics2=0;
  125. int delta_barre=0;
  126. int num_barre_en_cours=0; // permet de tracer l'avancement de l'exécution des notes du morceau
  127. int num_barre_saisie=0; // pour le composeur manuel
  128. long T_i=0; // variable GLOBALE
  129. int n_player=1;
  130. double seuil;
  131. double gain =1.0;
  132. int num_note_depart;
  133. int num_note_cliquee=0;
  134. int num_note_jouee=0;
  135. int nb_acc=0;
  136. int num_note_max=0;
  137. double memo_scroll_x=0;
  138. QDateTime temps_0; // départ du jeu des notes
  139. bool hamming = true;
  140. bool bourrage_de_zeros = true;
  141.  
  142. // type de mesure noté Ta/Tb (4/4, 3/2 ...)
  143. int8_t Ta = 4;
  144. int8_t Tb = 4;
  145.  
  146. int n_barre_copie;
  147.  
  148.  
  149. //QList<int> index_midi; // position x des notes midi sur le graphe FFT (à partir de midi=40)
  150. QList<QString> liste_couleurs;
  151. QList<ENR_FFT> liste_ENR_FFT; // liste de "notes" détectées (maximums de FFT)
  152. QList<NOTE> liste_NOTES;
  153. //QList<QString> noms_notes;
  154. QList<QString> gamme_chromatique;
  155. QList<QString> gamme_chromatique_GB;
  156. QList<QString> types_note;
  157. QList<QString> types_silence;
  158.  
  159.  
  160. QFile file_wav; // fichier à analyser
  161. QFile file_dat; // datas du TAB_FRQ
  162.  
  163. QDir currentDir;
  164. QString base_Dir;
  165. QString default_Dir = "/home/";
  166. QString string_currentDir = default_Dir; // à priori; sera mis à jour lors de la lecture du fichier 'params.ini'
  167. QString string_currentFile;
  168. QString nom_fichier_in="";
  169.  
  170. QDataStream binStream1;
  171.  
  172. double duree_totale; // calculée dans la fonction 'decode_entete'
  173. double data_size; // calculée dans la fonction 'decode_entete'
  174.  
  175. bool wav_ok = false;
  176. bool dossier_de_travail_ok = false;
  177. bool data_nts_ok = false;
  178. bool rapide = false;
  179. bool etendre = true;
  180. bool mode_composition = false;
  181.  
  182. //bool visu_T = true;
  183. //bool visu_notesM = false;
  184. //bool visu_M; // echelle temporelle sous forme de mesures (temps forts, temps faibles)
  185. //bool visu_T; // echelle temporelle simple en 1/40s
  186.  
  187. char mode = 'T'; // T ou M
  188.  
  189. bool visu_freq = true;
  190. bool visu_ech_tps;
  191. //bool mode_select = false;
  192.  
  193. bool visu_duree_notes = true;
  194. int duree_int = 4;
  195. bool visu_notes = true;
  196. bool visu_notes_auto = true;
  197. bool lecture_en_cours = false;
  198.  
  199. uint32_t offset_t;
  200. double zoom_x =1.0;
  201.  
  202.  
  203. MainWindow::MainWindow(QWidget *parent) :
  204. QMainWindow(parent)
  205. {
  206. setupUi(this);
  207. setWindowTitle("Transformée de Fourier Rapide FFT - version " + version);
  208.  
  209. //this->setGeometry(0,0, 1900, 1000);
  210. setWindowState(Qt::WindowMaximized);
  211. tabWidget_Global->setGeometry(0,0, 1920, 1280);
  212. tabWidget_Global->setCurrentIndex(0);
  213.  
  214. //-----------------------------------------------------
  215. // SCENE 1 - celle du haut ('Transformée de Fourier' ET 'partie échantillonée du signal')
  216.  
  217. scene1 = new QGraphicsScene(this);
  218. scene1->setBackgroundBrush(QColor(couleur_ecran));
  219. graphicsView1->setScene(scene1);
  220. graphicsView1->setGeometry(0, 0, 1900, 655); //( 0, 0, 1900, 700)
  221. graphicsView1->verticalScrollBar()->setValue(0);
  222.  
  223. calque_reticule1 = new QGraphicsItemGroup();
  224. scene1->addItem(calque_reticule1);
  225. afficher_titre_calque("Transformée de Fourier", 0, 0, calque_reticule1);
  226.  
  227. calque_trace_signal1 = new QGraphicsItemGroup();
  228. scene1->addItem(calque_trace_signal1);
  229.  
  230. calque_trace_FFT = new QGraphicsItemGroup();
  231. scene1->addItem(calque_trace_FFT);
  232.  
  233. calque_curseur = new QGraphicsItemGroup();
  234. scene1->addItem(calque_curseur);
  235.  
  236. calque_lignes_F_zero = new QGraphicsItemGroup();
  237. scene1->addItem(calque_lignes_F_zero);
  238.  
  239.  
  240. //-----------------------------------------------------
  241. // SCENE 2 - celle du bas ('Fichier Audio .wav')
  242.  
  243. scene2 = new QGraphicsScene(this);
  244. QBrush QB1("#222222");
  245. scene2->setBackgroundBrush(QB1); // couleur_ecran
  246.  
  247. graphicsView2->setScene(scene2);
  248. graphicsView2->setGeometry(0, 660, 1900, 200); // (0, 660, 1900, 200)
  249.  
  250. calque_trace_signal2 = new QGraphicsItemGroup();
  251. scene2->addItem(calque_trace_signal2);
  252.  
  253.  
  254. calque_reticule2 = new QGraphicsItemGroup();
  255. scene2->addItem(calque_reticule2);
  256. afficher_titre_calque("Fichier Audio .wav", 0, -80, calque_reticule2);
  257.  
  258. calque_encadrement1 = new QGraphicsItemGroup();
  259. scene2->addItem(calque_encadrement1);
  260.  
  261. calque_encadrement2 = new QGraphicsItemGroup();
  262. scene2->addItem(calque_encadrement2);
  263.  
  264. //-----------------------------------------------------
  265. // SCENE 3 - LISTE verticale NOTES sur l'onglet NOTES
  266. scene3 = new QGraphicsScene(this);
  267. scene3->setBackgroundBrush(QColor(couleur_ecran));
  268. graphicsView3->setScene(scene3);
  269.  
  270. calque_gradu_TAB_FRQ = new QGraphicsItemGroup();
  271. scene3->addItem(calque_gradu_TAB_FRQ);
  272.  
  273. //-----------------------------------------------------
  274. // SCENE 4 - sur l'onglet NOTES
  275.  
  276. scene4 = new QGraphicsScene(this);
  277. scene4->setBackgroundBrush(QColor(couleur_ecran));
  278. graphicsView4->setScene(scene4);
  279.  
  280. calque_grille_M = new QGraphicsItemGroup();
  281. scene4->addItem(calque_grille_M);
  282.  
  283. calque_grille_T = new QGraphicsItemGroup();
  284. scene4->addItem(calque_grille_T);
  285.  
  286. calque_TAB_FRQ = new QGraphicsItemGroup();
  287. scene4->addItem(calque_TAB_FRQ);
  288. afficher_titre_calque("Table Fréquences & notes", 200, 0, calque_TAB_FRQ);
  289.  
  290. calque_notes_manuelles = new QGraphicsItemGroup();
  291. scene4->addItem(calque_notes_manuelles);
  292.  
  293. calque_notes_auto = new QGraphicsItemGroup();
  294. scene4->addItem(calque_notes_auto);
  295.  
  296. calque_notes_jouee = new QGraphicsItemGroup();
  297. scene4->addItem(calque_notes_jouee);
  298.  
  299. calque_echelle_temporelle_T = new QGraphicsItemGroup();
  300. scene4->addItem(calque_echelle_temporelle_T);
  301.  
  302. calque_echelle_temporelle_M = new QGraphicsItemGroup();
  303. scene4->addItem(calque_echelle_temporelle_M);
  304.  
  305. calque_surbrillance= new QGraphicsItemGroup();
  306. scene4->addItem(calque_surbrillance);
  307.  
  308. calque_rect_select= new QGraphicsItemGroup();
  309. scene4->addItem(calque_rect_select);
  310.  
  311. //-----------------------------------------------------
  312. // SCENE 5 - Histogramme sur l'onglet NOTES
  313.  
  314. scene5 = new QGraphicsScene(this);
  315. scene5->setBackgroundBrush(QColor(couleur_ecran));
  316. graphicsView5->setScene(scene5);
  317. calque_histogramme = new QGraphicsItemGroup();
  318. scene5->addItem(calque_histogramme);
  319. //-----------------------------------------------------
  320.  
  321. Timer1 = new QTimer(this);
  322. connect(Timer1, SIGNAL(timeout()), this, SLOT(Tic1()));
  323.  
  324. Timer2 = new QTimer(this);
  325. connect(Timer2, SIGNAL(timeout()), this, SLOT(Tic2()));
  326.  
  327. Timer3 = new QTimer(this);
  328. connect(Timer3, SIGNAL(timeout()), this, SLOT(Tic3()));
  329.  
  330.  
  331. //noms_notes<<"La"<<"Si"<<"Do"<<"Ré"<<"Mi" <<"Fa"<<"Sol"<<"--"<<"--"; // <- A B C D E F G
  332. gamme_chromatique<<"Do"<<"Do#"<<"Ré"<<"Ré#"<<"Mi"<<"Fa"<<"Fa#"<<"Sol"<<"Sol#"<<"La"<<"La#"<<"Si";
  333.  
  334. //la gamme GB commence en principe par la lettre A (=La) mais pour simplifier ce programme
  335. //on la fait partir de C (=Do) comme la gamme FR...
  336. gamme_chromatique_GB<<"C"<<"C#"<<"D"<<"Eb"<<"E"<<"F"<<"F#"<<"G"<<"G#"<<"A"<<"A#"<<"B";
  337.  
  338. types_note <<"ronde"<<"blanche"<<"noire"<<"croche"<<"double croche"<<"triple croche"<<""<<"";
  339. types_silence << "pause" << "demi-pause" << "soupir" << "demi-soupir" << "quart de soupir" << "";
  340.  
  341. // dans la liste suivante, la première couleur (#0)->"#EF2929" est le rouge pour la note DO
  342. liste_couleurs <<"#EF2929"<<"#FF5C00"<<"#FCAF3E"<<"#FFE300"<<"#BFFF00"<<"#07F64F"
  343. <<"#16D298"<<"#16D2C4"<<"#00AEFF"<<"#1667D2"<<"#7C00FF"<<"#FF67EF"<<"#EEEEEC";
  344.  
  345. player1 = new QMediaPlayer;
  346. audioOutput1 = new QAudioOutput(this);
  347. player1->setAudioOutput(audioOutput1);
  348.  
  349. player2 = new QMediaPlayer;
  350. audioOutput2 = new QAudioOutput(this);
  351. player2->setAudioOutput(audioOutput2);
  352.  
  353. player3 = new QMediaPlayer;
  354. audioOutput3 = new QAudioOutput(this);
  355. player3->setAudioOutput(audioOutput3);
  356.  
  357. player4 = new QMediaPlayer;
  358. audioOutput4 = new QAudioOutput(this);
  359. player4->setAudioOutput(audioOutput4);
  360.  
  361. player5 = new QMediaPlayer;
  362. audioOutput5 = new QAudioOutput(this);
  363. player5->setAudioOutput(audioOutput5);
  364.  
  365. parametrages();
  366.  
  367. if(0)
  368. {
  369. //pour la phase de developpement
  370. afficher_titre_calque("Scene1", 100, 200, calque_trace_FFT);
  371. afficher_titre_calque("Scene2", 20, 20, calque_trace_signal2);
  372. afficher_titre_calque("Scene3", 10, 10, calque_gradu_TAB_FRQ);
  373. afficher_titre_calque("Scene4", 100, 100, calque_grille_T);
  374. afficher_titre_calque("Scene5", 20, 20, calque_histogramme);
  375. }
  376.  
  377. }
  378.  
  379.  
  380. void MainWindow::parametrages()
  381. {
  382. load_fichier_ini();
  383.  
  384. calcul_tableau_W();
  385. tracer_graduations_signal();
  386. tracer_graduations_FFT();
  387.  
  388. init_TW_1();
  389. init_TAB_FRQ();
  390. init_TAB_lst_notes();
  391. init_TW_type_M();
  392. init_Autres();
  393.  
  394. seuil = doubleSpinBox_seuil->value();
  395.  
  396. on_Bt_par_defaut_clicked();// valeurs FFT par défaut
  397.  
  398. write_mode=0;
  399. on_Bt_mode_R_clicked();
  400.  
  401. visu_notes_auto = false;
  402. on_Bt_toggle_visu_notes_auto_clicked();
  403.  
  404. visu_notes = false;
  405. on_Bt_toggle_visu_notes_clicked();
  406.  
  407. on_tableWidget_type_M_cellClicked(2, 0);
  408.  
  409. spinBox_zoom_2->setValue(2);
  410. // Bt_jouer_tout->setStyleSheet("background-color: rgb(200, 200, 200);");
  411.  
  412. progressBar_1->setValue(0);
  413.  
  414. effacer_calque(scene1,calque_lignes_F_zero );
  415. effacer_calque(scene1,calque_encadrement1 );
  416. effacer_calque(scene1,calque_trace_signal1 );
  417. effacer_calque(scene1,calque_trace_FFT );
  418. effacer_calque(scene1,calque_curseur );
  419.  
  420. effacer_calque(scene2,calque_encadrement2 );
  421. effacer_calque(scene2, calque_trace_signal2 );
  422.  
  423. effacer_calque(scene4,calque_TAB_FRQ );
  424. effacer_calque(scene4, calque_notes_manuelles );
  425. effacer_calque(scene4, calque_notes_auto );
  426. effacer_calque(scene4, calque_notes_jouee );
  427. effacer_calque(scene4, calque_echelle_temporelle_T);
  428.  
  429. for(int i=0; i<35; i++) { table_histogramme_durees[i]=0; }
  430. effacer_calque(scene5, calque_histogramme );
  431.  
  432. on_Bt_RAZ_clicked();
  433.  
  434. T_i=0; // T_i : variable GLOBALE
  435. doubleSpinBox_dxb->setValue(2.5);
  436.  
  437. mode='M';
  438. on_Bt_toggle_grille_T_clicked();
  439. mode_grille_T();
  440. spinBox_nb_barres->setValue(40);
  441. effacer_calque(scene4, calque_grille_T);
  442. tracer_grille_T();
  443. checkBox_scrolling->setChecked(true);
  444.  
  445. }
  446.  
  447.  
  448. void MainWindow::init_TAB_FRQ()
  449. {
  450. frame_notes->setGeometry(0,0,1920,720);
  451.  
  452. graphicsView3->setGeometry(0, 30, 100, 730);
  453.  
  454. graphicsView4->setGeometry(100, 30, 2000, 730);
  455. graphicsView4->setEnabled(false); // empêche le recadrage auto par le contenu, mais disable le scroll manuel !
  456.  
  457. rectangle1 = new QGraphicsRectItem(0, 0, 2000, 670);
  458.  
  459. rectangle1->setPen(QColor(couleur_ligne));
  460. calque_TAB_FRQ->addToGroup(rectangle1);
  461. tracer_graduation_TAB_NOTES();
  462. tracer_grille_M();
  463. }
  464.  
  465.  
  466. void MainWindow::init_TAB_lst_notes()
  467. {
  468. tableWidget_lst_notes->setGeometry(1105, 30, 350, 201);
  469. QStringList liste_entetes1;
  470. liste_entetes1<<"num"<<"midi"<<"note"<<"n° barT"<< "n° barM)" << "durée";
  471. tableWidget_lst_notes->setColumnWidth(1, 40);
  472. tableWidget_lst_notes->setColumnWidth(5, 50);
  473. tableWidget_lst_notes->setHorizontalHeaderLabels (liste_entetes1);
  474. tableWidget_lst_notes->setEditTriggers(QAbstractItemView::NoEditTriggers);
  475. }
  476.  
  477.  
  478.  
  479. void MainWindow::init_Autres()
  480. {
  481. // frame_1->setGeometry(1250, 865, 410, 131);
  482. // frame_1->setVisible(true);
  483. frame_2->setGeometry(10, 865, 970, 75);
  484. frame_3->setGeometry(1000, 865, 665, 121);
  485. frame_5->setGeometry(0, 760, 1920, 260); // 0, 760, 1920, 260
  486. frame_6->setGeometry(10, 950, 901, 40);
  487.  
  488. graphicsView5->setGeometry(1460, 15, 440, 235); //225 histogrammes
  489. graphicsView5->setScene(scene5);
  490.  
  491. // voir le fichier de ressources
  492. // Le fichier image est incorporé sous forme de ressource, il sera compilé et fera partie du programme
  493. // l'image sera dispo quelle que soit l'emplacement de l'executable,
  494. // et en particulier si celui-ci est appellé via un lien.
  495. Bt_deplace_H->setIcon(QIcon(":/images/01.png" )); // Le fichier image est incorporé sous forme de ressource
  496. Bt_deplace_B->setIcon(QIcon(":/images/02.png" ));
  497. Bt_deplace_R->setIcon(QIcon(":/images/03.png" ));
  498. Bt_deplace_L->setIcon(QIcon(":/images/04.png" ));
  499.  
  500. Bt_efface->setGeometry(915, 950, 60, 21);
  501. Bt_efface_2->setGeometry(1165, 0, 81, 26);
  502. pushButton_9->setGeometry(1290, 10, 31, 20);
  503. Bt_open_DIR_2->setGeometry(912, 40, 70, 26);
  504.  
  505. frame_8->setGeometry(1500, 740, 400, 30); // boutons "debut , < , > , fin"
  506. frame_9->setGeometry(1760, 850, 100, 70);
  507. frame_11->setGeometry(200, 152, 145, 21); // copie groupe de notes
  508.  
  509. Bt_save_notes->setGeometry(831, 5, 151, 31);
  510. Bt_RAZ_general->setGeometry(1700, 900, 150, 50);
  511.  
  512. lineEdit_fichier_FREQ->setGeometry(1250, 0, 700, 22);
  513. progressBar_1->setGeometry(98, 4, 101, 18); //(1085, 3, 78, 18);
  514. lineEdit_fichier->setGeometry(380, 40, 530, 26);
  515. groupBox_2->setGeometry(380, 70, 350, 161);
  516. groupBox_3->setGeometry(750, 70, 351, 161);
  517.  
  518. Bt_dedoubleM->setGeometry(110, 5, 92, 26);
  519.  
  520. // label_image1->setGeometry(1800, 780, 10, 10);
  521. frame_cle_de_sol->setGeometry(1700, 10, 200, 340); //1800, 805, 100, 170
  522. frame_cle_de_sol->setVisible(false);
  523. Bt_composition->setGeometry(1800, 10, 100, 30); // bouton 'Composition'
  524.  
  525. frame_composeur->setGeometry(1435, 80, 260, 181);
  526. frame_composeur->setVisible(false);
  527.  
  528. label_SEL_P_BOITE->setGeometry(120, 40, 260, 20);
  529. label_SEL_P_BOITE->setVisible(false);
  530.  
  531. tracer_gradu_temporelle_signal_entree();
  532. tracer_graduations_signal();
  533. }
  534.  
  535.  
  536. void MainWindow::init_TW_type_M()
  537. {
  538. frame_4->setGeometry(210, 5, 140, 90);
  539. frame_7->setGeometry(210, 100, 140, 50);
  540. frame_10->setGeometry(185, 100, 185, 50);
  541.  
  542. tableWidget_type_M->setGeometry(5, 20, 40, 62);
  543. lineEdit_10->setGeometry(55, 30, 51, 26);
  544. lineEdit_11->setGeometry(55, 60, 51, 26);
  545. label_8->setGeometry(2, 2, 111, 20);
  546. label_39->setGeometry(108, 63, 40, 20);
  547.  
  548. //spinBox_barre_zero->setGeometry(5, 110, 61, 21);
  549. //spinBox_nb_barres->setGeometry(5, 130, 61, 21);
  550.  
  551.  
  552. QStringList liste_labels; // pour mettre directement dans la 1ere colonne (et pas en entêtes)
  553. liste_labels << "2/4" << "3/4" << "4/4";
  554. for(int n=0; n<3; n++) { tableWidget_type_M->setItem(0, n, new QTableWidgetItem (liste_labels[n])); }
  555. }
  556.  
  557.  
  558. void MainWindow::init_TW_1() // affi entete du fichier wav
  559. {
  560. tableWidget_1->setGeometry(700, 200, 600, 300);
  561. Bt_close_entete->setGeometry(1280, 200, 20, 20);
  562. tableWidget_1->setColumnCount(6);
  563. tableWidget_1->setColumnWidth(4, 120);
  564. tableWidget_1->setColumnWidth(5, 130);
  565.  
  566. tableWidget_1->setVisible(false);
  567. Bt_close_entete->setVisible(false);
  568.  
  569. QStringList liste_entetes;
  570. liste_entetes <<"FileTypeBlocID"
  571. <<"FileSize"
  572. <<"FileFormatID"
  573. <<"FormatBlocID"
  574. <<"BlocSize"
  575. <<"AudioFormat"
  576. <<"NbrCanaux"
  577. <<"Frequence"
  578. <<"ECH (BytePerSec)"
  579. <<"BytePerBloc"
  580. <<"BitsPerSample"
  581. <<"DataBlocID"
  582. <<"DataSize"
  583. <<"durée calculée";
  584.  
  585. tableWidget_1->setVerticalHeaderLabels(liste_entetes);
  586. }
  587.  
  588.  
  589. void MainWindow::load_fichier_ini()
  590. {
  591. QString line;
  592. int p1, p2, p3;
  593.  
  594. dossier_de_travail_ok = false; // à priori
  595. QFile file1(QDir::currentPath() + "/" + "params_FFT.ini"); // dans le dossier de l'exécutable (= QDir::currentPath() )
  596. if (file1.open(QIODevice::ReadOnly | QIODevice::Text))
  597. {
  598. QTextStream in(&file1);
  599. in.reset();
  600. while ( !in.atEnd() )
  601. {
  602. line = in.readLine();
  603. if (line.at(0) !='#')
  604. {
  605. if ((p1 = line.indexOf("<currentDir>")) != -1)
  606. {
  607. p2 = line.indexOf('>',p1);
  608. p3 = line.indexOf("</",p2);
  609. QString s1 = line.mid(p2+1, p3-p2-1);
  610. string_currentDir = s1;
  611. dossier_de_travail_ok = true;
  612. }
  613.  
  614. if ((p1 = line.indexOf("<currentFile>")) != -1)
  615. {
  616. p2 = line.indexOf('>',p1);
  617. p3 = line.indexOf("</",p2);
  618. QString s1 = line.mid(p2+1, p3-p2-1);
  619. string_currentFile = s1;
  620. }
  621. }
  622. }
  623. file1.close();
  624. }
  625. else
  626. {
  627. QString s1 = "fichier .ini non trouvé, je le crée (dans le dossier de l'executable)";
  628. QMessageBox msgBox; msgBox.setText(s1); msgBox.exec();
  629. base_Dir=QDir::currentPath() + "/";
  630. save_fichier_ini();
  631. dossier_de_travail_ok = false;
  632. }
  633. lineEdit_current_dir->setText(string_currentDir);
  634. lineEdit_fichier->setText(string_currentDir);
  635. }
  636.  
  637.  
  638.  
  639. QString calcul_couleur(double x) // x = 0.0 à 1.0 ; return: rouge->jaune->vert
  640. {
  641. QString coul_str ="#000000";
  642. QString coul_R_str="#000000";
  643. QString coul_V_str="#000000";
  644. int R, V; // rouge, vert
  645.  
  646. V= x * 255;
  647. R= 300 - (1.2 * V);
  648.  
  649. double coxh;
  650. // la formule suivante met le jaune en valeur (avec un cosinus hyperbolique)
  651. 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) )
  652.  
  653. R *= coxh/1.2;
  654. V *= coxh/1.2;
  655.  
  656. coul_R_str.setNum(R, 16); coul_R_str = "0" + coul_R_str; coul_R_str = coul_R_str.right(2);
  657. coul_V_str.setNum(V, 16); coul_V_str = "0" + coul_V_str; coul_V_str = coul_V_str.right(2);
  658. coul_str = coul_R_str + coul_V_str;
  659. coul_str = "#" + coul_str + "00";
  660. return coul_str; // de la forme "#AABB00" (rouge & vert en exa, (bleu à zéro, à traiter))
  661. }
  662.  
  663.  
  664.  
  665. int MainWindow::calcul_y_note(int midi) // en pixels sur la grille
  666. {
  667. int y =690 - ((midi-28) * 12); // voir 'tracer_graduation_TAB_NOTES()' pour l'espacement vertical
  668. return y;
  669. }
  670.  
  671.  
  672.  
  673. int MainWindow::calcul_hauteur_note(int mid) //'hauteur' au sens musical, gamme chromatique de 0 à 11
  674. {
  675. int h1 = mid;
  676.  
  677. while(h1>=12) {h1-=12;}
  678. while(h1<0) {h1+=12;}
  679. if (h1==12) {h1=0;}
  680. if ((h1<0) || (h1>(liste_couleurs.length()-1))) {h1 = 0;}
  681.  
  682. return h1; // h1 = 0..11
  683. }
  684.  
  685.  
  686.  
  687. QString MainWindow::nom_note(int mid)
  688. {
  689. QString s1;
  690.  
  691. int h1 = calcul_hauteur_note(mid);
  692. s1 = gamme_chromatique[h1];
  693. return s1;
  694. }
  695.  
  696.  
  697. QString MainWindow::nom_note_GB(int mid)
  698. {
  699. QString s1;
  700.  
  701. int h1 = calcul_hauteur_note(mid);
  702. s1 = gamme_chromatique_GB[h1];
  703. return s1;
  704. }
  705.  
  706.  
  707. QString MainWindow::nom_octave_GB(int mid)
  708. {
  709. QString octave;
  710. if((mid>=40)&&(mid < 48)) {octave = "2";}
  711. if((mid>=48)&&(mid < 60)) {octave = "3";}
  712. if((mid>=60)&&(mid < 72)) {octave = "4";}
  713. if((mid>=72)&&(mid < 90)) {octave = "5";}
  714. return octave;
  715. }
  716.  
  717.  
  718.  
  719. double freq_mid(int midi_i) // calcule la fréquence (en Hertz) d'une note à partir de son numéro midi
  720. {
  721. // https://fr.wikipedia.org/wiki/MIDI_Tuning_Standard
  722. double F, A;
  723. A=((double)midi_i-69.0)/12.0;
  724. F= 440 * powf(2,A);
  725. return F;
  726. }
  727.  
  728.  
  729. double calcul_id_midi(double freq_i) // complément de la fonction précédente ( double freq_mid(int midi_i) )
  730. {
  731. double id;
  732. id = 69.0 + 12.0 * log2(freq_i / 440.0);
  733. return id;
  734. }
  735.  
  736.  
  737. int MainWindow::calcul_num_midi(double x) // en fonction de la position horizontale dans le tableau d'affichage de la FFT
  738. {
  739. // on va détecter la note la plus proche de la position donnée
  740. // rappel : x=96 +(m-28) * 32 (voir la fonction : 'tracer_graduations_FFT()')
  741.  
  742. double dx;
  743. double xm;
  744.  
  745. for (int m=28; m<83; m++)
  746. {
  747. xm= 96.0 +(m-28) * 32.0;
  748. dx = xm-x;
  749. if (dx<0){dx=-dx;}
  750. if (dx < (32.0/2) )
  751. {
  752. // encadrement_note(m);
  753. return m;
  754. }
  755. }
  756. return 0;
  757. }
  758.  
  759.  
  760. void MainWindow::play_note(int midi) // sortie audio; duree en nb de barres
  761. {
  762. QString s1, freq_txt;
  763. calcul_hauteur_note(midi);
  764. s1.setNum(midi);
  765. // fichiers audio comprenant une seule note chacun, voir dans le dossier "notes" sur le HDD
  766.  
  767. //int D;
  768. //if (mode == 'M') {D = 20;} else {D = 40;}
  769.  
  770. // (duree_i < D) { s1="notes2/"+s1+".wav"; } // (notes2 = notes +10dB)
  771. if (checkBox_long->isChecked()) { s1="notes_longues/"+s1+".wav"; } // (notes2 = notes +10dB)
  772. else { s1="notes2/"+s1+".wav"; }
  773.  
  774. //qDebug() << "s1" << s1;
  775.  
  776. if (n_player == 1) {player1->stop(); player1->setSource(QUrl::fromLocalFile(s1)); player1->play();}
  777. if (n_player == 2) {player2->stop(); player2->setSource(QUrl::fromLocalFile(s1)); player2->play();}
  778. if (n_player == 3) {player3->stop(); player3->setSource(QUrl::fromLocalFile(s1)); player3->play();}
  779. if (n_player == 4) {player4->stop(); player4->setSource(QUrl::fromLocalFile(s1)); player4->play();}
  780. if (n_player == 5) {player5->stop(); player5->setSource(QUrl::fromLocalFile(s1)); player5->play();}
  781. n_player++;
  782. if (n_player > 5) {n_player = 1;} // voir ligne 4013 RAZ du n° player, à voir
  783. }
  784.  
  785.  
  786.  
  787.  
  788. void MainWindow::effacer_calque(QGraphicsScene *scene_i, QGraphicsItemGroup *calque_i)
  789. {
  790. foreach( QGraphicsItem *item, scene_i->items( calque_i->boundingRect() ) )
  791. {if( item->group() == calque_i ) { delete item; }}
  792. }
  793.  
  794.  
  795. MainWindow::~MainWindow()
  796. {
  797.  
  798. }
  799.  
  800.  
  801.  
  802. void MainWindow::Etiquette(int x, int y, int dx, QString s, QString coul_txt, QString coul_fond, QString coul_bord, QGraphicsItemGroup *calque_i )
  803. {
  804. // si dx = 0 -> la largeur sera fonction du nb de caractères
  805.  
  806. if (dx==0)
  807. {
  808. dx = 8 * (s.length()+1 );
  809. }
  810. rect1 = new QGraphicsRectItem(x, y+4, dx, 18);
  811. rect1->setPen(QColor(coul_bord)); // bordure
  812. rect1->setBrush(QColor(coul_fond)); // fond
  813. calque_i->addToGroup(rect1);
  814.  
  815. //texte
  816. GraphicsTextItem = new QGraphicsTextItem(s);
  817. GraphicsTextItem->setPos(x, y);
  818. GraphicsTextItem->setDefaultTextColor(coul_txt);
  819. calque_i->addToGroup(GraphicsTextItem);
  820. }
  821.  
  822.  
  823.  
  824. void MainWindow::tracer_graduations_FFT() // sur onglet 'Source wav'
  825. {
  826. double x=0;
  827. QString s1;
  828. int y_bas =450; // 350
  829.  
  830. // cadre
  831. rectangle1 = new QGraphicsRectItem(0, 0, 1900, y_bas);
  832. QPen pen1("#12FF00");
  833. rectangle1->setPen(pen1);
  834.  
  835. calque_reticule1->addToGroup(rectangle1);
  836.  
  837. s1 = "midi :"; // numéro midi
  838. GraphicsTextItem = new QGraphicsTextItem(s1);
  839. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  840. GraphicsTextItem->setPos(30, 20);
  841. // if(x<1900)
  842. {
  843. calque_reticule1->addToGroup(GraphicsTextItem);
  844. }
  845.  
  846. // positions des notes midi
  847. x= 96;
  848. for(int m=28; m<=83; m++)
  849. {
  850. ligne1 = new QGraphicsLineItem(x, 70, x, y_bas);
  851. ligne1->setPen(pen_reticule);
  852. calque_reticule1->addToGroup(ligne1);
  853.  
  854. s1.setNum(m); // numéro midi
  855. GraphicsTextItem = new QGraphicsTextItem(s1);
  856. GraphicsTextItem->setDefaultTextColor("#D3D7CF");
  857. GraphicsTextItem->setPos(x-15, 20);
  858. if(x<1900) {calque_reticule1->addToGroup(GraphicsTextItem); }
  859.  
  860. int h1 = calcul_hauteur_note(m);
  861.  
  862. s1 = " " + gamme_chromatique[h1]; // nom de la note
  863. GraphicsTextItem = new QGraphicsTextItem(s1);
  864. GraphicsTextItem->setDefaultTextColor(liste_couleurs[h1]);
  865. GraphicsTextItem->setPos(x-18, 40);
  866. if(x<1900) {calque_reticule1->addToGroup(GraphicsTextItem); }
  867.  
  868. x+=32.0; // espacement des graduation
  869. }
  870. }
  871.  
  872.  
  873. // voir fonction "void MainWindow::tracer_echelle_temps_TAB_NOTES()"
  874. // dx = 1000.0 * pas_echantillonage/256.0; // = 1000 * 24 /256 = 93.75
  875.  
  876.  
  877. double MainWindow:: calcul_pas_grille()
  878. {
  879. double pas = 0;
  880. if (mode == 'T')
  881. {
  882. pas = 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x; // 1 barre toutes les 1/40 seconde
  883. }
  884. if (mode == 'M')
  885. {
  886. pas = (doubleSpinBox_dxb->value()) * 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x;
  887. }
  888. //qDebug() << "pas" << pas ;
  889. return pas;
  890. }
  891.  
  892. /*
  893. double MainWindow::calcul_pas_grille_M()
  894. {
  895.   double pas_grille_M = (spinBox_dxa->value()+doubleSpinBox_dxb->value()) * 1000.0 * pas_echantillonage/256.0 / 40.0 * zoom_x;
  896.   return pas_grille_M;
  897. }
  898. */
  899.  
  900. int MainWindow::calcul_tempo()
  901. {
  902. double dbar = doubleSpinBox_dxb->value(); // nb de barres de 1/40s séparant 2 barres de mesure
  903. double dt = (8.0/40.0) * dbar; // en s
  904. double nb_bpm = 60.0 / dt; // nb de barres / mn
  905. //double Tp = nb_bpm / 8.0;
  906. return int(nb_bpm);
  907. }
  908.  
  909.  
  910.  
  911. double MainWindow::calcul_x_barre(int n_barre)
  912. {
  913. // calcul de l'abscisse (en pixel) d'une barre de mesure
  914. double x =0;
  915. double x0;
  916.  
  917. int x0a = spinBox_x0a->value();
  918. double x0b = 80.0 + 10.0 * doubleSpinBox_x0b->value();
  919. x0b += 20.0 * x0a;
  920.  
  921. if (mode == 'T')
  922. {
  923. x0 = 80.0; // 100 à voir !
  924. x = x0 + double(n_barre) * calcul_pas_grille();
  925. }
  926. if (mode == 'M')
  927. {
  928. x = x0b + double(n_barre) * calcul_pas_grille();
  929. }
  930. //qDebug() << "x" << x;
  931. return x;
  932. }
  933.  
  934. /*
  935. double MainWindow::calcul_x_barre_M(int n_barre)
  936. {
  937.   double x = double(n_barre) * calcul_pas_grille_M();
  938.   return x;
  939. }
  940. */
  941.  
  942. void MainWindow::trace_1_barre_M(double x_i, QString couleur_i)
  943. {
  944. if(x_i<0) {return;} // pour ne pas décaler tout l'affichage
  945. QPen pen_i;
  946. pen_i.setColor(couleur_i);
  947. ligne1 = new QGraphicsLineItem(x_i, 0.0, x_i, 700.0);
  948. ligne1->setPen(pen_i);
  949. calque_grille_M->addToGroup(ligne1);
  950. }
  951.  
  952.  
  953. void MainWindow::tracer_grille_M()
  954. {
  955. effacer_calque(scene4, calque_echelle_temporelle_M);
  956. double x1;
  957. int num_temps=0;
  958. QString s1;
  959. QPen pen1;
  960.  
  961.  
  962. QString couleur1;
  963.  
  964. QString gris_clair = "#888888";
  965. QString gris_fonce = "#444444";
  966. QString gris_tres_fonce = "#222222";
  967. QString jaune = "#FFFF00";
  968. QString cyan = "#00FFFF";
  969. int num_mesure=0;
  970. int us2=0; // une sur 2
  971. for(int n=-500; n<=1000; n++)
  972. {
  973. // rappel : mesures type Ta/Tb dans le petit tableau 'Type Mesures'
  974. // 3/4 -> Ta=3 & Tb=4
  975. // 4/4 -> Ta=4 & Tb=4
  976. x1 = calcul_x_barre(n);
  977. couleur1 = gris_clair; // à priori
  978. if (n%(4*Ta) == 0)
  979. {
  980. if(x1<0){num_mesure= -1;}
  981. num_mesure++;
  982. if(num_mesure>0)
  983. {
  984. couleur1 = cyan; us2 =0;
  985. s1.setNum(num_mesure);
  986. Etiquette(x1, 10, 0, s1, "#FFFFFF", "#000000", "#00FFFF", calque_echelle_temporelle_M ); // en haut
  987. }
  988. }
  989. if ((Ta==4) && (1) && (num_mesure<10) && (n%(Ta/2) == 0) && (checkBox_numerotation->isChecked()))
  990. {
  991. // numérotation des temps au sein de chaque mesure
  992. num_temps = n/(Ta/2);
  993. if ((num_temps>=0) && (num_temps<80)) // <8
  994. {
  995. int dy =0;
  996. int nt2 =num_temps/2;
  997. nt2 = nt2 %4;
  998. s1.setNum(nt2 + 1);
  999. if(num_temps%2 == 1)
  1000. {
  1001. s1 = "&";
  1002. dy = 10;
  1003. }
  1004. Etiquette(x1, 400-dy, 0, s1, "#FFFFFF", "#000000", "#444444", calque_echelle_temporelle_M );// au milieu
  1005. }
  1006. }
  1007. us2++;
  1008. if ((us2 %2)==0) { couleur1 = gris_fonce; }
  1009. if(n==0){couleur1 = jaune;}
  1010. trace_1_barre_M(x1, couleur1); // principale
  1011. }
  1012.  
  1013. for(int n=0; n<55; n++)
  1014. {
  1015. int y = 40 + 12*n;
  1016. ligne1 = new QGraphicsLineItem(0, y, 12000, y);
  1017.  
  1018. pen1.setColor("#555555");
  1019. ligne1->setPen(pen1);
  1020. calque_grille_T->addToGroup(ligne1);
  1021. }
  1022.  
  1023.  
  1024. double Tempo = calcul_tempo();
  1025. s1.setNum(Tempo);
  1026. lineEdit_11->setText(s1); // BPM
  1027.  
  1028. // Etiquette(0, 0, 0, s1, "#FFFFFF", "#000000", "#FF00FF", calque_echelle_temporelle_T );
  1029. // s1 = "BPM";
  1030.  
  1031. /*
  1032.   GraphicsTextItem = new QGraphicsTextItem(s1);
  1033.   GraphicsTextItem->setPos(45, 0);
  1034.   GraphicsTextItem->setDefaultTextColor("#FF00FF");
  1035.   calque_echelle_temporelle_T->addToGroup(GraphicsTextItem);
  1036. */
  1037.  
  1038. }
  1039.  
  1040.  
  1041. void MainWindow::tracer_grille_T()
  1042. {
  1043. //grille T sur l'onglet NOTES (barres verticales)
  1044. QString s1;
  1045. // QString bleu_clair = "#00AAFF";
  1046. // QString jaune = "#FFFF00";
  1047. QString gris_clair = "#CCCCCC";
  1048. QString gris_fonce = "#777777";
  1049. QString gris_tres_fonce = "#444444";
  1050. QString couleur_i;
  1051. QPen pen_i;
  1052. double x_i1;
  1053. //int num_mesure;
  1054. int nb = spinBox_nb_barres->value();
  1055. int n_zero = spinBox_barre_zero->value();
  1056.  
  1057. for(int n=0; n<=120*16; n++)
  1058. {
  1059. if (Ta<2) {Ta=2;}
  1060. x_i1 = calcul_x_barre(n);
  1061.  
  1062. couleur_i = gris_tres_fonce; // à priori
  1063.  
  1064. if (((n-n_zero)%nb) == 0) { couleur_i ="#00AAAA"; } //couleur_i = gris_fonce;
  1065. /*
  1066.   if ( n%(4*Ta) == 0) // 1er temps fort de la mmesure
  1067.   {
  1068. // numérotation des mesures, en bas, chiffres jaunes
  1069.   num_mesure = n /Ta/4;
  1070.   s1.setNum(num_mesure);
  1071.   Etiquette(x_i1-0, 0, 650, s1, "#FFFF00", "#000000", "#0000FF", calque_grille_T);
  1072.   }
  1073. */
  1074. //if ( n%(4*m)== 0) {couleur_i = jaune;}
  1075.  
  1076. pen_i.setColor(couleur_i);
  1077. ligne1 = new QGraphicsLineItem(x_i1, 0.0, x_i1, 700.0); //100.0 pour test des 2 grilles ensemble
  1078. ligne1->setPen(pen_i);
  1079. calque_grille_T->addToGroup(ligne1);
  1080. }
  1081.  
  1082. for(int n=0; n<55; n++)
  1083. {
  1084. int y =40 + 12*n;
  1085. ligne1 = new QGraphicsLineItem(0, y, 12000, y);
  1086. pen_i.setColor("#555555");
  1087. ligne1->setPen(pen_i);
  1088. calque_grille_T->addToGroup(ligne1);
  1089. }
  1090.  
  1091. }
  1092.  
  1093.  
  1094. void MainWindow::afficher_titre_calque(QString titre, int x, int y, QGraphicsItemGroup *calque_i)
  1095. {
  1096. GraphicsTextItem = new QGraphicsTextItem(titre);
  1097. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  1098. GraphicsTextItem->setPos(x, y);
  1099. calque_i->addToGroup(GraphicsTextItem);
  1100. }
  1101.  
  1102.  
  1103.  
  1104. void MainWindow::tracer_graduation_TAB_NOTES() // midi ; en colonne à gauche + noms des notes
  1105. {
  1106. // positions des notes midi
  1107. QString s1;
  1108. int y= 640; //640
  1109. for(int m=28; m<=82; m++)
  1110. {
  1111. //ligne1 = new QGraphicsLineItem(100, 0, 100, 350);
  1112. //ligne1->setPen(pen_reticule);
  1113. //calque_reticule1->addToGroup(ligne1);
  1114.  
  1115. s1.setNum(m); // numéro midi
  1116. GraphicsTextItem = new QGraphicsTextItem(s1);
  1117. GraphicsTextItem->setDefaultTextColor("#D3D7CF");
  1118. GraphicsTextItem->setFont(QFont("Arial", 8));
  1119. GraphicsTextItem->setPos(0, y);
  1120. if(y> -50) {calque_gradu_TAB_FRQ->addToGroup(GraphicsTextItem); }
  1121.  
  1122. int h1 = calcul_hauteur_note(m);
  1123. s1 = " " + gamme_chromatique[h1]; // nom de la note
  1124. GraphicsTextItem = new QGraphicsTextItem(s1);
  1125. GraphicsTextItem->setDefaultTextColor(liste_couleurs[h1]);
  1126. GraphicsTextItem->setFont(QFont("Arial", 8));
  1127. // GraphicsTextItem->setHtml("<div style='background-color:#666666;'>" + s1 + "</div>");
  1128.  
  1129. if (m==69) // La 440
  1130. {
  1131. rect3 = new QGraphicsRectItem(30, y+6, 40, 10);
  1132. QBrush br2;
  1133. QPen pen_i;
  1134. pen_i.setColor("#AAAAAA");
  1135. rect3->setPen(pen_i);
  1136. calque_gradu_TAB_FRQ->addToGroup(rect3);
  1137.  
  1138. }
  1139.  
  1140. GraphicsTextItem->setPos(30, y);
  1141. if(y > -50) {calque_gradu_TAB_FRQ->addToGroup(GraphicsTextItem); }
  1142.  
  1143. y-=12; //16 espacement des graduations
  1144. }
  1145. graphicsView4->verticalScrollBar()->setValue(0);
  1146. }
  1147.  
  1148.  
  1149.  
  1150. void MainWindow::tracer_graduations_signal() // sur le 1er onglet (Source.wav)
  1151. {
  1152. /*
  1153.   midi57 = 110Hz
  1154.   1/110Hz = 9ms -> delta x = 142-46 = 96px
  1155.   echelle x = 96/9 = 10.6 px/ms
  1156.   soit:
  1157.   10ms -> 106px
  1158. */
  1159. double x;
  1160. double nb_grad_max;
  1161. double intervalle; // séparant les graduations
  1162. QPen pen1;
  1163. // int num_x;
  1164. //QString sti;
  1165. // uint decal = 3; // leger decallage vertical pour ne pas masquer la trace
  1166.  
  1167. /*
  1168.   rectangle1 = new QGraphicsRectItem(5, 452, 1900, 200);
  1169.   pen1.setColor("#0073FF");
  1170.   rectangle1->setPen(pen1);
  1171.   calque_reticule1->addToGroup(rectangle1);
  1172.  
  1173.   ligne1 = new QGraphicsLineItem(10, 475, 1900, 475); // ligne horizontale
  1174.   pen1.setColor("#0073FF");
  1175.   ligne1->setPen(pen1);
  1176.   calque_reticule1->addToGroup(ligne1);
  1177. */
  1178. afficher_titre_calque("Partie échantillonée du signal", 0, 452, calque_reticule1);
  1179.  
  1180. // lignes verticales
  1181.  
  1182. intervalle = 106;
  1183. nb_grad_max = 18;
  1184.  
  1185. for (int i=0; i<=nb_grad_max; i++)
  1186. {
  1187. x = intervalle * i;
  1188.  
  1189. ligne1 = new QGraphicsLineItem(x, 452, x, 780);
  1190. ligne1->setPen(pen_reticule);
  1191. }
  1192.  
  1193. /*
  1194. // lignes horizontales
  1195.   intervalle = 55;
  1196.   nb_grad_max = 3;
  1197.   for (i=0; i<=nb_grad_max; i++)
  1198.   {
  1199.   y = 300 - intervalle * i;
  1200.  
  1201.   ligne1 = new QGraphicsLineItem(0, y, 1350, y);
  1202.   ligne1->setPen(pen_reticule);
  1203.   calque_reticule1->addToGroup(ligne1);
  1204.   }
  1205.   texte_mid = new QGraphicsTextItem("Silicium628");
  1206.   texte_mid->setDefaultTextColor(couleur_signature);
  1207.   texte_mid->setPos(5,5);
  1208.   calque_reticule1->addToGroup(texte_mid);
  1209.  */
  1210.  
  1211. scene1->addItem(calque_reticule1);
  1212. }
  1213.  
  1214.  
  1215.  
  1216. void MainWindow::tracer_gradu_temporelle_signal_entree()
  1217. {
  1218. // GRADUATION TEMPORELLE sur le signal d'entrée, en secondes; (scene2 sur onglet 'Source wav')
  1219.  
  1220. QString s1, s2;
  1221. int x=0;
  1222. int dy = 75;
  1223. int nb_s, nb_mn;
  1224. double pas =8;
  1225.  
  1226. for(int n=0; n<2400; n++) // 1200
  1227. {
  1228.  
  1229. if (n%10 == 0) { dy = 75; }
  1230. else if (n%5 == 0) {dy = 20; }
  1231. else {dy = 10;}
  1232.  
  1233. x = n *pas;
  1234. ligne1 = new QGraphicsLineItem(x, -dy, x, dy);
  1235. QPen P1("#AAAAAA");
  1236. ligne1->setPen(P1);
  1237. calque_reticule2->addToGroup(ligne1);
  1238.  
  1239. if (n%10 == 0)
  1240. {
  1241. nb_s = n/10;
  1242. s1.setNum(nb_s);
  1243. s1+="s";
  1244.  
  1245. if (nb_s>60)
  1246. {
  1247. nb_mn = nb_s/60;
  1248. nb_s -= nb_mn * 60;
  1249. s1.setNum(nb_s);
  1250. if (nb_s<10) {s1 = "0" +s1;}
  1251. s2.setNum(nb_mn);
  1252. s1 = s2 + ":" + s1;
  1253. }
  1254. GraphicsTextItem = new QGraphicsTextItem(s1);
  1255. GraphicsTextItem->setDefaultTextColor(couleur_texte);
  1256. GraphicsTextItem->setPos(x,55);
  1257. if(x<20000) {calque_reticule2->addToGroup(GraphicsTextItem); }//6000
  1258. }
  1259. }
  1260. }
  1261.  
  1262.  
  1263.  
  1264. void MainWindow::tracer_signal_complet() // totalité du fichier wav (dans le cadre du bas du 1er onglet)
  1265. {
  1266. uint8_t octet_n=0;
  1267. double R;
  1268.  
  1269. double offset_y = 0.0;
  1270. double echelle_y =doubleSpinBox_gain->value();
  1271. double echelle_x =0.2;
  1272.  
  1273. int x, y, memo_x, memo_y;
  1274. double min= 1000000.0;
  1275. double max=-1000000.0;
  1276.  
  1277. int pas = 10 * pas_echantillonage; // 240;
  1278.  
  1279. //rappel : duree_totale = data_size / 96000;
  1280.  
  1281. // le signal wav est échantillonné à l'origine à 96000 Bps (séréo 2*fois 48000 Bps)
  1282. // en ne prenant qu'un octet sur 24 on obtient 4000 Bps.
  1283. QString s1;
  1284.  
  1285. effacer_calque(scene2, calque_trace_signal2 );
  1286. segment_trace = new QGraphicsLineItem(0, offset_y, 512, offset_y);
  1287. QPen P1("#0000FF");
  1288. segment_trace->setPen(P1); //couleur_ligne
  1289. calque_trace_signal2->addToGroup(segment_trace);
  1290.  
  1291. x=0;
  1292. y=offset_y;
  1293.  
  1294. double n_max=1;
  1295. if (pas !=0) {n_max = data_size / pas;}
  1296.  
  1297. long n;
  1298. long i=0;
  1299. // int j=0;
  1300.  
  1301. for(n=0; n<n_max; n+=10)
  1302. {
  1303. memo_x = x;
  1304. memo_y = y;
  1305. x = echelle_x * n;
  1306. if (i < 2000000)
  1307. {
  1308. octet_n = temp_data[i]; // canal 1}
  1309. }
  1310. R = octet_n - 128; // pour ôter la composante continue propre au codage par des octets non signés
  1311. R *= echelle_y;
  1312. R *= doubleSpinBox_gain->value();
  1313. y=offset_y + R;
  1314.  
  1315. // recherche du mini-maxi:
  1316. if (y < min) {min = y;}
  1317. if (y > max) {max = y;}
  1318.  
  1319. //if (x<3000) //3000
  1320. {
  1321. segment_trace = new QGraphicsLineItem(memo_x ,memo_y, x, y);
  1322. QPen P1("#0055FF");
  1323. segment_trace->setPen(P1);
  1324. calque_trace_signal2->addToGroup(segment_trace);
  1325. }
  1326.  
  1327. i+= pas; // le nb de pas étant pair, on retombe toujours sur le même canal (droite ou gauche)
  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. void MainWindow::encadrement_signal(int x, int dx)
  1339. {
  1340. ligne1 = new QGraphicsLineItem(x, -80, x, 80);
  1341. ligne1->setPen(pen_encadrement);
  1342. calque_encadrement2->addToGroup(ligne1);
  1343.  
  1344. ligne1 = new QGraphicsLineItem(x+dx, -80, x+dx, 80);
  1345. ligne1->setPen(pen_encadrement);
  1346. calque_encadrement2->addToGroup(ligne1);
  1347.  
  1348. ligne1 = new QGraphicsLineItem(x, -80, x+dx, -80);
  1349. ligne1->setPen(pen_encadrement);
  1350. calque_encadrement2->addToGroup(ligne1);
  1351.  
  1352. ligne1 = new QGraphicsLineItem(x, 80, x+dx, 80);
  1353. ligne1->setPen(pen_encadrement);
  1354. calque_encadrement2->addToGroup(ligne1);
  1355. }
  1356.  
  1357.  
  1358.  
  1359. void MainWindow::encadrement_note(int n_midi) // par un rectangle sur l'onglet 'Source wav'
  1360. {
  1361. double x, dx, y, dy;
  1362.  
  1363. x=92 - 13 + ((double)n_midi-40.0) * 40.9;
  1364. dx=35;
  1365. y=16;
  1366. dy=50;
  1367.  
  1368. rectangle1 = new QGraphicsRectItem(x, y, dx, dy);
  1369. rectangle1->setPen(pen_encadrement);
  1370. calque_trace_FFT->addToGroup(rectangle1);
  1371. }
  1372.  
  1373.  
  1374.  
  1375. void MainWindow::tracer_signal_a_convertir() //partie à analyser s=f(t) (signal incident, pas le FFT); dans le cadre du haut
  1376. {
  1377. double offset_y = 575.0;
  1378. double echelle =5.0;
  1379. uint8_t octet_n;
  1380. double R;
  1381. double x, y, memo_x, memo_y;
  1382. double min= 1000000.0;
  1383. double max=-1000000.0;
  1384. QString s1;
  1385.  
  1386. effacer_calque(scene1,calque_trace_signal1 );
  1387. segment_trace = new QGraphicsLineItem(0, offset_y, 512, offset_y);
  1388. segment_trace->setPen(QColor(couleur_ligne));
  1389. calque_trace_signal1->addToGroup(segment_trace);
  1390.  
  1391. long n;
  1392. long i=0;
  1393. x=0;
  1394. y=offset_y;
  1395. int pas = 64;
  1396. for(n=0; n<nb_ech/2; n++)
  1397. {
  1398. memo_x = x;
  1399. memo_y = y;
  1400. x = echelle * n;
  1401.  
  1402. octet_n = temp_data[i]; // canal 1
  1403. R = octet_n - 128; // pour oter la composante continue propre au codage par des octets non signés
  1404. // R /= 10.0;
  1405. y=offset_y + R;
  1406.  
  1407. if (y < min) {min = y;}
  1408. if (y > max) {max = y;}
  1409.  
  1410. if (x<1800)
  1411. {
  1412. segment_trace = new QGraphicsLineItem(memo_x ,memo_y, x, y);
  1413. segment_trace->setPen(pen_trace1);
  1414. calque_trace_signal1->addToGroup(segment_trace);
  1415. }
  1416.  
  1417. i++; // pour sauter le canal B (le signal dans le fichier .wav est stéréo)
  1418. i+= pas;
  1419. }
  1420. //scene1->addItem(calque_trace_signal);
  1421. s1.setNum(min);
  1422. //lineEdit_4->setText(s1);
  1423. s1.setNum(max);
  1424. // lineEdit_5->setText(s1);
  1425. }
  1426.  
  1427.  
  1428.  
  1429.  
  1430. void MainWindow::tracer_segments_FFT() //scene1 sur le 1er onglet (Source wav)
  1431. {
  1432. double offset_x= spinBox_offset->value(); // ref -2146 ; +/- 22 pour un décalage de +/-1/4 de ton
  1433. double echelle_x =doubleSpinBox_echx->value(); // 498
  1434. double offset_y = 350.0;
  1435.  
  1436. uint n;
  1437. double module_FFT;
  1438. double x=0, y=0;
  1439. // double dx;
  1440. double memo_x[5]={0,0,0,0,0};
  1441. double memo_y[5]={0,0,0,0,0};
  1442. double x0, y0; // fréquence centrale trouvée comme résultat (points d'inflexions de la courbe)
  1443.  
  1444. double z=1.6;
  1445. //int x1=0;
  1446. //int x2=0;
  1447. int num_raie=0;
  1448. //bool note_validee = false;
  1449.  
  1450. QPen pen1("#12FF00");
  1451.  
  1452. if(!rapide)
  1453. {
  1454. effacer_calque(scene1,calque_trace_FFT );
  1455. // effacer_calque(scene1,calque_lignes_F_zero );
  1456. }
  1457.  
  1458.  
  1459. y = offset_y;
  1460. ENR_FFT enr_i;
  1461.  
  1462. //qDebug() << "nb_ech" << nb_ech; // 1024
  1463. //x=0.0;
  1464. //dx = 30.0;
  1465. for(n=0; n<nb_ech; n++)
  1466. {
  1467. //note_validee = false;
  1468. memo_x[0] = x;
  1469. memo_y[0] = y;
  1470.  
  1471. //x = 100 + 6.0 * n; // echelle linéaire -> pas top
  1472. x = offset_x + echelle_x * log2((double)(n+1)); // échelle logarithmique afin que les tons soient graphiquement équi-espacés
  1473.  
  1474. // x += dx;
  1475.  
  1476. // ci-dessous 'a' est la partie réelle du complexe, et 'b' la partie imaginaire
  1477. // on calcule le module :
  1478. module_FFT = z * sqrt( tab_X[n].a * tab_X[n].a + tab_X[n].b * tab_X[n].b ); // z * racine(a²+b²)
  1479.  
  1480. y = module_FFT*10.0; // amplitude
  1481. y = offset_y - y; // offset et inversion du sens d'affichage because à l'écran les y croissent de haut en bas
  1482.  
  1483.  
  1484. // décale la pile memo_x
  1485. // puis mise en mémoire (empile) le dernier point
  1486. memo_x[4] = memo_x[3]; memo_y[4] = memo_y[3];
  1487. memo_x[3] = memo_x[2]; memo_y[3] = memo_y[2];
  1488. memo_x[2] = memo_x[1]; memo_y[2] = memo_y[1];
  1489. memo_x[1] = memo_x[0]; memo_y[1] = memo_y[0];
  1490. memo_x[0] = x;
  1491. memo_y[0] = y;
  1492.  
  1493. if((x>20) && (x<1900))
  1494. {
  1495. //y *=1.0;
  1496. if (x > -100)
  1497. {
  1498. if (!rapide)
  1499. {
  1500. segment_trace = new QGraphicsLineItem(memo_x[1], memo_y[1], x, y);
  1501. segment_trace->setPen(pen_trace2);
  1502. calque_trace_FFT->addToGroup(segment_trace);
  1503. }
  1504. }
  1505.  
  1506. // DETECTION DES NOTES primaires
  1507.  
  1508. //----------------------------------------------------------------------------------
  1509. // détection direct des points hauts (points d'inflexion de la courbe)
  1510. // on pourrait calculer la dérivée de la courbe, et détecter les valeurs pour lesquelles elle s'annule
  1511. // problème : peut ne pas détecter si le sommet est un pic (discontinuité)
  1512. //----------------------------------------------------------------------------------
  1513.  
  1514. // Autre méthode :
  1515. // détection de 2 doublets de points de part et d'autre, montants puis descendant
  1516. // le sommet se situe donc entre les 2 doublets
  1517.  
  1518. // la DETECTION s'effectue ICI
  1519.  
  1520. // ATTENTION : la ligne qui suit détermine la stratégie utilisée et son paramétrage influe grandement
  1521. // sur la qualité du résultat.
  1522. // on doit pouvoir l'améliorer mais attention : toujours expérimenter sur des données réelles (air de musique)
  1523. // avant de valider la moindre "amélioration".
  1524.  
  1525. //if ( (memo_y[3] - memo_y[2]) >0.5 && (memo_y[1] - memo_y[2]) >0.5 )
  1526.  
  1527. if ( (memo_y[3] - memo_y[2]) > 1.1 && (memo_y[1] - memo_y[2]) > 1.1 )
  1528. {
  1529. x0 = memo_x[2]; // point d'inflexion probable
  1530. y0 = memo_y[2];
  1531. // x0 = (memo_x[0]+ memo_x[1]+ memo_x[2]+ memo_x[3] + memo_x[4]) / 5.0;
  1532.  
  1533. if( !rapide) // donc pas d'affichage en mode rapide
  1534. {
  1535. ligne1 = new QGraphicsLineItem(x0, 60, x0, 350);
  1536. ligne1->setPen(pen1);
  1537. calque_lignes_F_zero->addToGroup(ligne1);
  1538.  
  1539. // ligne1 = new QGraphicsLineItem(x0+1, 60, x0+1, 350); // pour épaissir le trait
  1540. // ligne1->setPen(pen1);
  1541. // calque_lignes_F_zero->addToGroup(ligne1);
  1542.  
  1543. ligne1 = new QGraphicsLineItem(x0, T_i-1, x0, T_i+1); // T_i : variable GLOBALE
  1544. ligne1->setPen(pen1);
  1545. }
  1546.  
  1547. int m0 = 0;
  1548. m0 = calcul_num_midi(x0);
  1549. enr_i.t = T_i; // T_i : variable GLOBALE
  1550. enr_i.num = num_raie;
  1551. enr_i.midi = m0;
  1552. enr_i.amplitude = y0;
  1553.  
  1554. // tracer sur tableau fréquences
  1555. if(num_raie<10) // 6
  1556. {
  1557. liste_ENR_FFT << enr_i; // memorisation ; donc 5 notes max pour un temps (T_i) donné
  1558. // les notes ayant même T_i seront considérées comme simultanées (accord)
  1559. tracer_1enr(enr_i); // sur le 2eme onglet (NOTES)
  1560. }
  1561.  
  1562. num_raie++;
  1563. }
  1564. }
  1565.  
  1566.  
  1567. //dx /= 1.059463;
  1568.  
  1569. }
  1570. T_i++; // variable GLOBALE
  1571.  
  1572. // T_i est ici incrémenté à chaque appel de la fonction
  1573. // sachant que chaque appel de cette fonction analyse 1024 échantillons du signal.
  1574. // et que chaque échantillon représente une durée = 0.5ms du signal d'origine
  1575. // donc T_i est (virtuellement) incrémenté toutes les 1024*0.5ms = 512ms;
  1576. // pourquoi 'virtuellement' ? parce que chaque échantillon "REPRESENTE" une durée de 0.5 ms
  1577. // mais ne "DURE PAS" 0.5ms; L'analyse s'effectue à très haute vitesse sur un signal pré-échantilloné.
  1578. // de quel chapeau sort ce 0.5ms? Voir la fontion 'void MainWindow::remplir_tableau_echantillons_signal()'
  1579.  
  1580. num_raie=0;
  1581. //affi_notes();
  1582. }
  1583.  
  1584.  
  1585. void MainWindow::tracer_echelle_temps_TAB_NOTES() //en secondes (scene4 sur l'onglet NOTES)
  1586. {
  1587.  
  1588. QString s1;
  1589. double x, x0, dx;
  1590. int offset_x = 80;
  1591. int y0 = 620;
  1592. double nbs;
  1593.  
  1594. //effacer_calque(scene4, calque_echelle_temporelle_T);
  1595.  
  1596. if (visu_ech_tps == true) {y0 = 0;} // grandes lignes
  1597. for(int n=0; n<=120; n++)
  1598. {
  1599. x0 = 10.0 * doubleSpinBox_T0->value();
  1600. dx = 1000.0 * pas_echantillonage/256.0; // = 1000 * 24 /256 = 93.75
  1601.  
  1602. x = x0 + dx * zoom_x * (double)n;
  1603.  
  1604. ligne1 = new QGraphicsLineItem(offset_x + x, y0-5, offset_x + x, 650);
  1605. QPen pen1;
  1606. pen1.setColor("#00FF00"); //
  1607. ligne1->setPen(pen1);
  1608. calque_echelle_temporelle_T->addToGroup(ligne1);
  1609.  
  1610. nbs = (double) n;
  1611. s1.setNum(nbs, 10, 0); // base 10, 0 décimale
  1612. s1 += "s";
  1613.  
  1614. Etiquette(offset_x + x, 630, 0, s1, "#FFFFFF", "#000000", "#00FF00", calque_echelle_temporelle_T); // en bas
  1615. }
  1616. }
  1617.  
  1618.  
  1619.  
  1620. void MainWindow::tracer_1enr(ENR_FFT enr_i) // c.a.d. ayant la durée élémentaire T_i = 256 ms
  1621. {
  1622. // "notes" primaires -> calque 'calque_TAB_FRQ' sur le 2eme onglet (NOTES)
  1623.  
  1624. int T2;
  1625. //uint8_t num_raie;
  1626. uint8_t m0;
  1627. double yH, yL;
  1628. double y0, y2, dy, dy2;
  1629. uint16_t v; // v comme 'vertical'
  1630. double offset_y = 350.0;
  1631. QString couleur1;
  1632.  
  1633. T2 = zoom_x * enr_i.t;
  1634.  
  1635. m0 = enr_i.midi;
  1636. y0 = enr_i.amplitude;
  1637.  
  1638. if (checkBox_flitrer->isChecked() && (m0 != spinBox_filtre->value())) {return;}
  1639.  
  1640. v= 689 - (12 * (m0-28) );
  1641. y2 = -y0 + offset_y;
  1642. dy = y2/30.0; // 40
  1643. //dy = y2/10;
  1644. //dy=dy*dy; // pour un meilleur affichage ; A VOIR !!!!
  1645. //dy /=5.0;
  1646. dy *= gain;
  1647.  
  1648. if (dy > 200) {dy = 200;} // bridage amplitude max
  1649.  
  1650. if(v > 730) {return;}
  1651.  
  1652. if (dy > seuil)
  1653. {
  1654. dy2 = dy;
  1655. if (checkBox_norm->isChecked()) {dy2=5; } // bride la hauteur des tirets
  1656. double x = 80.0 + T2;
  1657. yH = v+dy2/2;
  1658. yL = v-dy2/2;
  1659. // rabotage pour éviter le scrolling de l'affichage:
  1660. if(yH > 730) {yH = 730;}
  1661. if(yL <0) {yH = 0;}
  1662.  
  1663. //ligne1 = new QGraphicsLineItem(x, yL, x, yH);
  1664.  
  1665. rectangle1 = new QGraphicsRectItem(x, v-dy2/2, zoom_x-2, dy2);
  1666. int h1 = calcul_hauteur_note(m0);
  1667.  
  1668. if (checkBox_norm->isChecked()) // utilise une couleur en fonction de l'amplitude du signal
  1669. {
  1670. double dy3 = dy/ 20;
  1671. if (dy3 > 0.8) {dy3 = 0.8;}
  1672. couleur1 = calcul_couleur(dy3);
  1673. }
  1674. else
  1675. {
  1676. // utilise une couleur en fonction de la fréquence ('hauteur') de la note
  1677. couleur1 = liste_couleurs[h1];
  1678. }
  1679.  
  1680. QPen pen1;
  1681. pen1.setColor(couleur1);
  1682.  
  1683. rectangle1->setPen(pen1);
  1684. rectangle1->setBrush(QColor(couleur1));
  1685.  
  1686. QBrush br1;
  1687. br1.setStyle(Qt::SolidPattern);
  1688. br1.setColor(couleur1);
  1689. rectangle1->setBrush(br1);
  1690. calque_TAB_FRQ->addToGroup(rectangle1); // lent !
  1691.  
  1692. graphicsView1->verticalScrollBar()->setValue(0);
  1693. }
  1694. }
  1695.  
  1696.  
  1697. void MainWindow::detection_notes_auto() // notes secondaires (affi par petits cercles colorés)
  1698. {
  1699. ENR_FFT enr_i;
  1700.  
  1701. int T2;
  1702. uint32_t n_max;
  1703. uint8_t m0;
  1704. double A1;
  1705. double x, y, y0, y2;
  1706. // double memo_x = 0;
  1707. double offset_y = 350.0;
  1708. //double decalage;
  1709. QString couleur1;
  1710. QPen pen1;
  1711. pen1.setWidth(1);
  1712.  
  1713. double pas_grille = doubleSpinBox_dxb->value()/2.0 * zoom_x;
  1714. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  1715.  
  1716. n_max = liste_ENR_FFT.size();
  1717.  
  1718. if (n_max == 0) return;
  1719.  
  1720. tableWidget_type_M->setCurrentCell(2, 0);
  1721. on_tableWidget_type_M_cellClicked(2, 0);
  1722.  
  1723. liste_NOTES.clear();
  1724.  
  1725. for(int n=0; n<83; n++)
  1726. {
  1727. table_integration_amplitudes[n] =0; // RAZ
  1728. }
  1729. calque_notes_auto->setPos(0, 0);
  1730.  
  1731. for(uint32_t n=0; n<n_max-1; n++)
  1732. {
  1733. enr_i = liste_ENR_FFT[n];
  1734. T2 = zoom_x * enr_i.t;
  1735.  
  1736. m0 = enr_i.midi;
  1737.  
  1738. y0 = enr_i.amplitude;
  1739. y2 = -y0 + offset_y;
  1740.  
  1741. // y = 700 - (16 * (m0-40) );
  1742. y = 689 - (12 * (m0-28) );
  1743.  
  1744. A1 = y2/10.0; // 40
  1745. A1 *= gain;
  1746.  
  1747. // table_integration_amplitudes[m0] /= 2.0; // usure volontaire
  1748. if(A1<20)
  1749. {
  1750. table_integration_amplitudes[m0] = 0; // ce qui est débloquant
  1751. }
  1752.  
  1753. if (A1 > 20) // 30
  1754. {
  1755. x = 80.0 + T2 -8; // le -8 pour décaler dans le temps (de la durée de l'intégration)
  1756.  
  1757. //intégration temporelle des amplitudes en vue de valider en tant que note
  1758. if(table_integration_amplitudes[m0] >=0) // si pas de blocage en cours
  1759. {
  1760. table_integration_amplitudes[m0] += A1;
  1761. }
  1762.  
  1763. if (table_integration_amplitudes[m0] > 200.0)
  1764. {
  1765. // la NOTE est comfirmée, on va l'ajouter à la fin de la liste des notes
  1766. // Mais il faut aussi empêcher des re-détections multiples lorsque l'amplitute du signal ne décroit
  1767. // que progressivement. Pour cela on attribue la valeur -1 dans la table d'intégration
  1768. // pour le n° midi de la note, ce qui sera bloquant.
  1769. // Le déblocage se produira lorsque l'amplitude du signal concernant cette note
  1770. // sera descendu en dessous d'un certain niveau.
  1771.  
  1772. table_integration_amplitudes[m0] = -1; //ce qui est bloquant (voir 10 lignes +haut)
  1773.  
  1774. int h1 = calcul_hauteur_note(m0); //'hauteur' au sens musical, gamme chromatique
  1775. couleur1 = liste_couleurs[h1];
  1776. pen1.setColor(couleur1);
  1777.  
  1778. // int delta_x = int(x - memo_x);
  1779. // memo_x = x ;
  1780.  
  1781. ellipse1 = new QGraphicsEllipseItem(x-A1/2, y-A1/2, A1, A1);
  1782. ellipse1->setPen(pen1);
  1783. calque_notes_auto->addToGroup(ellipse1); // grands cercles colorés fin
  1784. //on va ajouter la note à la liste des notes
  1785.  
  1786. int n_barre = num_barre(x);
  1787.  
  1788. if (n_barre != -1000) {ajout_note(m0, n_barre, 0);}
  1789.  
  1790. // ellipse1 = new QGraphicsEllipseItem(x, v-1, 2, 2);
  1791. // pen1.setColor("#FFFFFF");
  1792. // ellipse1->setPen(pen1);
  1793. // calque_notes_auto->addToGroup(ellipse1); // point blanc
  1794. }
  1795. }
  1796. // voir la fonction -> 'tracer_1enr(ENR_FFT enr_i)' pour le cadrage
  1797.  
  1798. }
  1799. calque_notes_auto->setPos(offset_x, 0);
  1800. mode='M';
  1801. on_Bt_toggle_grille_T_clicked(); // basculera à T;
  1802. doubleSpinBox_vitesse->setValue(30);
  1803. }
  1804.  
  1805.  
  1806. void MainWindow::retracer_TAB_FRQ()
  1807. {
  1808. ENR_FFT enr_i;
  1809. uint16_t n_max = liste_ENR_FFT.length();
  1810. if (n_max == 0) return;
  1811. //effacer_calque(scene1,calque_trace_FFT );
  1812. tracer_graduation_TAB_NOTES();
  1813.  
  1814. calque_TAB_FRQ->setPos(0, 0);
  1815. for(uint16_t n=0; n<n_max-1; n++)
  1816. {
  1817. enr_i = liste_ENR_FFT[n];
  1818. tracer_1enr(enr_i);
  1819. }
  1820.  
  1821. double pas_grille = doubleSpinBox_dxb->value()/2.0 * zoom_x;
  1822. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  1823. calque_TAB_FRQ->setPos(offset_x, 0);
  1824. }
  1825.  
  1826.  
  1827.  
  1828. void RAZ_tableau_echantillons()
  1829. {
  1830. uint n;
  1831. for(n=0; n < nb_ech; n++)
  1832. {
  1833. ech[n].a = 0; // partie reelle
  1834. ech[n].b = 0; // partie imaginaire
  1835. }
  1836. }
  1837.  
  1838.  
  1839.  
  1840. uint bit_reversal(uint num, uint nb_bits)
  1841. {
  1842. uint r = 0, i, s;
  1843. if ( num > (1<< nb_bits)) { return 0; }
  1844.  
  1845. for (i=0; i<nb_bits; i++)
  1846. {
  1847. s = (num & (1 << i));
  1848. if(s) { r |= (1 << ((nb_bits - 1) - i)); }
  1849. }
  1850. return r;
  1851. }
  1852.  
  1853.  
  1854.  
  1855. void MainWindow::bit_reverse_tableau_X()
  1856. {
  1857. // recopie les échantillons en les classant dans l'ordre 'bit reverse'
  1858. uint n,r;
  1859.  
  1860. for(n=0; n < nb_ech; n++) // nb d'échantillons
  1861. {
  1862. r=bit_reversal(n,nb_etapes);
  1863. tab_X[n] = ech[r];
  1864. }
  1865. }
  1866.  
  1867. void MainWindow::calcul_tableau_W()
  1868. {
  1869. if (tableau_w_plein == true) {return;}
  1870. // calcul et memorisation dans un tableau des twiddle factors (facteurs de rotation)
  1871. uint n;
  1872. double x;
  1873. for(n=0; n<(nb_ech/2-1); n++)
  1874. {
  1875. x=2.0*M_PI * n / nb_ech;
  1876.  
  1877. tab_W[n].a = cos(x); // partie reelle
  1878. tab_W[n].b = -sin(x); // partie imaginaire
  1879. }
  1880. tableau_w_plein = true;
  1881. }
  1882.  
  1883.  
  1884. void MainWindow::calcul_FFT()
  1885. {
  1886. Complexe produit; // voir la classe "Complexe" : complexe.h et complexe.ccp
  1887.  
  1888. uint etape, e1, e2, li, w, ci;
  1889. uint li_max=nb_ech;
  1890. e2=1;
  1891.  
  1892. for (etape=1; etape<=nb_etapes; etape++)
  1893. {
  1894. e1=e2; //(e1 évite d'effectuer des divisions e2/2 plus bas)
  1895. e2=e2+e2; // plus rapide que *=2
  1896.  
  1897. for (li=0; li<li_max; li+=1)
  1898. {
  1899. ci=li & (e2-1); // ET bit à bit
  1900. if (ci>(e1-1))
  1901. {
  1902. w=li_max/e2*(li & (e1 -1)); // ET bit à bit calcul du numéro du facteur de rotation W
  1903. 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"
  1904. tab_X[li]=tab_X[li-e1] - produit; // concerne la ligne basse du croisillon; soustraction complexe; Voir "complexe.cpp"
  1905. tab_X[li-e1]=tab_X[li-e1] + produit; // concerne la ligne haute du croisillon; addition complexe; Voir "complexe.cpp"
  1906. }
  1907. }
  1908. }
  1909. }
  1910.  
  1911.  
  1912. void MainWindow::Tic1() // pour l'analyse de Fourier en vitesse lente
  1913. {
  1914.  
  1915. nb_tics++;
  1916. if(nb_tics > 4000)
  1917. {
  1918. Timer1->stop();
  1919. nb_tics=0;
  1920. }
  1921. else
  1922. {
  1923. spinBox_4->setValue( spinBox_4->value() +1); //voir la fonction 'on_spinBox_4_valueChanged()'
  1924. Timer1->setInterval(2); // à voir
  1925. }
  1926. }
  1927.  
  1928.  
  1929. void MainWindow::trace_time_line()
  1930. {
  1931. double x_note=0, x, dx;
  1932.  
  1933. if (num_note_jouee < 1) {return;}
  1934. if(mode=='T') { x_note = calcul_x_barre(liste_NOTES[num_note_jouee-1].n_barreT); }
  1935. if(mode=='M') { x_note = calcul_x_barre(liste_NOTES[num_note_jouee-1].n_barreM); }
  1936. dx = calcul_pas_grille();
  1937. x = x_note + double(num_barre_en_cours) * dx;
  1938.  
  1939.  
  1940. int midi_i = liste_NOTES[num_note_jouee-1].midi;
  1941. int y = calcul_y_note(midi_i) ;
  1942.  
  1943. int h1 = calcul_hauteur_note(midi_i);
  1944. QString couleur1 = liste_couleurs[h1];
  1945.  
  1946. QPen pen1;
  1947. pen1.setColor(couleur1);
  1948. pen1.setWidth(2);
  1949.  
  1950. //ellipse1 = new QGraphicsEllipseItem(x, y, 2, 2) ;
  1951. //ellipse1->setPen(pen1);
  1952. //ellipse1->setBrush(blanc);
  1953. //calque_notes_jouee->addToGroup(ellipse1);
  1954.  
  1955. rectangle1 = new QGraphicsRectItem(x, y, dx, 2) ;
  1956. rectangle1->setPen(pen1);
  1957. calque_notes_jouee->addToGroup(rectangle1);
  1958. }
  1959.  
  1960.  
  1961.  
  1962.  
  1963. void MainWindow::Tic2()
  1964. {
  1965. int d_barre;
  1966. float dt, vts;
  1967. int itrv;
  1968.  
  1969. vts = doubleSpinBox_vitesse->value();
  1970. d_barre = joue_1_note_de_la_liste(); // nb de barres temporelles séparant la note avec celle qui suit
  1971.  
  1972. dt = 20.0 * d_barre;
  1973. dt *= (200.0 / vts);
  1974. itrv = (int) dt;
  1975.  
  1976. Timer2->setInterval(itrv);
  1977. }
  1978.  
  1979.  
  1980. void MainWindow::Tic3()
  1981. {
  1982. if(spinBox_6->value()>52)
  1983. {
  1984. Timer3->stop();
  1985. return;
  1986. }
  1987.  
  1988. spinBox_6->setValue( spinBox_6->value() +1);
  1989. Timer3->setInterval(5);
  1990. }
  1991.  
  1992.  
  1993.  
  1994. void clear_temp_data()
  1995. {
  1996. for(int i=0; i<2000000; i++)
  1997. {
  1998. temp_data[i]=0;
  1999. }
  2000.  
  2001. }
  2002.  
  2003.  
  2004. void MainWindow::on_Bt_load_wav_clicked()
  2005. {
  2006.  
  2007. open_fichier_wav(); // associe le binStream1 au fichier wav
  2008. decode_entete();
  2009. MainWindow::setCursor(Qt::WaitCursor);
  2010. liste_ENR_FFT.clear();
  2011. effacer_calque(scene1,calque_trace_signal1 );
  2012. effacer_calque(scene1, calque_trace_FFT);
  2013. clear_temp_data();
  2014. garnis_temp_data(0);
  2015. ajustement_gain();
  2016. // donne accès à la totalité (2MB) du fichier wav (dans le 'temp_data')
  2017. tracer_signal_complet();
  2018. MainWindow::setCursor(Qt::ArrowCursor);
  2019. tracer_gradu_temporelle_signal_entree();
  2020. frame_3->setVisible(true);
  2021. Bt_scan_auto->setVisible(true);
  2022. checkBox_rapide->setVisible(true);
  2023. }
  2024.  
  2025.  
  2026.  
  2027. /*
  2028.   char RIFF[4]; (4 bytes)
  2029.   unsigned long ChunkSize; (4 bytes)
  2030.   char WAVE[4]; (4 bytes)
  2031.   char fmt[4]; (4 bytes)
  2032.   unsigned long Subchunk1Size; (4 bytes)
  2033.   unsigned short AudioFormat; (2 octets)
  2034.   unsigned short NumOfChan; (2 octets)
  2035.   unsigned long SamplesPerSec; (4 bytes)
  2036.   unsigned long bytesPerSec; (4 bytes)
  2037.   unsigned short blockAlign; (2 octets)
  2038.   unsigned short bitsPerSample; (2 octets)
  2039.   char Subchunk2ID[4]; (4 bytes)
  2040.   unsigned long Subchunk2Size; (4 bytes)
  2041.  
  2042.   TOTAL 44 octets
  2043. */
  2044.  
  2045.  
  2046. QString separ_milliers(uint n) // séparation des miliers par des espaces
  2047. {
  2048. QString s1, s1a, s1b, s1c;
  2049. s1.setNum(n);
  2050. int L= s1.length(); s1a = s1.right(3); s1b = s1.mid(L-6, 3); s1c = s1.mid(L-9, 3);
  2051. return (s1c+" "+s1b+" "+s1a);
  2052. }
  2053.  
  2054.  
  2055.  
  2056. void MainWindow::save_fichier_ini()
  2057. {
  2058. QFile file1(QDir::currentPath() + "/" + "params_FFT.ini"); // dans le dossier de l'exécutable
  2059. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2060. {
  2061. //int p1= string_currentFile.lastIndexOf('/');
  2062. //string_currentDir = string_currentFile.left(p1);
  2063.  
  2064. QTextStream out(&file1);
  2065.  
  2066. out << "# Ce fichier est crée automatiquement par le programme";
  2067. out << '\n';
  2068. out << "#";
  2069. out << '\n';
  2070. out << "# chemins:";
  2071. out << '\n';
  2072. out << "<currentDir>" << string_currentDir << "</currentDir>";
  2073. out << '\n';
  2074. out << "<currentFile>" << string_currentFile << "</currentFile>";
  2075. }
  2076. file1.close();
  2077. }
  2078.  
  2079.  
  2080.  
  2081. void MainWindow::open_fichier_wav()
  2082. {
  2083. // Le fichier .wav comprend un signal audio stéréo échantilloné à 48 000 octets/seconde pour chaque canal
  2084. // ce qui fait 96000 octets/s pour l'ensemble du signal stéréo
  2085.  
  2086. string_currentFile = QFileDialog::getOpenFileName(this, tr("Ouvrir Fichier wav..."), string_currentDir,
  2087. tr("Fichiers wav (*.wav);;All Files (*)"));
  2088. if (string_currentFile != "")
  2089. {
  2090. save_fichier_ini();
  2091. }
  2092. lineEdit_1->setText(string_currentFile);
  2093.  
  2094. int p1= string_currentFile.lastIndexOf('/');
  2095. string_currentDir = string_currentFile.left(p1);
  2096. lineEdit_current_dir->setText(string_currentDir);
  2097.  
  2098. save_fichier_ini();
  2099.  
  2100. file_wav.setFileName(string_currentFile);
  2101. if (!file_wav.open(QIODevice::ReadOnly))
  2102. {
  2103. wav_ok = false;
  2104. Bt_scan_auto->setStyleSheet("background-color: rgb(200, 200, 200);");
  2105. return ;
  2106. }
  2107. else
  2108. {
  2109. binStream1.setDevice(&file_wav); // accès à la totalité du fichier wav
  2110. wav_ok = true;
  2111. Bt_scan_auto->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  2112.  
  2113. }
  2114. // le fichier reste ouvert pour toute la session
  2115. }
  2116.  
  2117.  
  2118.  
  2119.  
  2120. void MainWindow::decode_entete()
  2121. {
  2122. // ============ [Bloc de déclaration d'un fichier au format WAVE] ============
  2123.  
  2124. if (! wav_ok) {return;}
  2125. QString s3, s4, s5, fileSize1;
  2126. uint8_t x, nb_canaux;
  2127. double tot1, tot2, tot3, tot4;
  2128.  
  2129.  
  2130. binStream1.device()->seek(0); // retour de la lecture au début du fichier
  2131. binStream1.readRawData (temp_entete, 100); // lecture entete du fichier
  2132. //FileTypeBlocID
  2133. x=(uint8_t)temp_entete[0]; if ((x>64) && (x<127)) { s3 = char(x); }
  2134. x=(uint8_t)temp_entete[1]; if ((x>64) && (x<127)) { s3 += char(x); }
  2135. x=(uint8_t)temp_entete[2]; if ((x>64) && (x<127)) { s3 += char(x); }
  2136. x=(uint8_t)temp_entete[3]; if ((x>64) && (x<127)) { s3 += char(x); }
  2137. tableWidget_1->setItem(0, 0, new QTableWidgetItem (s3) ); //FileTypeBlocID
  2138.  
  2139. // FileSize
  2140. x=(uint8_t)temp_entete[4]; s3.setNum(x); tableWidget_1->setItem(1, 0, new QTableWidgetItem (s3) );
  2141. x=(uint8_t)temp_entete[5]; s3.setNum(x); tableWidget_1->setItem(1, 1, new QTableWidgetItem (s3) );
  2142. x=(uint8_t)temp_entete[6]; s3.setNum(x); tableWidget_1->setItem(1, 2, new QTableWidgetItem (s3) );
  2143. x=(uint8_t)temp_entete[7]; s3.setNum(x); tableWidget_1->setItem(1, 3, new QTableWidgetItem (s3) );
  2144.  
  2145. tot1 = temp_entete[4] + (2<<7) * temp_entete[5] + (2<<15) * temp_entete[6] + (2<23)* temp_entete[7];
  2146. fileSize1 = separ_milliers(tot1);
  2147. tableWidget_1->setItem(1, 4, new QTableWidgetItem ("= " + fileSize1) );
  2148.  
  2149. // FileFormatID
  2150. x=(uint8_t)temp_entete[8]; if ((x>64) && (x<127)) { s3 = char(x); }
  2151. x=(uint8_t)temp_entete[9]; if ((x>64) && (x<127)) { s3 += char(x); }
  2152. x=(uint8_t)temp_entete[10]; if ((x>64) && (x<127)) { s3 += char(x); }
  2153. x=(uint8_t)temp_entete[11]; if ((x>64) && (x<127)) { s3 += char(x); }
  2154. tableWidget_1->setItem(2, 0, new QTableWidgetItem (s3) );
  2155.  
  2156. // ============ [Bloc décrivant le format audio] ==============
  2157.  
  2158. // FormatBlocID
  2159. x=(uint8_t)temp_entete[12]; if ((x>64) && (x<127)) { s3 = char(x); }
  2160. x=(uint8_t)temp_entete[13]; if ((x>64) && (x<127)) { s3 += char(x); }
  2161. x=(uint8_t)temp_entete[14]; if ((x>64) && (x<127)) { s3 += char(x); }
  2162. x=(uint8_t)temp_entete[15]; if ((x>64) && (x<127)) { s3 += char(x); }
  2163. tableWidget_1->setItem(3, 0, new QTableWidgetItem (s3) );
  2164.  
  2165. //BlocSize
  2166. x=(uint8_t)temp_entete[16]; s3.setNum(x); tableWidget_1->setItem(4, 0, new QTableWidgetItem (s3) );
  2167. x=(uint8_t)temp_entete[17]; s3.setNum(x); tableWidget_1->setItem(4, 1, new QTableWidgetItem (s3) );
  2168. x=(uint8_t)temp_entete[18]; s3.setNum(x); tableWidget_1->setItem(4, 2, new QTableWidgetItem (s3) );
  2169. x=(uint8_t)temp_entete[19]; s3.setNum(x); tableWidget_1->setItem(4, 3, new QTableWidgetItem (s3) );
  2170.  
  2171. 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];
  2172. tableWidget_1->setItem(4, 4, new QTableWidgetItem ("= " + separ_milliers(tot2)) );
  2173.  
  2174. //AudioFormat
  2175. x=(uint8_t)temp_entete[20]; s3.setNum(x); tableWidget_1->setItem(5, 0, new QTableWidgetItem (s3) );
  2176. x=(uint8_t)temp_entete[21]; s3.setNum(x); tableWidget_1->setItem(5, 1, new QTableWidgetItem (s3) );
  2177.  
  2178. if ((uint8_t)temp_entete[20]==1){tableWidget_1->setItem(5, 4, new QTableWidgetItem ("PCM") );}
  2179.  
  2180. //NbrCanaux
  2181. nb_canaux=(uint8_t)temp_entete[22]; s3.setNum(nb_canaux); tableWidget_1->setItem(6, 0, new QTableWidgetItem (s3) );
  2182. x=(uint8_t)temp_entete[23]; s3.setNum(x); tableWidget_1->setItem(6, 1, new QTableWidgetItem (s3) );
  2183.  
  2184. //Fréquence d'échantillonage en Hz
  2185. x=(uint8_t)temp_entete[24]; s3.setNum(x); tableWidget_1->setItem(7, 0, new QTableWidgetItem (s3) );
  2186. x=(uint8_t)temp_entete[25]; s3.setNum(x); tableWidget_1->setItem(7, 1, new QTableWidgetItem (s3) );
  2187. x=(uint8_t)temp_entete[26]; s3.setNum(x); tableWidget_1->setItem(7, 2, new QTableWidgetItem (s3) );
  2188. x=(uint8_t)temp_entete[27]; s3.setNum(x); tableWidget_1->setItem(7, 3, new QTableWidgetItem (s3) );
  2189.  
  2190. 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];
  2191. tableWidget_1->setItem(7, 4, new QTableWidgetItem ("= " + separ_milliers(tot3)) );
  2192.  
  2193. //BytePerSec
  2194. x=temp_entete[28]; s3.setNum(x); tableWidget_1->setItem(8, 0, new QTableWidgetItem (s3) );
  2195. x=temp_entete[29]; s3.setNum(x); tableWidget_1->setItem(8, 1, new QTableWidgetItem (s3) );
  2196. x=temp_entete[30]; s3.setNum(x); tableWidget_1->setItem(8, 2, new QTableWidgetItem (s3) );
  2197. x=temp_entete[31]; s3.setNum(x); tableWidget_1->setItem(8, 3, new QTableWidgetItem (s3) );
  2198.  
  2199. 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];
  2200. s3.setNum(tot4); // 96000
  2201.  
  2202. tableWidget_1->setItem(8, 4, new QTableWidgetItem (s3));
  2203. //tableWidget_1->setItem(8, 4, new QTableWidgetItem ("= " + separ_milliers(tot4)) );
  2204.  
  2205. //BytePerBloc
  2206. x=(uint8_t)temp_entete[32]; s3.setNum(x); tableWidget_1->setItem(9, 0, new QTableWidgetItem (s3) );
  2207. x=(uint8_t)temp_entete[33]; s3.setNum(x); tableWidget_1->setItem(9, 1, new QTableWidgetItem (s3) );
  2208.  
  2209. //BitsPerSample
  2210. x=(uint8_t)temp_entete[34]; s3.setNum(x); tableWidget_1->setItem(10, 0, new QTableWidgetItem (s3) );
  2211. x=(uint8_t)temp_entete[35]; s3.setNum(x); tableWidget_1->setItem(10, 1, new QTableWidgetItem (s3) );
  2212.  
  2213. x=(uint8_t)temp_entete[36]; if ((x>64) && (x<127)) { s3 = char(x); }
  2214. x=(uint8_t)temp_entete[37]; if ((x>64) && (x<127)) { s3 += char(x); }
  2215. x=(uint8_t)temp_entete[38]; if ((x>64) && (x<127)) { s3 += char(x); }
  2216. x=(uint8_t)temp_entete[39]; if ((x>64) && (x<127)) { s3 += char(x); }
  2217. tableWidget_1->setItem(11, 0, new QTableWidgetItem (s3) );
  2218.  
  2219. // DataSize
  2220. x=(uint8_t)temp_entete[40]; s3.setNum(x); tableWidget_1->setItem(12, 0, new QTableWidgetItem (s3) );
  2221. x=(uint8_t)temp_entete[41]; s3.setNum(x); tableWidget_1->setItem(12, 1, new QTableWidgetItem (s3) );
  2222. x=(uint8_t)temp_entete[42]; s3.setNum(x); tableWidget_1->setItem(12, 2, new QTableWidgetItem (s3) );
  2223. x=(uint8_t)temp_entete[43]; s3.setNum(x); tableWidget_1->setItem(12, 3, new QTableWidgetItem (s3) );
  2224.  
  2225. int tot5a = 1 * (uint8_t) temp_entete[40]; //because le temp_entête de type 'char' code avec entiers signés
  2226. int tot5b = (1<<8) * (uint8_t)temp_entete[41]; // remarque: (1<<8) = 2^8 = 256 // ne pas écrire (2<<8) !!
  2227. int tot5c = (1<<16) * (uint8_t)temp_entete[42];
  2228. int tot5d = (1<<24) * (uint8_t)temp_entete[43];
  2229.  
  2230. data_size = tot5a + tot5b + tot5c + tot5d;
  2231.  
  2232. // 21248 + 458752 = 480000
  2233. // pour le .wav LA 440 (48000, durée 10s) ->14x(2^16) + 166 * (2^8) = 960000
  2234. // 960 000 kb (stéréo) / 96 000 kb/s (stéréo)= 10s
  2235.  
  2236. tableWidget_1->setItem(12, 4, new QTableWidgetItem ("= " + separ_milliers(data_size)) ); // DataSize
  2237.  
  2238. // durée calculée
  2239. duree_totale = data_size / tot4;
  2240. s3.setNum(duree_totale, 'f', 3);// double n, char format = 'g', int precision = 6
  2241. tableWidget_1->setItem(13, 4, new QTableWidgetItem (s3 + " s") );
  2242.  
  2243. s4.setNum(tot4);
  2244. s4 = "ech : " + s3;
  2245. s4 += " Bps / 2 voies (stéréo) = ";
  2246.  
  2247. s5.setNum(tot4/2000);
  2248. s5 +=" kBps";
  2249.  
  2250. tableWidget_1->setItem(8, 5, new QTableWidgetItem (s5) );
  2251. lineEdit_6->setText("File size = " + fileSize1 + " bytes ; " + s4 + s5 + " ; durée calculée = " +s3 + "s");
  2252.  
  2253. if ((nb_canaux == 2) && (tot4 != 96000))
  2254. {
  2255. QMessageBox msgBox;
  2256. QString s1;
  2257. s1 = "Attention: Le taux d'échentillonage n'est pas 48 kb/s";
  2258. msgBox.setText(s1);
  2259. msgBox.exec();
  2260. }
  2261. if (nb_canaux != 2)
  2262. {
  2263. QMessageBox msgBox;
  2264. QString s1;
  2265. s1 = "Attention: Signal mono (doit être STEREO !)";
  2266. msgBox.setText(s1);
  2267. msgBox.exec();
  2268. }
  2269. }
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275. // voir la page : https://fr.wikipedia.org/wiki/Waveform_Audio_File_Format
  2276. void MainWindow::garnis_temp_data(qint32 offset_i)
  2277. {
  2278. if (! wav_ok) {return;}
  2279.  
  2280. binStream1.device()->seek(0); // retour de la lecture au début du fichier
  2281. binStream1.skipRawData(44+offset_i); // saut bien plus loin dans le fichier
  2282. binStream1.readRawData (temp_data, 2000000); //lecture des données audio
  2283.  
  2284. //file_wav.close();
  2285. }
  2286.  
  2287.  
  2288. void MainWindow::calcul_compression()
  2289. {
  2290. double R;
  2291. double R_max=0;
  2292.  
  2293. for(uint n =0; n<nb_ech/4; n++)
  2294. {
  2295. R=ech[n].a;
  2296. if (R>R_max) {R_max=R;}
  2297. }
  2298. }
  2299.  
  2300.  
  2301. void MainWindow::remplir_tableau_echantillons_signal() // lecture du signal à analyser dans le 'temp_data' -> ech[n]
  2302. {
  2303.  
  2304. /*
  2305. Le fichier .wav doit avoir les caractéristiques suivantes :
  2306. - RIFF PCM WAVE fmt
  2307. - stéréo deux voies
  2308. - 96000 octets/s c'est à dire acqui avec 48000 octets/s x 2 voies
  2309. La FTT sera effectuée en 10 passes, sur un nb_ech = 2^10 = 1024 échantillons
  2310. */
  2311.  
  2312. uint n, n_max, i, offset_x;
  2313. double R;
  2314.  
  2315. offset_x = 40; // ou plus, si lecture plus loin dans le temps, à voir
  2316.  
  2317. uint8_t octet_n; // octet_B;
  2318. /*
  2319.   pour un codage 8 bits/sample = 2 * 1 octet/sample (stéréo)
  2320.   [Octet du Sample1 Canal1 ] (octet_A, octet_B)
  2321.   [Octet du Sample1 Canal2 ]
  2322.   ...
  2323. */
  2324. i=0;
  2325. n=0;
  2326. // on ne prend pas en compte tous les échantillons dispo dans le .wav (inutile ici)
  2327. // mais 1 sur 40 (la fréquence de la note la plus aigue (midi94) est = 932Hz)
  2328. // et seul le fondamental est pertinant pour reconnaitre la note, les harmoniques (timbre) sont ignorées
  2329. // il faut donc échantilloner à 932*2 = 1864 Hz au minimum
  2330. // Le fichier .wav d'origine est échantilloné à 48kHz
  2331. // 48000 / 1864 = 25.75
  2332. // On va prendre 1 échantillon sur 24 , ce qui donne un échantillonage à 48000/24 = 2000Hz
  2333. // attention : tout changement de cette valeur (pas = 24) change l'échelle de représentation de la FFT
  2334. // et fout le bocson dans tout le programme !!!
  2335. // chaque échantillon représente donc une durée = 1/2000 seconde = 0.5ms = 500us
  2336. // voir la suite des explications vers la fin de la fonction 'void MainWindow::tracer_segments_FFT()'
  2337.  
  2338. n_max = nb_ech /2; // = 1024/2 = 512
  2339. // 512*0.5ms = 256 ms
  2340.  
  2341. while (n < n_max)
  2342. {
  2343. octet_n = temp_data[offset_x + i]; // canal A
  2344. // i++; // pour sauter (et ignorer) le canal B (le signal dans le fichier .wav est stéréo)
  2345. i+= pas_echantillonage;
  2346.  
  2347. // x= 256 * octet_A + octet_B;
  2348. R = octet_n - 128; // pour oter la composante continue propre au codage par des octets non signés
  2349. R /= 10.0;
  2350. R *= doubleSpinBox_gain->value();
  2351.  
  2352. if (hamming) { R = R * (1- cos (2* M_PI * n / nb_ech/2 ));}
  2353.  
  2354. if (bourrage_de_zeros)
  2355. {
  2356. if (n<=nb_ech/4) // /4 -> signal
  2357. {
  2358. ech[n].a = R; // partie reelle
  2359. ech[n].b = 0; // partie imaginaire
  2360. }
  2361. else // -> Bourage de zéros
  2362. {
  2363. ech[n].a = 0; // partie reelle
  2364. ech[n].b = 0; // partie imaginaire
  2365. }
  2366. }
  2367. else
  2368. {
  2369. ech[n].a = R; // partie reelle
  2370. ech[n].b = 0; // partie imaginaire
  2371. }
  2372.  
  2373. n++; // n atteindra la valeur max = 512 ech représentant une durée totale de 256 ms
  2374. }
  2375.  
  2376. //calcul_compression();
  2377. }
  2378.  
  2379. /*
  2380. void MainWindow::on_toolButton_2_clicked() // recup signal
  2381. {
  2382.   RAZ_tableau_echantillons();
  2383.   remplir_tableau_echantillons_signal();
  2384.   tracer_signal_a_convertir();
  2385. }
  2386. */
  2387.  
  2388. void MainWindow::calcul_ofsset()
  2389. {
  2390. if(!wav_ok) return;
  2391. offset_t = spinBox_1->value() + 10 * spinBox_2->value() + 100 * spinBox_3->value() + 1000 * spinBox_4->value()
  2392. + 10000 * spinBox_5->value() + 100000 * spinBox_6->value();
  2393. QString s1;
  2394. s1 = separ_milliers(offset_t) ;
  2395. lineEdit_3->setText(s1);
  2396. effacer_calque(scene2, calque_encadrement2);
  2397. encadrement_signal(offset_t/1200, 25);
  2398. }
  2399.  
  2400.  
  2401. void MainWindow::traitement_signal() // lance les Transformées de Fourier du signal
  2402. {
  2403. if (! wav_ok) {return;}
  2404.  
  2405. garnis_temp_data(offset_t);
  2406. remplir_tableau_echantillons_signal();
  2407.  
  2408. calcul_tableau_W();
  2409. //RAZ_tableau_echantillons();
  2410.  
  2411. if(!rapide) { tracer_signal_a_convertir();}
  2412. bit_reverse_tableau_X();
  2413.  
  2414. calcul_FFT(); // 1 FFT s'effectue sur 1 cluster de 1024 échantillons.
  2415. //Le résultat représente un spectre élémentaire correspondant au cluster, c.a.d à une durée = 1024 x ms = 512 ms
  2416. // ce résultat est retourné dans le tableau 'Complexe tab_X[2048]'
  2417.  
  2418. //if (radioButton_notes->isChecked()) { tracer_segments_FFT(); }
  2419. //else { tracer_modules_FFT(); }
  2420.  
  2421. tracer_segments_FFT();
  2422. }
  2423.  
  2424.  
  2425.  
  2426. void MainWindow::analyse_tout() // FFT de tous les clusters, c.a.d. sur la totalité du signal
  2427. {
  2428.  
  2429. progressBar_1->setVisible(true);
  2430.  
  2431. QString s1;
  2432. offset_t=0;
  2433. T_i=0; // variable GLOBALE
  2434.  
  2435. uint16_t i_max = data_size / 1024; // = environ 6000
  2436.  
  2437. if (checkBox_debut_seul->isChecked()) {i_max=2000;} // pour gagner du temps lors de la phase de test
  2438.  
  2439.  
  2440. // data_size est affiché par le visualisateur d'entête
  2441. // et aussi dans le LineEdit en bas de l'onglet FFT
  2442. // data_size = de l'ordre de 7MB, ce qui nous donne un i_max d'environ 6900
  2443.  
  2444. effacer_calque(scene4, calque_TAB_FRQ);
  2445. liste_ENR_FFT.clear();
  2446. //clear_temp_data();
  2447. //garnis_temp_data(0);
  2448.  
  2449. // effacer_calque(scene4, calque_gradu_TAB_FRQ);
  2450. // effacer_calque(scene4, calque_notes_manuelles);
  2451. // effacer_calque(scene4, calque_notes_jouee);
  2452. // effacer_calque(scene4, calque_grille_mesures);
  2453. // effacer_calque(scene4, calque_echelle_temporelle_T);
  2454.  
  2455. for(uint16_t i=0 ; i<i_max ; i++) // cette boucle sera donc parcourue environ 6000 fois...
  2456. {
  2457. if ((i % 200) == 0)
  2458. {
  2459. uint16_t pc = 100 * i / i_max;
  2460. pc+=2;
  2461. progressBar_1->setValue(pc);
  2462. // la ligne suivante permet l'affichage de la progression
  2463. QCoreApplication::processEvents(QEventLoop::AllEvents, 1);
  2464. }
  2465. //s1.setNum(i); lineEdit_compteur->setText(s1);
  2466.  
  2467. traitement_signal(); // traitement d'un cluster de 1024 échantillons
  2468. offset_t += 1024; // on passera au cluster de 1024 échantillons suivant c.a.d à un temps + 0.5ms
  2469.  
  2470. }
  2471. progressBar_1->setVisible(false);
  2472.  
  2473. tracer_echelle_temps_TAB_NOTES();
  2474. }
  2475.  
  2476.  
  2477.  
  2478.  
  2479. void MainWindow::on_spinBox_1_valueChanged(int arg1)
  2480. {
  2481. if (arg1==10) { spinBox_1->setValue(0); spinBox_2->stepUp();}
  2482. calcul_ofsset();
  2483. traitement_signal();
  2484. }
  2485.  
  2486.  
  2487. void MainWindow::on_spinBox_2_valueChanged(int arg1)
  2488. {
  2489. if (arg1==-1) {spinBox_2->setValue(9); spinBox_3->stepDown();}
  2490. if (arg1==10) { spinBox_2->setValue(0); spinBox_3->stepUp();}
  2491. calcul_ofsset();
  2492. traitement_signal();
  2493. }
  2494.  
  2495.  
  2496. void MainWindow::on_spinBox_3_valueChanged(int arg1)
  2497. {
  2498. if (arg1==-1) {spinBox_3->setValue(9); spinBox_4->stepDown();}
  2499. if (arg1==10) { spinBox_3->setValue(0); spinBox_4->stepUp();}
  2500. calcul_ofsset();
  2501. traitement_signal();
  2502. }
  2503.  
  2504.  
  2505. void MainWindow::on_spinBox_4_valueChanged(int arg1)
  2506. {
  2507. if (arg1==-1) {spinBox_4->setValue(9); spinBox_5->stepDown();}
  2508. if (arg1==10) { spinBox_4->setValue(0); spinBox_5->stepUp();}
  2509. calcul_ofsset();
  2510. traitement_signal();
  2511. }
  2512.  
  2513.  
  2514. void MainWindow::on_spinBox_5_valueChanged(int arg1)
  2515. {
  2516. if (arg1==-1) {spinBox_5->setValue(9); spinBox_6->stepDown();}
  2517. if (arg1==10) { spinBox_5->setValue(0); spinBox_6->stepUp();}
  2518. calcul_ofsset();
  2519. traitement_signal();
  2520. }
  2521.  
  2522.  
  2523. void MainWindow::on_spinBox_6_valueChanged()
  2524. {
  2525. //if (arg1==-1) {spinBox_6->setValue(9);} //spinBox_6->stepDown();}
  2526. calcul_ofsset();
  2527. traitement_signal();
  2528. }
  2529.  
  2530.  
  2531. void MainWindow::on_doubleSpinBox_1_valueChanged()
  2532. {
  2533. calcul_ofsset();
  2534. traitement_signal();
  2535. }
  2536.  
  2537.  
  2538. void MainWindow::on_pushButton_8_clicked()
  2539. {
  2540. QMessageBox msgBox;
  2541. QString s1;
  2542. s1 = "Le fichier audio à analyser doit être au format unsigned 8 bits PCM";
  2543. s1 += " (généré par exemple avec Audacity)";
  2544. s1 += "\n";
  2545. s1 += "Attention: ce n'est pas le format PCM par défaut, il faut aller dans les sous-menus :";
  2546. s1 += "\n";
  2547. s1 += "Fichier/Exporter/Exporter en WAV / encodage : Unsigned 8-bit PCM";
  2548. s1 += "\n";
  2549. s1 += "Ce n'est pas 'top WiFi', mais largement suffisant pour en faire la FFT et retrouver les notes.";
  2550. s1 += "\n";
  2551. s1 += "Ce qui est le but ici.";
  2552. s1 += "\n";
  2553. s1 += "D'autre part il est vivement conseillé de compresser la dynamique de l'audio (ce qui est simple avec Audacity)";
  2554. s1 += "\n";
  2555. s1 += "ce qui facilite grandement la détection des notes.";
  2556.  
  2557. msgBox.setText(s1);
  2558. msgBox.exec();
  2559. }
  2560.  
  2561.  
  2562. void MainWindow::on_Bt_RAZ_clicked()
  2563. {
  2564. spinBox_1->setValue(0);
  2565. spinBox_2->setValue(0);
  2566. spinBox_3->setValue(0);
  2567. spinBox_4->setValue(0);
  2568. spinBox_5->setValue(0);
  2569. spinBox_6->setValue(0);
  2570. offset_t=0;
  2571. num_barre_en_cours=0;
  2572.  
  2573. effacer_calque(scene1,calque_trace_FFT );
  2574. effacer_calque(scene1,calque_lignes_F_zero );
  2575. }
  2576.  
  2577.  
  2578. void MainWindow::on_spinBox_7_valueChanged(int arg1)
  2579. {
  2580. // ligne verticale
  2581. effacer_calque(scene1,calque_curseur);
  2582. int x = arg1;
  2583. ligne1 = new QGraphicsLineItem(x, 10, x, 500);
  2584. ligne1->setPen(pen_curseur);
  2585. calque_curseur->addToGroup(ligne1);
  2586.  
  2587. }
  2588.  
  2589.  
  2590.  
  2591.  
  2592. void MainWindow::on_pushButton_2_clicked()
  2593. {
  2594. Timer1->stop();
  2595. nb_tics=0;
  2596. }
  2597.  
  2598.  
  2599. void MainWindow::on_Btn_52_clicked()
  2600. {
  2601. //spinBox_n_midi->setValue(52);
  2602.  
  2603. file_wav.setFileName(nom_fichier_in);
  2604. if (!file_wav.open(QIODevice::ReadOnly))
  2605. {
  2606. wav_ok = false;
  2607. return ;
  2608. }
  2609.  
  2610. wav_ok = true;
  2611.  
  2612. on_Bt_RAZ_clicked();
  2613.  
  2614. binStream1.setDevice(&file_wav);
  2615. calcul_ofsset();
  2616. traitement_signal();
  2617. }
  2618.  
  2619.  
  2620. void MainWindow::on_Btn_94_clicked()
  2621. {
  2622.  
  2623. file_wav.setFileName(nom_fichier_in);
  2624. if (!file_wav.open(QIODevice::ReadOnly))
  2625. {
  2626. wav_ok = false;
  2627. return ;
  2628. }
  2629.  
  2630. wav_ok = true;
  2631.  
  2632. on_Bt_RAZ_clicked();
  2633.  
  2634. binStream1.setDevice(&file_wav);
  2635. calcul_ofsset();
  2636. traitement_signal();
  2637. }
  2638.  
  2639.  
  2640. void MainWindow::on_Bt_efface_clicked()
  2641. {
  2642. QMessageBox msgBox;
  2643. msgBox.setText("Erase Frequences");
  2644. msgBox.setInformativeText("Effacer toutes les FFT ?");
  2645. msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
  2646. msgBox.setDefaultButton(QMessageBox::Cancel);
  2647. int ret = msgBox.exec();
  2648.  
  2649. if (ret == QMessageBox::Ok )
  2650. {
  2651. effacer_calque(scene1,calque_trace_signal1 );
  2652. effacer_calque(scene1,calque_trace_FFT );
  2653. effacer_calque(scene1,calque_lignes_F_zero );
  2654. effacer_calque(scene1,calque_encadrement1 );
  2655. effacer_calque(scene2,calque_encadrement2 );
  2656.  
  2657. effacer_calque(scene4,calque_TAB_FRQ );
  2658. on_Bt_RAZ_clicked();
  2659. T_i=0; // T_i : variable GLOBALE
  2660. }
  2661.  
  2662. }
  2663.  
  2664.  
  2665.  
  2666. void MainWindow::on_pushButton_3_clicked()
  2667. {
  2668.  
  2669. tableWidget_1->setVisible(true);
  2670. Bt_close_entete->setVisible(true);
  2671. }
  2672.  
  2673.  
  2674. void MainWindow::on_Bt_close_entete_clicked()
  2675. {
  2676. tableWidget_1->setVisible(false);
  2677. Bt_close_entete->setVisible(false);
  2678. }
  2679.  
  2680. /*
  2681. void MainWindow::on_Bt_close_frame1_clicked()
  2682. {
  2683.   frame_1->setVisible(false);
  2684.   frame_3->setVisible(true);
  2685. }
  2686.  
  2687.  
  2688. void MainWindow::on_Bt_composition_clicked()
  2689. {
  2690.   frame_3->setVisible(false);
  2691.   frame_1->setVisible(true);
  2692. }
  2693. */
  2694.  
  2695.  
  2696. void MainWindow::on_pushButton_6_clicked()
  2697. {
  2698. frame_notes->setVisible(false);
  2699. }
  2700.  
  2701.  
  2702.  
  2703.  
  2704. int MainWindow::save_fichier_FRQ(QString date_i)
  2705. {
  2706. // enregisterment incrémentiel sur le disque (nom de fichier = 1..2...3...)
  2707. ENR_FFT enr_i;
  2708. QString s1;
  2709.  
  2710. uint8_t x0a = spinBox_x0a->value();
  2711. double x0b = doubleSpinBox_x0b->value();
  2712.  
  2713. //uint8_t dxa = spinBox_dxa->value();
  2714. double dxb = doubleSpinBox_dxb->value();
  2715.  
  2716. long n_max = liste_ENR_FFT.length();
  2717. if (n_max == 0)
  2718. {
  2719. QMessageBox msgBox; msgBox.setText("liste FRQ vide !"); msgBox.exec();
  2720. return 1;
  2721. }
  2722. //int numero=0;
  2723. QString s2 = date_i;
  2724. Timer1->stop();
  2725.  
  2726. QFile file1(string_currentDir + "/" + s2 + ".FRQ");
  2727. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2728. {
  2729. QByteArray byteArray1;
  2730. QDataStream stream1(&byteArray1, QIODevice::WriteOnly);
  2731. stream1.setDevice(&file1);
  2732. stream1.setVersion(QDataStream::Qt_6_8);
  2733.  
  2734. // entête 64 octets------------------
  2735. double vts = doubleSpinBox_vitesse->value(); // 8 octets
  2736. stream1 << x0b << dxb << vts << Ta << Tb << x0a; //8+8+8+1+1+1+1 =27 octets au début du fichier
  2737.  
  2738. for (int i=0; i<(64-27); i++) {stream1 << 'x';} // complète à 64 octet
  2739. // ----------------------------------
  2740.  
  2741. for(int n=0; n<n_max; n++)
  2742. {
  2743. enr_i = liste_ENR_FFT[n];
  2744. stream1 << enr_i.amplitude << enr_i.midi << enr_i.num << enr_i.t; // sérialisation des data
  2745. }
  2746. }
  2747. file1.close();
  2748.  
  2749. return 0;
  2750.  
  2751. }
  2752.  
  2753.  
  2754. void MainWindow::choix_dossier_de_travail()
  2755. {
  2756.  
  2757. QString actuel = string_currentDir;
  2758.  
  2759. if (string_currentDir == "") { string_currentDir = QDir::homePath(); }
  2760.  
  2761. qDebug() << "string_currentDir" << string_currentDir;
  2762.  
  2763.  
  2764. string_currentDir = QFileDialog::getExistingDirectory
  2765. (this, tr("Open Directory"), actuel, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  2766.  
  2767. if (string_currentDir != "")
  2768. {
  2769. dossier_de_travail_ok = true;
  2770. save_fichier_ini();
  2771. lineEdit_current_dir->setText(string_currentDir);
  2772. }
  2773. else // -> si on clique sur le bouton 'cancel'
  2774. {
  2775. string_currentDir = QDir::homePath();
  2776. //dossier_de_travail_ok = false;
  2777. }
  2778.  
  2779. }
  2780.  
  2781.  
  2782. void MainWindow::on_Bt_choix_current_dir_clicked()
  2783. {
  2784. lecture_en_cours = false;
  2785. Timer2->stop();
  2786. Bt_jouer_tout->setText(">");
  2787.  
  2788. choix_dossier_de_travail();
  2789. }
  2790.  
  2791.  
  2792. void MainWindow::ajustement_gain()
  2793. {
  2794. double somme;
  2795. double moyenne=0;
  2796. double R;
  2797. double gain=0.3;
  2798. uint8_t octet_n;
  2799. long i, j;
  2800. double pas = 10.0 * pas_echantillonage; // 240
  2801. double n_max=1;
  2802. if (pas !=0)
  2803. {
  2804. n_max = 2000000 / pas;
  2805. }
  2806. i=0;
  2807. j=0;
  2808. somme =0;
  2809. for(long n=0; n<n_max; n++)
  2810. {
  2811.  
  2812. octet_n = temp_data[i]; // canal 1
  2813. if (octet_n !=0)
  2814. {
  2815. R = octet_n - 128;// pour ôter la composante continue (octets non signés)
  2816. if (R<0) {R= -R;}
  2817. somme += R;
  2818. j++; // nb de notes effectivement prises en compte
  2819. }
  2820. i+= pas;
  2821. }
  2822. if (j !=0) { moyenne = somme / j;}
  2823. if (moyenne !=0) { gain = 20.0/moyenne;}
  2824. doubleSpinBox_gain->setValue(gain);
  2825. }
  2826.  
  2827.  
  2828. void MainWindow::load_fichier_FRQ()
  2829. {
  2830. QString filename1;
  2831. QString s1;
  2832.  
  2833. MainWindow::setCursor(Qt::WaitCursor);
  2834.  
  2835. if(dossier_de_travail_ok == false)
  2836. {
  2837. choix_dossier_de_travail();
  2838. if (dossier_de_travail_ok == false)
  2839. {
  2840. QMessageBox msgBox;
  2841. s1="Le dossier de travail n'est pas spécifié";
  2842. msgBox.setText(s1); msgBox.exec();
  2843. MainWindow::setCursor(Qt::ArrowCursor);
  2844. return ;
  2845. }
  2846. }
  2847.  
  2848. filename1 = QFileDialog::getOpenFileName(this,
  2849. tr("Ouvrir Fichier FRQ"), string_currentDir + "/", tr("Fichiers FRQ (*.FRQ)"));
  2850.  
  2851.  
  2852. lineEdit_fichier_FREQ->setText(filename1);
  2853.  
  2854. file_dat.setFileName(filename1);
  2855. if (!file_dat.open(QIODevice::ReadOnly))
  2856. {
  2857. data_nts_ok = false;
  2858. MainWindow::setCursor(Qt::ArrowCursor);
  2859. return ;
  2860. }
  2861. else
  2862. {
  2863. binStream1.setDevice(&file_dat); // accès à la totalité du fichier dat
  2864. binStream1.setVersion(QDataStream::Qt_6_8);
  2865. data_nts_ok = true;
  2866. liste_ENR_FFT.clear();
  2867. }
  2868.  
  2869. //int z = sizeof(ENR_FFT); // ATTENTION ! ne PAS utiliser cette valeur qui tient en compte l'alignement en RAM
  2870. long n_max = file_dat.bytesAvailable() / 14; // 14 bits par enr; voir la def de 'ENR_FFT' dans le .h
  2871.  
  2872. uint8_t x0a;
  2873. double x0b;
  2874. uint8_t dxa;
  2875. double dxb;
  2876.  
  2877. double vts;
  2878.  
  2879. // lecture entête -----------------
  2880.  
  2881. binStream1 >> x0b >> dxb >> vts >> Ta >> Tb >> x0a >> dxa; // 8+8+8+1+1+1+1=28 octets au début du fichiers
  2882.  
  2883. uint8_t xx;
  2884. for (int i=0; i<(64-28); i++) {binStream1 >> xx;} // lit en tout à 64 octets
  2885. //---------------------------------
  2886.  
  2887. spinBox_x0a->setValue(x0a);
  2888. doubleSpinBox_x0b->setValue(x0b);
  2889. // spinBox_dxa->setValue(dxa);
  2890. doubleSpinBox_dxb->setValue(dxb);
  2891. doubleSpinBox_vitesse->setValue(vts);
  2892.  
  2893. //---------------------------------
  2894.  
  2895. ENR_FFT enr_i;
  2896. for(int n=0; n<n_max; n++)
  2897. {
  2898. binStream1 >> enr_i.amplitude >> enr_i.midi >> enr_i.num >> enr_i.t;
  2899. liste_ENR_FFT << enr_i;
  2900. }
  2901. file_dat.close();
  2902.  
  2903. retracer_TAB_FRQ();
  2904. MainWindow::setCursor(Qt::ArrowCursor);
  2905. }
  2906.  
  2907.  
  2908. int MainWindow::save_fichier_NOTES(QString date_i)
  2909. {
  2910. // enregisterment incrémentiel sur le disque (nom de fichier = 1..2...3...)
  2911. NOTE note_i;
  2912. // QString s1;
  2913.  
  2914. uint8_t x0a = spinBox_x0a->value();
  2915. double x0b = doubleSpinBox_x0b->value();
  2916.  
  2917. //uint8_t dxa = spinBox_dxa->value();
  2918. double dxb = doubleSpinBox_dxb->value();
  2919.  
  2920. uint16_t n_max = liste_NOTES.length();
  2921. if (n_max == 0)
  2922. {
  2923. QMessageBox msgBox; msgBox.setText("liste NOTES vide !"); msgBox.exec();
  2924. return 1;
  2925. }
  2926.  
  2927. if (date_i == "BAK")
  2928. {
  2929. QMessageBox msgBox;
  2930. QString s1="Fichier BAK.NTS enregistré";
  2931. msgBox.setText(s1); msgBox.exec();
  2932. }
  2933.  
  2934.  
  2935. //int numero=0;
  2936. QString s2;
  2937.  
  2938. Timer1->stop();
  2939.  
  2940. s2 = date_i;
  2941.  
  2942. //QFile file1(string_currentDir + "/" + "NOTES_" + s2 + ".nts");
  2943. QFile file1(string_currentDir + "/" + s2 + ".NTS");
  2944. if (file1.open(QIODevice::WriteOnly | QIODevice::Text))
  2945. {
  2946. QByteArray byteArray1;
  2947. QDataStream stream1(&byteArray1, QIODevice::WriteOnly);
  2948. stream1.setDevice(&file1);
  2949. stream1.setVersion(QDataStream::Qt_6_8);
  2950.  
  2951. // entête 64 octets --------------
  2952. double vts = doubleSpinBox_vitesse->value(); // 8 octets
  2953. stream1 << x0b << dxb << vts << Ta << Tb << x0a; //8+8+8+1+1+1 =27 octets au début du fichier
  2954.  
  2955. for (int i=0; i<(64-27); i++) {stream1 << 'x';} // complète à 64 octets
  2956. //--------------------------------
  2957. for(uint16_t n=0; n<n_max; n++)
  2958. {
  2959. note_i = liste_NOTES[n];
  2960. // sérialisation des data
  2961. stream1 << note_i.numero << note_i.midi << note_i.n_barreT << note_i.n_barreM;
  2962. }
  2963. }
  2964. file1.close();
  2965.  
  2966. return 0;
  2967. }
  2968.  
  2969.  
  2970.  
  2971. void MainWindow::load_fichier_NOTES(QString s0)
  2972. {
  2973. QString filename1;
  2974. QString s1;
  2975.  
  2976. MainWindow::setCursor(Qt::WaitCursor);
  2977.  
  2978. if (s0 == "BAK")
  2979. {
  2980. filename1 = string_currentDir+ "/BAK.NTS";
  2981. }
  2982. else
  2983. {
  2984. if(dossier_de_travail_ok == false)
  2985. {
  2986. choix_dossier_de_travail();
  2987. if (dossier_de_travail_ok == false)
  2988. {
  2989. QMessageBox msgBox;
  2990. s1="Le dossier de travail n'est pas spécifié";
  2991. msgBox.setText(s1); msgBox.exec();
  2992. MainWindow::setCursor(Qt::ArrowCursor);
  2993. return ;
  2994. }
  2995. }
  2996. filename1 = QFileDialog::getOpenFileName(this,
  2997. tr("Ouvrir Fichier NTS"), string_currentDir+"/", tr("Fichiers nts (*.NTS)"));
  2998. }
  2999.  
  3000. lineEdit_fichier->setText(filename1);
  3001. file_dat.setFileName(filename1);
  3002. if (!file_dat.open(QIODevice::ReadOnly))
  3003. {
  3004. data_nts_ok = false;
  3005. MainWindow::setCursor(Qt::ArrowCursor);
  3006. return ;
  3007. }
  3008. else
  3009. {
  3010. binStream1.setDevice(&file_dat); // accès à la totalité du fichier dat
  3011. binStream1.setVersion(QDataStream::Qt_6_8);
  3012. data_nts_ok = true;
  3013. }
  3014.  
  3015. //int z = sizeof(NOTE); // ATTENTION ! ne PAS utiliser cette valeur qui tient en compte l'alignement en RAM
  3016. uint16_t n_max = file_dat.bytesAvailable() / 7; // 7 bits par enr; voir la def de 'NOTE' dans le .h
  3017.  
  3018. uint8_t x0a;
  3019. double x0b;
  3020. uint8_t dxa;
  3021. double dxb;
  3022. double vts;
  3023.  
  3024. // lecture entête -----------------
  3025. binStream1 >> x0b >> dxb >> vts >> Ta >> Tb >> x0a >> dxa; // 8+8+8+1+1+1+1=28 octets au début du fichiers
  3026.  
  3027. uint8_t xx;
  3028. for (int i=0; i<(64-28); i++) {binStream1 >> xx;} // lit en tout à 64 octets
  3029. //---------------------------------
  3030. spinBox_x0a->setValue(x0a);
  3031. doubleSpinBox_x0b->setValue(x0b);
  3032. //spinBox_dxa->setValue(dxa);
  3033. doubleSpinBox_dxb->setValue(dxb);
  3034. doubleSpinBox_vitesse->setValue(vts);
  3035.  
  3036. switch (Ta)
  3037. {
  3038. case 2: {lineEdit_10->setText("2/4"); Ta=2; Tb=4;} break; // Ta et Tb variables globales
  3039. case 3: {lineEdit_10->setText("3/4"); Ta=3; Tb=4;} break;
  3040. case 4: {lineEdit_10->setText("4/4"); Ta=4; Tb=4;} break;
  3041. default: break;
  3042. }
  3043.  
  3044. for(int n=0; n<n_max; n++)
  3045. {
  3046. NOTE note_i;
  3047. binStream1 >> note_i.numero >> note_i.midi >> note_i.n_barreT >> note_i.n_barreM;
  3048. note_i.statut = 0; // n'est pas sauvegardé ni relu
  3049. liste_NOTES << note_i;
  3050. }
  3051.  
  3052.  
  3053. file_dat.close();
  3054. mode = 'M';
  3055.  
  3056. affiche_liste_notes();
  3057. //on_Bt_toggle_grille_T_clicked();
  3058. Bt_jouer_tout->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  3059.  
  3060. MainWindow::setCursor(Qt::ArrowCursor);
  3061. }
  3062.  
  3063.  
  3064. void decalle_notes(int d)
  3065. {
  3066. int nb;
  3067. uint16_t i_max = liste_NOTES.length();
  3068. for( int i =0; i<i_max; i++)
  3069. {
  3070. nb = liste_NOTES[i].n_barreT;
  3071. nb += d;
  3072. liste_NOTES[i].n_barreT = nb;
  3073. }
  3074. }
  3075.  
  3076.  
  3077. void MainWindow::on_Bt_load_FREQ_clicked()
  3078. {
  3079. load_fichier_FRQ();
  3080. on_Bt_toggle_grille_T_clicked();
  3081. // effacer_calque(scene4, );
  3082. effacer_calque(scene5, calque_histogramme );
  3083. // tracer_echelle_temps_TAB_NOTES();
  3084. }
  3085.  
  3086.  
  3087. void MainWindow::on_checkBox_rapide_stateChanged(int arg1)
  3088. {
  3089. rapide=arg1;
  3090. init_TAB_FRQ();
  3091. }
  3092.  
  3093.  
  3094. void MainWindow::on_doubleSpinBox_seuil_valueChanged(double arg1)
  3095. {
  3096. seuil = arg1;
  3097. effacer_calque(scene4, calque_TAB_FRQ);
  3098. retracer_TAB_FRQ();
  3099. }
  3100.  
  3101.  
  3102. void MainWindow::on_checkBox_norm_clicked()
  3103. {
  3104. /*
  3105.   if (checkBox_norm->isChecked())
  3106.   {
  3107.   textEdit_ETAT->setText("Mode Normalisé : \n Les couleurs représentent l'amplitude du signal");
  3108.   }
  3109.   else
  3110.   {
  3111.   textEdit_ETAT->setText(
  3112. "Mode Fréquences : \n"
  3113.  "Les couleurs représentent la valeur (fréquence) de la note (Do, RE, MI...) \n"
  3114.  "La taille de chaque tiret représente (abusivement sur l'axe fréquenciel) l'amplitude du signal \n"
  3115.  "cette taille ne signifie donc pas un étalement en fréquence du signal, c'est juste une astuce de représentation."
  3116.   );
  3117.   }
  3118. */
  3119. effacer_calque(scene4, calque_TAB_FRQ);
  3120. retracer_TAB_FRQ();
  3121. }
  3122.  
  3123.  
  3124. /*
  3125. void MainWindow::surbrille_barre(num_barre)
  3126. {
  3127.  
  3128. }
  3129. */
  3130.  
  3131. void MainWindow::surbrille_note(uint16_t n, bool HRM, int type) // HRM = visu harmoniques
  3132. {
  3133. // HRM true -> visu harmoniques x2 et x3
  3134. double x_note=0;
  3135. QPen pen1;
  3136. //QString couleur1;
  3137. QString blanc = "#FFFFFF";
  3138.  
  3139. NOTE note_i;
  3140. uint16_t n_max = liste_NOTES.length();
  3141. if ( n>= n_max) {return;}
  3142.  
  3143. note_i = liste_NOTES[n];
  3144. if(mode=='T') { x_note = calcul_x_barre(note_i.n_barreT); }
  3145. if(mode=='M') { x_note = calcul_x_barre(note_i.n_barreM); }
  3146.  
  3147. if (checkBox_scrolling->isChecked())
  3148. {
  3149. //int n =0;
  3150. double diff1 =0;
  3151.  
  3152. double xb = graphicsView4->horizontalScrollBar()->value();
  3153. diff1= x_note - xb;
  3154.  
  3155. if(diff1 >1700)
  3156. {
  3157. on_Bt_next_clicked();
  3158. on_Bt_next_clicked();
  3159. }
  3160. }
  3161.  
  3162. int y1, y2, y3; // y1=F0; y2 = 2xF0; y3 = 3xF0
  3163. int h1;
  3164. int midi_i;
  3165.  
  3166. midi_i = note_i.midi;
  3167. y1 = calcul_y_note(midi_i);
  3168. y2 = calcul_y_note(midi_i+12);
  3169. y3 = calcul_y_note(midi_i+17);
  3170.  
  3171. if(type == 1)
  3172. {
  3173. pen1.setColor(blanc);
  3174. pen1.setWidth(1);
  3175. ellipse1 = new QGraphicsEllipseItem(x_note-12, y1-12, 24, 24) ; // cercle
  3176. ellipse1->setPen(pen1);
  3177. calque_notes_jouee->addToGroup(ellipse1);
  3178. }
  3179.  
  3180. if(type == 2)
  3181. {
  3182. pen1.setColor(blanc);
  3183. pen1.setWidth(1);
  3184. rectangle1 = new QGraphicsRectItem(x_note-15, y1-15, 30, 30) ; // carré
  3185. rectangle1->setPen(pen1);
  3186. calque_notes_jouee->addToGroup(rectangle1);
  3187. }
  3188.  
  3189.  
  3190. if (HRM== true)
  3191. {
  3192. // visu harmoniques x2 et x3
  3193.  
  3194. if (y2 > 4) // afin d'éviter d'afficher trop haut ce qui décalerait tout l'affichage
  3195. {
  3196. h1 = calcul_hauteur_note(midi_i+12);
  3197. pen1.setColor(liste_couleurs[h1]);
  3198. rectangle1= new QGraphicsRectItem(x_note-20, y2-1, 40, 2) ;
  3199. rectangle1->setPen(pen1);
  3200. calque_notes_jouee->addToGroup(rectangle1);
  3201. }
  3202.  
  3203. if (y3 > 4) // afin d'éviter d'afficher trop haut ce qui décalerait tout l'affichage
  3204. {
  3205. h1 = calcul_hauteur_note(midi_i+17);
  3206. pen1.setColor(liste_couleurs[h1]);
  3207. rectangle1= new QGraphicsRectItem(x_note-20, y3-1, 40, 2) ;
  3208. rectangle1->setPen(pen1);
  3209. calque_notes_jouee->addToGroup(rectangle1);
  3210. }
  3211. }
  3212.  
  3213. }
  3214.  
  3215.  
  3216. void MainWindow::surbrille_barre(int n_barre, QString couleur) // par un trait vertical
  3217. {
  3218. QPen pen1;
  3219. pen1.setColor(couleur);
  3220. pen1.setWidth(2);
  3221.  
  3222. int x= calcul_x_barre(n_barre);
  3223.  
  3224. ligne1 = new QGraphicsLineItem(x, 200, x, 500);
  3225. ligne1->setPen(pen1);
  3226. effacer_calque(scene4, calque_surbrillance);
  3227. calque_surbrillance->addToGroup(ligne1);
  3228. }
  3229.  
  3230.  
  3231. void MainWindow::encadre_groupe_notes(int n_barre_i, int nombre)
  3232. {
  3233. NOTE note_i;
  3234. int midi_i;
  3235. double y_i, y_min, y_max;
  3236.  
  3237. int x1 = calcul_x_barre(n_barre_i);
  3238. int x2 = calcul_x_barre(n_barre_i + nombre);
  3239.  
  3240. int n_max = liste_NOTES.length();
  3241. y_min = 1000;
  3242. y_max = -1;
  3243.  
  3244. for(int n_i=0; n_i<nombre; n_i++)
  3245. {
  3246. for(int n=0; n<n_max; n++)
  3247. {
  3248. note_i = liste_NOTES[n];
  3249. midi_i = note_i.midi;
  3250. if(note_i.n_barreM == n_barre_i+n_i)
  3251. {
  3252. y_i = calcul_y_note(midi_i);
  3253. if (y_i > y_max) {y_max=y_i;}
  3254. if (y_i < y_min) {y_min=y_i;}
  3255. }
  3256. }
  3257. }
  3258.  
  3259. QPen pen1;
  3260. pen1.setColor("#00FFFF");
  3261. pen1.setWidth(1);
  3262.  
  3263. rectangle1= new QGraphicsRectItem(x1-15, y_min-15, x2-x1 +30, y_max-y_min+30) ;
  3264. rectangle1->setPen(pen1);
  3265. calque_surbrillance->addToGroup(rectangle1);
  3266.  
  3267.  
  3268. }
  3269.  
  3270.  
  3271.  
  3272. void MainWindow::complete_case(int row, int column, QString s1, QString c1, QString c2, bool bold1, QTableWidget *QTI)
  3273. {
  3274. QTableWidgetItem *Item1 = new QTableWidgetItem();
  3275. Item1->QTableWidgetItem::setForeground(QColor(c1));
  3276. Item1->QTableWidgetItem::setBackground(QColor(c2));
  3277.  
  3278. QFont font1;
  3279. font1.setBold(bold1);
  3280. Item1->setFont(font1);
  3281. Item1->setTextAlignment(Qt::AlignCenter);
  3282.  
  3283. Item1->setText(s1);
  3284. QTI->setItem(row, column, Item1);
  3285. }
  3286.  
  3287.  
  3288. void MainWindow::affiche_liste_notes() // en TEXTE dans le petit tableau
  3289. {
  3290. NOTE note_i;
  3291. QString s1;
  3292.  
  3293. QString blanc = "#FFFFFF";
  3294. QString jaune = "#FFFF00";
  3295. QString cyan = "#00FFFF";
  3296.  
  3297. tableWidget_lst_notes->clear();
  3298. tableWidget_lst_notes->setRowCount(0);
  3299. init_TAB_lst_notes();
  3300.  
  3301. uint16_t n_max = liste_NOTES.length();
  3302. if (n_max == 0) {return;}
  3303.  
  3304. int memo_n_barreM =0;
  3305. for(int n=0; n<n_max; n++) //n_max
  3306. {
  3307. note_i=liste_NOTES[n];
  3308.  
  3309. int numero = note_i.numero;
  3310. int midi = note_i.midi;
  3311. int n_barreT = note_i.n_barreT;
  3312. int n_barreM = note_i.n_barreM;
  3313. int duree = n_barreM - memo_n_barreM;
  3314. memo_n_barreM = n_barreM;
  3315. int num_ligne = tableWidget_lst_notes->rowCount();
  3316. tableWidget_lst_notes->setRowCount(num_ligne+1); // ajout une ligne au tableau
  3317.  
  3318. s1.setNum(numero);
  3319.  
  3320. complete_case(n, 0, s1, "000000", "#FFFFFF", false, tableWidget_lst_notes);
  3321.  
  3322. s1.setNum(midi);
  3323. int h1 = calcul_hauteur_note(midi);
  3324.  
  3325. QString couleur1 = liste_couleurs[h1];
  3326. complete_case(n, 1, s1, "#000000", couleur1, true, tableWidget_lst_notes);
  3327.  
  3328. s1 = nom_note(midi);
  3329. complete_case(n, 2, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  3330.  
  3331. s1.setNum(n_barreT);
  3332. complete_case(n, 3, s1, jaune, "#555555", true, tableWidget_lst_notes);
  3333.  
  3334. s1.setNum(n_barreM);
  3335. complete_case(n, 4, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  3336.  
  3337. s1.setNum(duree);
  3338. complete_case(n, 5, s1, "#000000", "#FFFFFF", false, tableWidget_lst_notes);
  3339. }
  3340. //tableWidget_lst_notes->AdjustToContents;
  3341. affiche_histogramme();
  3342. }
  3343.  
  3344.  
  3345. void MainWindow::affiche_histogramme_durees()
  3346. {
  3347. int x;
  3348. double dy;
  3349. double echelle;
  3350. QBrush br1;
  3351. QString couleur1;
  3352. QString s1;
  3353.  
  3354. effacer_calque(scene5, calque_histogramme);
  3355.  
  3356. GraphicsTextItem = new QGraphicsTextItem("Histogramme des durées \n en nb de barres 1/40s");
  3357. GraphicsTextItem->setFont(QFont("Arial", 12));
  3358. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3359. GraphicsTextItem->setPos(100, -160);
  3360. calque_histogramme->addToGroup(GraphicsTextItem);
  3361.  
  3362. //calcul de la valeur la plus grande
  3363. int total=0;
  3364. for(int n=0; n<=20; n++) // attention à ne pas dépasser la taille de la table...
  3365. {
  3366. dy = table_histogramme_durees[n];
  3367. if (dy > total ) {total = dy;}
  3368. }
  3369. //calcul échelle y
  3370. if (total == 0) {total = 1;}
  3371. echelle = 150.0 / total;
  3372.  
  3373. for(int n=0; n<=30; n++) // attention à ne pas dépasser la taille de la table...
  3374. {
  3375. x = 10*n;
  3376. dy = echelle * table_histogramme_durees[n];
  3377. dy = -dy;
  3378. rect1 = new QGraphicsRectItem(x, 0, 2, dy);
  3379.  
  3380. couleur1="#AAFFFF";
  3381. br1.setStyle(Qt::SolidPattern);
  3382. br1.setColor(QColor(couleur1));
  3383.  
  3384. rect1->setPen(QColor(couleur1));
  3385. rect1->setBrush(br1);
  3386. calque_histogramme->addToGroup(rect1);
  3387.  
  3388. if (n%2 == 0)
  3389. {
  3390. x = -5 + 20*n;
  3391. s1.setNum(n);
  3392. GraphicsTextItem = new QGraphicsTextItem(s1);
  3393. GraphicsTextItem->setFont(QFont("Arial", 10));
  3394. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3395. GraphicsTextItem->setPos(x, 0);
  3396. calque_histogramme->addToGroup(GraphicsTextItem);
  3397. }
  3398. }
  3399. }
  3400.  
  3401.  
  3402.  
  3403. void MainWindow::calcul_histogramme_durees()
  3404. {
  3405. uint16_t n_max = liste_NOTES.length();
  3406. if (n_max == 0) {return;}
  3407.  
  3408. for(int i=0; i<35; i++) { table_histogramme_durees[i]=0; } // RAZ
  3409.  
  3410. for(int n=1; n<n_max; n++) // attention: =1 et pas =0 because 'liste_NOTES[n-1]' ci-dessous !
  3411. {
  3412. int duree = liste_NOTES[n].n_barreT - liste_NOTES[n-1].n_barreT;
  3413. table_histogramme_durees[duree]++;
  3414. }
  3415. }
  3416.  
  3417.  
  3418. void MainWindow::affiche_histogramme_midi()
  3419. {
  3420. int x;
  3421. double dy;
  3422. double echelle;
  3423. QBrush br1;
  3424. QString couleur1;
  3425. QString s1;
  3426.  
  3427. effacer_calque(scene5, calque_histogramme);
  3428.  
  3429. GraphicsTextItem = new QGraphicsTextItem("Histogramme des notes midi");
  3430. GraphicsTextItem->setFont(QFont("Arial", 12));
  3431. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3432. GraphicsTextItem->setPos(100, -160);
  3433. calque_histogramme->addToGroup(GraphicsTextItem);
  3434.  
  3435. //calcul de la valeur la plus grande
  3436. int total=0;
  3437. for(int n=0; n<_Hmax; n++) // 42, attention à ne pas dépasser la taille de la table...
  3438. {
  3439. dy = table_histogramme_midi[n];
  3440. if (dy > total ) {total = dy;}
  3441. }
  3442. //calcul échelle y
  3443. if (total == 0) {total = 1;}
  3444. echelle = 150.0 / total;
  3445.  
  3446. for(int n=0; n<=40; n++) // 42 attention à ne pas dépasser la taille de la table...
  3447. {
  3448. x = 10*n;
  3449. dy = echelle * table_histogramme_midi[n];
  3450. dy = -dy;
  3451. rect1 = new QGraphicsRectItem(x, 0, 5, dy);
  3452.  
  3453. couleur1="#AAFFFF";
  3454. int h1 = calcul_hauteur_note(n+40);
  3455. QString couleur1 = liste_couleurs[h1];
  3456. br1.setStyle(Qt::SolidPattern);
  3457. br1.setColor(QColor(couleur1));
  3458.  
  3459. rect1->setPen(QColor(couleur1));
  3460. rect1->setBrush(br1);
  3461. calque_histogramme->addToGroup(rect1);
  3462.  
  3463. if (n%2== 0)
  3464. {
  3465. x = -5 + 10*n;
  3466. s1.setNum(n+40);
  3467. GraphicsTextItem = new QGraphicsTextItem(s1);
  3468. GraphicsTextItem->setFont(QFont("Arial", 10));
  3469. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3470. GraphicsTextItem->setPos(x, 0);
  3471. calque_histogramme->addToGroup(GraphicsTextItem);
  3472. }
  3473. }
  3474.  
  3475. }
  3476.  
  3477.  
  3478. void MainWindow::calcul_histogramme_midi()
  3479. {
  3480. for(int i=0; i<42; i++)
  3481. {
  3482. table_histogramme_midi[i]=0; // RAZ
  3483. }
  3484.  
  3485. uint16_t n_max = liste_NOTES.length();
  3486.  
  3487. for(int n=0; n<n_max; n++)
  3488. {
  3489. int M=liste_NOTES[n].midi;
  3490. if ((M>=40)&&(M<=82)) { table_histogramme_midi[M-40]++;}
  3491. }
  3492. }
  3493.  
  3494. /*
  3495. Liste des correspondances en fonction des dièses présents à la clef :
  3496. Pas d'altération : Do Majeur
  3497.  Fa# : Sol Majeur
  3498.  Fa#, Do# -> gamme de Ré Majeur
  3499.  Fa#, Do#, Sol# -> gamme de La Majeur
  3500.  Fa#, Do#, Sol#, Ré# -> gamme de Mi Majeur
  3501.  Fa#, Do#, Sol#, Ré#, La# -> gamme de Si Majeur
  3502.  Fa#, Do#, Sol#, Ré#, La#, Mi# -> gamme de Fa dièse Majeur
  3503.  Fa#, Do#, Sol#, Ré#, La#, Mi#, Si# -> gamme de Do dièse Majeur
  3504. */
  3505.  
  3506.  
  3507. QString MainWindow::denombre_diezes_a_la_cle()
  3508. {
  3509. // FA♯ DO♯ SOL♯ RÉ♯ LA♯ MI♯ SI♯
  3510. // 42 49 56 51 46 53 48 // midi
  3511. // 6 1 8 3 10 5 0 (reportées dans la première octave)
  3512.  
  3513. QString s1, s2;
  3514. int N;
  3515. int FA=0, DO=0, SOL=0, RE=0, LA=0; //, MI=0, SI=0;
  3516. s1="";
  3517. if (table_histogramme_degre[6] > 0) {FA=1; s1+=" FA#";}
  3518. if ((table_histogramme_degre[1] > 0)&&(FA==1)) {DO=1; s1+= " DO#";}
  3519. if ((table_histogramme_degre[8] > 0)&&(DO==1)) {SOL=1; s1+= " SOL#";}
  3520. if ((table_histogramme_degre[3] > 0)&&(SOL==1)) {RE=1; s1+= " RE#";}
  3521. if ((table_histogramme_degre[10] > 0)&&(RE==1)) {LA=1; s1+= " LA#";}
  3522. if ((table_histogramme_degre[5] > 0)&&(LA==1)) {s1+= " MI#";}
  3523. // if ((table_histogramme_degre[0] > 0)&&(MI==1)) {SI=1; s1+= " SI#";}
  3524.  
  3525. N = FA+DO+SOL+RE+LA;
  3526. s2.setNum(N);
  3527. s2+=" dièse";
  3528. if (N>1) {s2+="s";}
  3529. s2+=" à la clé " ;
  3530. s2 += s1;
  3531. return s2;
  3532. }
  3533.  
  3534.  
  3535. void MainWindow::affiche_histogramme_degre()
  3536. {
  3537.  
  3538. int y1, y2;
  3539. double dx;
  3540. double echelle;
  3541. QBrush br1;
  3542. QString couleur1;
  3543. QString s1;
  3544.  
  3545. effacer_calque(scene5, calque_histogramme);
  3546.  
  3547. GraphicsTextItem = new QGraphicsTextItem("Histogramme des degrés (gamme chromatique)");
  3548. GraphicsTextItem->setFont(QFont("Arial", 10));
  3549. GraphicsTextItem->setDefaultTextColor("#FFFFFF");
  3550. GraphicsTextItem->setPos(8, -170);
  3551. calque_histogramme->addToGroup(GraphicsTextItem);
  3552.  
  3553. //calcul de la valeur la plus grande
  3554. int total=0;
  3555. for(int n=0; n<12; n++) // attention à ne pas dépasser la taille de la table...
  3556. {
  3557. dx = table_histogramme_degre[n];
  3558. if (dx > total ) {total = dx;}
  3559. }
  3560. //calcul échelle y
  3561. if (total == 0) {total = 1;}
  3562. echelle = 150.0 / total;
  3563.  
  3564. for(int n=0; n<12; n++)
  3565. {
  3566. y1 = 20 - 10*n;
  3567. dx = echelle * table_histogramme_degre[n];
  3568. if (dx>0)
  3569. {
  3570. rect1 = new QGraphicsRectItem(40, y1, dx, 4);
  3571.  
  3572. couleur1="#AAFFFF";
  3573. int h1 = n;
  3574. QString couleur1 = liste_couleurs[h1];
  3575. br1.setStyle(Qt::SolidPattern);
  3576. br1.setColor(QColor(couleur1));
  3577.  
  3578. rect1->setPen(QColor(couleur1));
  3579. rect1->setBrush(br1);
  3580. calque_histogramme->addToGroup(rect1);
  3581. }
  3582.  
  3583. y2 = 12 - 10*n;
  3584. //s1.setNum(n+1);
  3585. s1=gamme_chromatique[n];
  3586. GraphicsTextItem = new QGraphicsTextItem(s1);
  3587. GraphicsTextItem->setFont(QFont("Arial", 8));
  3588. GraphicsTextItem->setDefaultTextColor(couleur1);
  3589. GraphicsTextItem->setPos(0, y2);
  3590. calque_histogramme->addToGroup(GraphicsTextItem);
  3591.  
  3592. }
  3593.  
  3594. s1 = denombre_diezes_a_la_cle();
  3595. Etiquette(10, -140, 0, s1, "#FFFF00", "#000000", "#FFFFFF", calque_histogramme );
  3596.  
  3597.  
  3598. }
  3599.  
  3600.  
  3601.  
  3602. void MainWindow::calcul_histogramme_degre() // degres de la gamme chromatique (= 1..12 )
  3603. {
  3604. for(int n=0; n<12; n++)
  3605. {
  3606. table_histogramme_degre[n]=0; // RAZ
  3607. }
  3608.  
  3609. uint16_t n_max = liste_NOTES.length();
  3610.  
  3611. for(int n=0; n<n_max; n++)
  3612. {
  3613. int M=liste_NOTES[n].midi;
  3614. if ((M>=40)&&(M<=82))
  3615. {
  3616. //int midi = M-40;
  3617. int H = calcul_hauteur_note(M);
  3618. table_histogramme_degre[H]++;
  3619. }
  3620. }
  3621. }
  3622.  
  3623.  
  3624. void MainWindow::affiche_histogramme()
  3625. {
  3626.  
  3627.  
  3628. //la suite fait planter !
  3629.  
  3630. if(radioButton_D->isChecked())
  3631. {
  3632. calcul_histogramme_durees();
  3633. affiche_histogramme_durees();
  3634. }
  3635. if(radioButton_M->isChecked())
  3636. {
  3637. calcul_histogramme_midi();
  3638. affiche_histogramme_midi();
  3639. }
  3640. if(radioButton_H->isChecked())
  3641. {
  3642. calcul_histogramme_degre();
  3643. affiche_histogramme_degre();
  3644. }
  3645. }
  3646.  
  3647. void MainWindow::trace_liste_notes() //dessine des cercles colorés (couleur midi) sur la grille
  3648. {
  3649. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  3650. numerotation_liste_notes();
  3651.  
  3652. effacer_calque(scene4,calque_notes_manuelles);
  3653. effacer_calque(scene4,calque_notes_jouee);
  3654.  
  3655. QString s1;
  3656. int midi_i;
  3657. double x, dx, y;
  3658. double x_suivante;
  3659. int numero;
  3660. uint16_t n_max = liste_NOTES.length();
  3661. int n_barre_1, n_barre_suivante=0;
  3662. int x0a = spinBox_x0a->value();
  3663. double x0b = 10.0 * doubleSpinBox_x0b->value();
  3664. x0b += 20.0 * x0a;
  3665. QString blanc = "#FFFFFF";
  3666. QString jaune = "#FFFF00";
  3667. // QString cyan = "#00FFFF";
  3668.  
  3669. for(int n=0; n<n_max; n++)
  3670. {
  3671. n_barre_1=0;
  3672. if (mode=='T') {n_barre_1 = liste_NOTES[n].n_barreT; }
  3673. if (mode=='M')
  3674. {
  3675. n_barre_1 = liste_NOTES[n].n_barreM;
  3676. if (n < n_max-1) { n_barre_suivante = liste_NOTES[n+1].n_barreM;}
  3677. else {n_barre_suivante = num_barre_saisie;}
  3678. }
  3679. //memo_x = x;
  3680. x = calcul_x_barre(n_barre_1);
  3681. x_suivante = calcul_x_barre(n_barre_suivante);
  3682. dx = x_suivante -x;
  3683. midi_i = liste_NOTES[n].midi;
  3684.  
  3685. if ((midi_i >=28) && (midi_i <=83) )
  3686. {
  3687. y = calcul_y_note(midi_i);
  3688. int h1 = calcul_hauteur_note(midi_i);
  3689. QString couleur1 = liste_couleurs[h1];
  3690. ellipse1 = new QGraphicsEllipseItem(x-8, y-8, 16, 16); // cercle
  3691. if (mode=='T') {ellipse1->setPen(QColor(jaune));}
  3692. if (mode=='M') {ellipse1->setPen(QColor(blanc));}
  3693. ellipse1->setBrush(QColor(couleur1));
  3694. calque_notes_manuelles->addToGroup(ellipse1);
  3695.  
  3696. // marque la durée des notes par un fin rectangle horizontal
  3697. if ( (mode_composition = true) && (mode == 'M') && (visu_freq == 0) && (n<n_max-1) )
  3698. {
  3699. rectangle1 = new QGraphicsRectItem(x, y-2, dx, 4);
  3700. rectangle1->setPen(QColor(couleur1));
  3701. calque_notes_manuelles->addToGroup(rectangle1);
  3702. }
  3703.  
  3704. // inscrit le numéro de la note au centre de la note
  3705. numero = liste_NOTES[n].numero;
  3706. s1.setNum(numero);
  3707. GraphicsTextItem = new QGraphicsTextItem(s1);
  3708. GraphicsTextItem->setFont(QFont("Arial", 8));
  3709. GraphicsTextItem->setDefaultTextColor("#000000");
  3710. int x2 = x-12; if(numero<10){x2+=4;}
  3711. GraphicsTextItem->setPos(x2, y-10);
  3712. calque_notes_manuelles->addToGroup(GraphicsTextItem);
  3713. }
  3714. if( liste_NOTES[n].statut & 0b00000001 == 0b00000001) {surbrille_note(n, false, 2);}
  3715. }
  3716. tracer_echelle_temps_TAB_NOTES();
  3717. }
  3718.  
  3719.  
  3720. void MainWindow::numerotation_liste_notes()
  3721. {
  3722. uint16_t i_max = liste_NOTES.length();
  3723.  
  3724. for(uint16_t n=0; n<i_max; n++)
  3725. {
  3726. liste_NOTES[n].numero = n;
  3727. }
  3728. }
  3729.  
  3730.  
  3731. void MainWindow::suppression_notes_invalides()
  3732. {
  3733. int midi;
  3734. int nb = 0;
  3735. uint16_t n_max = liste_NOTES.length();
  3736. if (n_max == 0) {return;}
  3737. bool boucler=true;
  3738. do
  3739. {
  3740. nb=0;
  3741. for(uint16_t n=0; n<n_max; n++)
  3742. {
  3743. midi = liste_NOTES[n].midi;
  3744. if ((midi <40) || (midi>82))
  3745. {
  3746. supprime_note(n);
  3747. if (n_max == 0) {return;}
  3748. n_max --;
  3749. nb++;
  3750. }
  3751. }
  3752. if (nb==0) {boucler=false;}
  3753. }
  3754. while (boucler == true);
  3755. }
  3756.  
  3757.  
  3758. void MainWindow::suppression_mesures()
  3759. {
  3760. //int midi;
  3761. uint16_t n_max = liste_NOTES.length();
  3762. int nb = 0;
  3763.  
  3764. bool boucler=true;
  3765. do
  3766. {
  3767. nb=0;
  3768. for(int n=0; n<n_max; n++)
  3769. {
  3770. //midi = liste_NOTES[n].midi;
  3771. /*
  3772.   if (midi == 100) // midi=100 codera pour les barres de mesures
  3773.   {
  3774.   supprime_note(n);
  3775.   n_max --;
  3776.   nb++;
  3777.   }
  3778. */
  3779. }
  3780. if (nb==0) {boucler=false;}
  3781. }
  3782. while (boucler == true);
  3783.  
  3784. }
  3785.  
  3786.  
  3787.  
  3788. void MainWindow::tri_liste_notes_par_num_barre()
  3789. {
  3790.  
  3791. // tri par bulles
  3792.  
  3793. int ba1=0, ba2=0; // barres
  3794. NOTE note_i;
  3795. uint16_t i_max = liste_NOTES.length();
  3796. if (i_max==0){return;}
  3797.  
  3798. for(int p=0; p<i_max; p++)
  3799. {
  3800. for(int n=0; n<i_max-1; n++)
  3801. {
  3802. if(mode=='T')
  3803. {
  3804. ba1=liste_NOTES[n].n_barreT;
  3805. ba2=liste_NOTES[n+1].n_barreT;
  3806. }
  3807. if(mode=='M')
  3808. {
  3809. ba1=liste_NOTES[n].n_barreM;
  3810. ba2=liste_NOTES[n+1].n_barreM;
  3811. }
  3812.  
  3813. if(ba1 > ba2)
  3814. {
  3815. //permutter les notes
  3816. note_i = liste_NOTES[n];
  3817. liste_NOTES[n] = liste_NOTES[n+1];
  3818. liste_NOTES[n+1] = note_i;
  3819. }
  3820. }
  3821. }
  3822. }
  3823.  
  3824.  
  3825.  
  3826. void MainWindow::ajout_note(int midi, int n_barreT, int n_barreM)
  3827. {
  3828. // ajout d'une note à la fin de la liste 'liste_NOTES[]'
  3829. NOTE note_i;
  3830. note_i.midi = midi;
  3831. note_i.n_barreT = n_barreT; // valeur discrète, entière : numéro de la barre de la grille temporelle
  3832. note_i.n_barreM = n_barreM;
  3833. liste_NOTES << note_i;
  3834. tri_liste_notes_par_num_barre();
  3835. }
  3836.  
  3837.  
  3838. void MainWindow::deplace_note(int num, int DG, int HB)
  3839. {
  3840. //if (n<=0) {return;}
  3841. if (num >= liste_NOTES.length()) {return;}
  3842. NOTE note_i;
  3843. note_i = liste_NOTES[num];
  3844. if (mode == 'T')
  3845. {
  3846. note_i.n_barreT = note_i.n_barreT+DG;
  3847. note_i.midi = note_i.midi+HB;
  3848. }
  3849. if (mode == 'M')
  3850. {
  3851. note_i.n_barreM = note_i.n_barreM+DG;
  3852. note_i.midi = note_i.midi+HB;
  3853. }
  3854. liste_NOTES[num] = note_i;
  3855. surbrille_note(num, true, 1);
  3856. }
  3857.  
  3858.  
  3859. void MainWindow::duplique_notes(int n_barreM_1, int n_barreM_2, int nombre)
  3860. {
  3861. NOTE note_i;
  3862. int midi_i;
  3863. int n_max = liste_NOTES.length();
  3864.  
  3865. for (int n_i = 0; n_i < nombre; n_i ++)
  3866. {
  3867. for(int n=0; n<n_max; n++)
  3868. {
  3869. note_i = liste_NOTES[n];
  3870. midi_i = note_i.midi;
  3871. if(note_i.n_barreM == n_barreM_1+n_i)
  3872. {
  3873. ajout_note(midi_i, 0, n_barreM_2+n_i);
  3874. }
  3875. }
  3876.  
  3877. }
  3878. }
  3879.  
  3880.  
  3881. void MainWindow::supprime_note(int16_t n)
  3882. {
  3883. int n_max = liste_NOTES.length();
  3884. if ( (n>=0) && (n<n_max) )
  3885. {
  3886. liste_NOTES.remove(n);
  3887. effacer_calque(scene4, calque_notes_manuelles);
  3888. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  3889. numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  3890. trace_liste_notes();
  3891. }
  3892. }
  3893.  
  3894.  
  3895.  
  3896. int MainWindow::test_if_note_in_liste(int16_t n_barre, int midi)
  3897. {
  3898. // retourne la position dans la liste, sinon zéro;
  3899. int16_t barre_i=0; // accepte nb négatifs
  3900. int midi_i;
  3901. int i_max = liste_NOTES.length();
  3902. for(int n=0; n<i_max; n++)
  3903. {
  3904. if(mode=='T') {barre_i = liste_NOTES[n].n_barreT;}
  3905. if(mode=='M') {barre_i = liste_NOTES[n].n_barreM;}
  3906.  
  3907. midi_i = liste_NOTES[n].midi;
  3908.  
  3909. // int diff_n = abs(barre_i-n_barre);
  3910. //if ((diff_n ==0) && (midi_i == midi))
  3911.  
  3912. if ((barre_i == n_barre) && (midi_i == midi))
  3913. {
  3914. return n;
  3915. }
  3916. }
  3917. return -1000;
  3918. }
  3919.  
  3920.  
  3921. uint16_t MainWindow::calcul_n_barreM_note(uint16_t n)
  3922. //numero de la barre M la plus proche de la note posée sur une barre T
  3923. {
  3924. uint16_t nT = liste_NOTES[n].n_barreT;
  3925.  
  3926. //qDebug() << "nT" << nT;
  3927.  
  3928. mode='T';
  3929. int xT = calcul_x_barre(nT);
  3930.  
  3931. //qDebug() << "xT" << xT;
  3932.  
  3933. int trouve = 0;
  3934. int16_t i =-250;
  3935.  
  3936. mode='M';
  3937.  
  3938. // int x0a = spinBox_x0a->value();
  3939. // double x0b = 10.0 * doubleSpinBox_x0b->value();
  3940. // x0b += 20.0 * x0a;
  3941.  
  3942. while ((trouve == 0) && (i<600))
  3943. {
  3944. double xi = calcul_x_barre(i);
  3945. double diff = xT - xi;
  3946. if(diff<0)diff = -diff;
  3947.  
  3948. if(diff < calcul_pas_grille() /2 )
  3949. {
  3950. trouve = 1;
  3951. }
  3952. i++;
  3953. }
  3954. if (trouve == 0) {i=1;}
  3955. mode='T';
  3956. return i-1;
  3957. }
  3958.  
  3959.  
  3960. uint16_t MainWindow::calcul_n_barreT_note(uint16_t n)
  3961. {
  3962. //numero de la barre T la plus proche de la note posée sur une barre M
  3963. //toutefois cette fonction est à revoir, HS telle-quelle !
  3964.  
  3965. int16_t nM = liste_NOTES[n].n_barreM;
  3966. mode='M';
  3967. int xM = calcul_x_barre(nM);
  3968.  
  3969.  
  3970. int trouve = 0;
  3971. int16_t i = -500;
  3972. //spinBox_x0a->setValue(0);
  3973.  
  3974. mode='T';
  3975. double pas_T = calcul_pas_grille();
  3976. while ((trouve == 0) && (i<2000))
  3977. {
  3978. double xi = calcul_x_barre(i);
  3979. if (xi>0)
  3980. {
  3981. double diff = xM - xi;
  3982. if(diff<0)
  3983. {
  3984. diff = -diff;
  3985. }
  3986. if(diff < (pas_T /1.5) )
  3987. {
  3988. trouve = 1;
  3989. }
  3990. }
  3991. i++;
  3992. }
  3993. if (trouve == 0) {i=1;}
  3994. mode='M';
  3995. return i-1;
  3996. }
  3997.  
  3998.  
  3999.  
  4000. void MainWindow::affi_txt_en_couleur(int midi_i, QLineEdit *lineEdit_i)
  4001. {
  4002. int h1 = calcul_hauteur_note(midi_i);
  4003.  
  4004. QString c1 = liste_couleurs[h1];
  4005. QString c2 = "#000000";
  4006. lineEdit_i->setStyleSheet("color: " + c1 + "; background-color: " + c2 + "; font: 700 14pt 'Ubuntu';");
  4007. }
  4008.  
  4009.  
  4010.  
  4011. void MainWindow::encadre_midi(int n_midi) // sur l'onglet 'NOTES' dans la liste des notes à gauche
  4012. {
  4013. //n_midi = 82; /// pour test (ok)
  4014.  
  4015. if ((n_midi<28) || (n_midi>82)) {return;}
  4016.  
  4017. effacer_calque(scene3, calque_gradu_TAB_FRQ);
  4018. tracer_graduation_TAB_NOTES();
  4019. double x, dx, y1, y2, dy;
  4020.  
  4021. int dm = n_midi -28;
  4022. y1 = 645 - (dm * 12);
  4023.  
  4024. dy=12;
  4025. x=0;
  4026. dx=85;
  4027.  
  4028. rectangle1 = new QGraphicsRectItem(x, y1, dx, dy);
  4029. QPen pen1;
  4030. pen1.setColor("#FFFFFF");
  4031. pen1.setWidth(1);
  4032. rectangle1->setPen(pen1);
  4033. calque_gradu_TAB_FRQ->addToGroup(rectangle1);
  4034.  
  4035.  
  4036. if (! checkBox_sel_boite->isChecked())
  4037. {
  4038. y2 = y1 + 44;
  4039. ligne1 = new QGraphicsLineItem(0, y2, 12000, y2); // ligne horizontale sur toute la largeur du calque
  4040. ligne1->setPen(pen1);
  4041. calque_surbrillance->addToGroup(ligne1);
  4042. }
  4043.  
  4044. }
  4045.  
  4046.  
  4047. int MainWindow::num_barre(double xi) // en fonction de la position x
  4048. {
  4049. //double pas_grille = spinBox_dxa->value()/2.0 * zoom_x; // pas de la grille
  4050. //double offset_grille = 0; //75;
  4051. //double x_barre = offset_grille; //0
  4052.  
  4053. int n_barre=0; // numero de la barre verticale de la grille T temporelle (depuis le départ)
  4054. double x_barre=0;
  4055. bool trouve = false; // à priori
  4056. int n =-100; // nb négatif pour prendre en compte les notes situées en amont (à gauche) de la barre zéro
  4057. while ((n<2000) && (trouve == false))
  4058. {
  4059. double dx2 = xi- x_barre;
  4060. if (dx2<0) {dx2 = -dx2;}
  4061.  
  4062. if (dx2 < calcul_pas_grille()/2.0)
  4063. {
  4064. trouve = true;
  4065. n_barre = n; // numero de la barre verticale de la grille temporelle
  4066. }
  4067. x_barre = calcul_x_barre(n+1);
  4068. n++;
  4069. }
  4070.  
  4071. if (trouve == false) {return -1000;}
  4072. //if (n==0) {return -1000;}
  4073.  
  4074. return n_barre;
  4075. }
  4076.  
  4077.  
  4078.  
  4079. int MainWindow::recherche_note(double y_i)
  4080. {
  4081. // recherche (verticale) de la note midi la plus proche du point cliqué
  4082. int dm =-1;
  4083. for(int n=0; n<=54; n++)
  4084. {
  4085. int d1= (684-y_i) - 12*n; // 704
  4086. //d1=abs(d1);
  4087. if(d1<0){d1= -d1;}
  4088. if(d1 <= 5) { dm = n; } // 5 sachant que l'espacement (vertical) de niveaux est = 10
  4089. }
  4090. return dm;
  4091. }
  4092.  
  4093.  
  4094. void MainWindow::recherche_notes_rect()
  4095. {
  4096. // recherche des notes comprises dans un rectangle
  4097.  
  4098. int n_max = liste_NOTES.length();
  4099. for (int n=0; n< n_max; n++)
  4100. {
  4101. int n_barre_i = liste_NOTES[n].n_barreM;
  4102. int midi_i = liste_NOTES[n].midi;
  4103. double x = calcul_x_barre(n_barre_i);
  4104. double y = calcul_y_note(midi_i);
  4105.  
  4106. if ((x >= x0_boite) && (x <= x1_boite) && (y >= y0_boite) && (y <= y1_boite) )
  4107. {
  4108. liste_NOTES[n].statut |= 0b00000001 ;
  4109. surbrille_note(n, false, 2);
  4110. }
  4111. }
  4112. }
  4113.  
  4114.  
  4115.  
  4116. void MainWindow::mouseMoveEvent(QMouseEvent *event) // actif si le clic de droite reste appuyé
  4117. {
  4118. double x0, y0; // position cliquée
  4119. int midi=0;
  4120. int dm =0;
  4121.  
  4122. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  4123. double scroll_y = graphicsView4->verticalScrollBar()->value();
  4124.  
  4125. x_clic_ecran = event->position().x();
  4126. y_clic_ecran = event->position().y();
  4127.  
  4128. x0 = x_clic_ecran-102 + scroll_x; // position cliquée
  4129. y0 = y_clic_ecran-78 + scroll_y; // 78
  4130.  
  4131. // recherche (verticale) de la note midi la plus proche du point cliqué
  4132.  
  4133. dm = recherche_note(y0);
  4134. if (dm == -1) {return;}
  4135.  
  4136. // calcul de la valeur midi de la note
  4137. midi = 28 + dm;
  4138.  
  4139. effacer_calque(scene4, calque_rect_select);
  4140. effacer_calque(scene4, calque_surbrillance);
  4141. encadre_midi(midi);
  4142. affi_details_note(midi);
  4143.  
  4144. // sélection par boite
  4145. if (checkBox_sel_boite->isChecked())
  4146. {
  4147.  
  4148. x0_boite = x_clic_GRV4;
  4149. x1_boite = x0;
  4150. if(x1_boite <= x0_boite) { x1_boite=x0_boite +1; }
  4151. y0_boite = y_clic_GRV4 -8.0;
  4152. y1_boite = y0;
  4153. if(y1_boite <= y0_boite) { y1_boite=y0_boite +1; }
  4154.  
  4155. // rectangle1 = new QGraphicsRectItem(x_clic_GRV4, y_clic_GRV4 -8.0, x0 - x_clic_GRV4, y0 - y_clic_GRV4);
  4156. rectangle1 = new QGraphicsRectItem(x0_boite, y0_boite -8.0, x1_boite - x0_boite, y1_boite - y0_boite);
  4157. QPen pen1;
  4158. pen1.setColor("#F57900");
  4159. pen1.setWidth(1);
  4160. rectangle1->setPen(pen1);
  4161. calque_rect_select->addToGroup(rectangle1);
  4162.  
  4163. deselect_notes();
  4164.  
  4165. //effacer_calque(scene4, calque_notes_jouee);
  4166. recherche_notes_rect();
  4167. trace_liste_notes();
  4168. }
  4169.  
  4170.  
  4171. }
  4172.  
  4173.  
  4174. void MainWindow::affi_details_note(int midi)
  4175. {
  4176. QString s1;
  4177. s1.setNum(midi);
  4178. lineEdit_7->setText(s1);
  4179.  
  4180. affi_txt_en_couleur(midi, lineEdit_7b);
  4181. lineEdit_7b->setText(nom_note(midi));
  4182.  
  4183. affi_txt_en_couleur(midi, lineEdit_7e);
  4184.  
  4185. s1=nom_note_GB(midi);
  4186. s1+=nom_octave_GB(midi);
  4187. lineEdit_7e->setText(s1);
  4188.  
  4189. double F = freq_mid(midi);
  4190. s1.setNum(F);
  4191. s1.replace('.',','); // ce qui permet un copié-collé direct dans 'Adacity'
  4192. lineEdit_7d->setText(s1);
  4193. }
  4194.  
  4195.  
  4196. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
  4197. {
  4198. // sert à ajouter une note (en write_mode 1) lorsqu'on relache le clic
  4199. // tant que le clic de droite reste enfoncé cela permet de confirmer la note midi qui sera ajoutée
  4200. // (mise en surbrillance en temps réel de la valeur midi dans la colonne de gauche)
  4201.  
  4202. QString s1;
  4203. double x0, y0; // position cliquée
  4204. int n_barre=0; // numero de la barre verticale de la grille temporelle (depuis le départ)
  4205. int n2=0;
  4206. int midi=0;
  4207. int dm =0;
  4208.  
  4209. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  4210. double scroll_y = graphicsView4->verticalScrollBar()->value();
  4211.  
  4212. x_clic_ecran = event->position().x();
  4213. y_clic_ecran = event->position().y();
  4214.  
  4215. x0 = x_clic_ecran-102 + scroll_x; // position cliquée
  4216. y0 = y_clic_ecran-78 + scroll_y;
  4217.  
  4218. //qDebug() << "y0" << y0;
  4219.  
  4220. dm = recherche_note(y0);
  4221. if (dm == -1) {return;}
  4222.  
  4223. midi = 28 + dm; // calcul de la valeur midi de la note
  4224. n_barre = num_barre(x0);
  4225. if (n_barre == -1000) {return;}
  4226.  
  4227. affi_details_note(midi);
  4228.  
  4229. n2 = test_if_note_in_liste(n_barre, midi); // si note in liste, -> n2 = num de la note
  4230.  
  4231. if (n2 != -1000) { QString s1; s1.setNum(n2); lineEdit_7c->setText(s1); }
  4232.  
  4233. if (write_mode == 1) // WRITE (ajout d'une note)
  4234. {
  4235. n2 = test_if_note_in_liste(n_barre, midi);
  4236. if (n2 == -1000) // si la note ne figure pas déjà dans la liste...
  4237. {
  4238. // enregistre la note dans la liste (à la fin)
  4239. if(mode=='T') {ajout_note(midi, n_barre, 0);}
  4240. if(mode=='M') {ajout_note(midi, 0, n_barre);}
  4241. }
  4242. effacer_calque(scene4,calque_notes_manuelles);
  4243. //effacer_calque(scene4,calque_notes_jouee);
  4244. tri_liste_notes_par_num_barre(); // les notes seront triées par num_barre croissant
  4245. numerotation_liste_notes(); // les notes seront numérotées par num_barre croissant
  4246. affiche_liste_notes();
  4247. trace_liste_notes();
  4248. surbrille_note(n2, true, 1);
  4249. }
  4250. }
  4251.  
  4252.  
  4253. void MainWindow::deselect_notes()
  4254. {
  4255. int n_max =liste_NOTES.length();
  4256. for (int n =0; n<n_max; n++)
  4257. {
  4258. liste_NOTES[n].statut &= ~0b00000001;
  4259. }
  4260. effacer_calque(scene4, calque_surbrillance);
  4261.  
  4262. }
  4263.  
  4264.  
  4265.  
  4266. void MainWindow::mousePressEvent(QMouseEvent *event)
  4267. {
  4268. if(event->button() == Qt::RightButton) {return;}
  4269.  
  4270. qDebug() << "clic de gauche";
  4271.  
  4272. if (tabWidget_Global->currentIndex() != 1) {return;}
  4273.  
  4274. QString s1;
  4275. //double x0, y0; // position cliquée
  4276.  
  4277. int n_barre=0; // numero de la barre verticale de la grille temporelle (depuis le départ)
  4278. int n2=0;
  4279.  
  4280. //double x_barre=0;
  4281. double x_min, x_max;
  4282. double y_min, y_max;
  4283.  
  4284. int midi=0; // midi
  4285. int dm =0;
  4286.  
  4287. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  4288. double scroll_y = graphicsView4->verticalScrollBar()->value();
  4289.  
  4290. graphicsView4->verticalScrollBar()->setValue(0);
  4291.  
  4292. //if (checkBox_sel_boite->isChecked()) { deselect_notes();}
  4293. effacer_calque(scene4, calque_surbrillance);
  4294.  
  4295. s1.setNum(scroll_x); lineEdit_8->setText(s1);
  4296. s1.setNum(scroll_y); lineEdit_9->setText(s1);
  4297.  
  4298. x_min = graphicsView4->x();
  4299. x_max = x_min + graphicsView4->width();
  4300.  
  4301. y_min = graphicsView4->y()+60;
  4302. y_max = y_min + graphicsView4->height() + 32; // +32 sinon rate le mi grave (midi 40)
  4303.  
  4304. x_clic_ecran = event->position().x(); // variable globale
  4305. y_clic_ecran = event->position().y();
  4306.  
  4307. x_clic_GRV4 = x_clic_ecran-102 + scroll_x; // position cliquée // variable globale
  4308. y_clic_GRV4 = y_clic_ecran-78 + scroll_y; // 78
  4309.  
  4310.  
  4311. // ---------------------- si clic sur la surface de graphicsView4 ----------------------------------------
  4312. if (x_clic_ecran > x_min && x_clic_ecran < x_max && y_clic_ecran > y_min && y_clic_ecran < y_max)
  4313. {
  4314. s1.setNum(x_clic_GRV4); lineEdit_4->setText(s1);
  4315. s1.setNum(y_clic_GRV4); lineEdit_5->setText(s1); // =481 foire !
  4316.  
  4317. dm = recherche_note(y_clic_GRV4);
  4318. if (dm != -1)
  4319. {
  4320. // calcul de la valeur midi de la note
  4321. midi = 28 + dm;
  4322. encadre_midi(midi);
  4323. n_barre = num_barre(x_clic_GRV4);
  4324. num_barre_saisie = n_barre;
  4325. spinBox_num_barre->setValue(num_barre_saisie);
  4326. surbrille_barre(num_barre_saisie, "#00FF00");
  4327. //if (n_barre == -1000) {return;}
  4328. affi_details_note(midi);
  4329. n2 = test_if_note_in_liste(n_barre, midi); // si note in liste, -> n2 = num de la note
  4330. if (n2 != -1000) { QString s1; s1.setNum(n2); lineEdit_7c->setText(s1); }
  4331.  
  4332. if (write_mode == 3) // SELECT
  4333. {
  4334. n2 = test_if_note_in_liste(n_barre, midi);
  4335. if (n2 != -1000) // si la note figure dans la liste...
  4336. {
  4337. effacer_calque(scene4, calque_notes_jouee);
  4338. num_note_cliquee = n2;
  4339. //liste_NOTES[n2].statut |= 0b00000001;
  4340. }
  4341. }
  4342.  
  4343. if (write_mode < 5) {play_note(midi);}
  4344.  
  4345. //effacer_calque(scene4, calque_surbrillance);
  4346. // encadre_midi(midi);
  4347.  
  4348. // surbrille_note(n2, true);
  4349.  
  4350. if (write_mode == 2) // EFFACE une note puis quitte ce mode
  4351. {
  4352. n2 = test_if_note_in_liste(n_barre, midi);
  4353. if (n2 != -1000) // si la note figure dans la liste...
  4354. {
  4355. supprime_note(n2);
  4356. on_Bt_mode_R_clicked(); // repasse en mode LECTURE pour éviter d'effacer d'autres notes par erreur
  4357. }
  4358. }
  4359.  
  4360. if (write_mode == 4) // EFFACE plusieurs notes (c.à.d ne quitte pas le mode)
  4361. {
  4362. if (checkBox_sel_boite->isChecked())
  4363. {
  4364. int n_max = liste_NOTES.length();
  4365. for(int n=0; n<n_max; n++)
  4366. {
  4367. if ((liste_NOTES[n].statut & 0b00000001) == 0b00000001) {supprime_note(n);}
  4368. }
  4369.  
  4370. }
  4371.  
  4372. n2 = test_if_note_in_liste(n_barre, midi);
  4373. if (n2 != -1000) // si la note figure dans la liste...
  4374. {
  4375. supprime_note(n2);
  4376. }
  4377.  
  4378. }
  4379.  
  4380. if (write_mode == 5) // COPIER groupe de notes
  4381. {
  4382. n_barre_copie = n_barre;
  4383. MainWindow::setCursor(Qt::PointingHandCursor);
  4384. encadre_groupe_notes(n_barre_copie, spinBox_nb_copie->value());
  4385. //surbrille_barre(n_barre_copie);
  4386. write_mode = 6;
  4387. }
  4388. else if (write_mode == 6) // COLLER groupe de notes
  4389. {
  4390. duplique_notes(n_barre_copie, n_barre, spinBox_nb_copie->value());
  4391. write_mode = 0;
  4392. effacer_calque(scene4, calque_surbrillance);
  4393. encadre_groupe_notes(n_barre, spinBox_nb_copie->value());
  4394. MainWindow::setCursor(Qt::ArrowCursor);
  4395. }
  4396. }
  4397. else
  4398. {
  4399. ;
  4400. //deselect_notes();
  4401. //write_mode =0;
  4402. }
  4403. }
  4404. /*
  4405.  *problème avec cette fonction : la disposition verticalement des notes sur une portée suit la gamme diatonique et non
  4406.  *chromatique, un même espacement peut compter pour un ton ou un demi-ton (mi-fa et si-do)
  4407.  *donc il faudra en tenir compte. pour l'intant je la passe en commentaire.
  4408.  *
  4409.   int xcds = frame_cle_de_sol->pos().x();
  4410.   int ycds = frame_cle_de_sol->pos().y();
  4411.   if ( x_clic_ecran > xcds && y_clic_ecran > ycds )
  4412.   {
  4413.   int hauteur = y_clic_ecran - ycds;
  4414.   hauteur -= 50; // à voir pourquoi...
  4415.   float pix_par_demi_ton = 162/26;
  4416.   float nb_deg = 10 + hauteur/pix_par_demi_ton;
  4417.   int n_midi = 82 - nb_deg;
  4418.   encadre_midi(n_midi);
  4419.   }
  4420. */
  4421.  
  4422. //int h1 = calcul_hauteur_note(midi);
  4423. //QColor couleur1 = liste_couleurs[h1];
  4424.  
  4425. effacer_calque(scene4,calque_notes_manuelles);
  4426. //effacer_calque(scene4,calque_notes_jouee);
  4427. tri_liste_notes_par_num_barre(); // les notes seront triées par num_barre croissant
  4428. numerotation_liste_notes(); // les notes seront numérotées par num_barre croissant
  4429. affiche_liste_notes();
  4430. trace_liste_notes();
  4431. surbrille_note(n2, true, 1);
  4432. encadre_midi(midi);
  4433.  
  4434. int octave = (midi-36) /12;
  4435. int hauteur = calcul_hauteur_note(midi);
  4436.  
  4437. spinBox_octave->setValue(octave);
  4438. spinBox_hauteur->setValue(hauteur);
  4439.  
  4440. spinBox_num_note->setValue(num_note_cliquee);
  4441. spinBox_10->setValue(num_note_cliquee); // 'debut'
  4442.  
  4443.  
  4444. if (0) // 1 pour test (affiche une petite croix à la position cliquée)
  4445. {
  4446. int d=10; // taille
  4447. QPen pen1; pen1.setColor("#FFFF00");
  4448. ligne1 = new QGraphicsLineItem(x_clic_GRV4-d, y_clic_GRV4-d, x_clic_GRV4+d, y_clic_GRV4+d);
  4449. ligne1->setPen(pen1);
  4450. calque_notes_manuelles->addToGroup(ligne1);
  4451. ligne1 = new QGraphicsLineItem(x_clic_GRV4-d, y_clic_GRV4+d, x_clic_GRV4+d, y_clic_GRV4-d);
  4452. ligne1->setPen(pen1);
  4453. calque_notes_manuelles->addToGroup(ligne1);
  4454. }
  4455. }
  4456.  
  4457.  
  4458. void MainWindow::contextMenuEvent(QContextMenuEvent *event)
  4459. //declenche le menu contextuel lors du clic de droite
  4460. {
  4461. qDebug() << "clic de droite";
  4462. return;
  4463.  
  4464. }
  4465.  
  4466.  
  4467. int MainWindow::joue_1_note_de_la_liste()
  4468. {
  4469. NOTE note_i1, note_i2;
  4470. int midi_i;
  4471. int barre1=0;
  4472. int barre2=0;
  4473. int d_barre;
  4474. QString s1;
  4475.  
  4476. QDateTime tpi;
  4477. tpi = QDateTime::currentDateTime();
  4478. qint64 tp_relatif = temps_0.msecsTo(tpi); // en ms
  4479. s1.setNum(tp_relatif);
  4480.  
  4481. uint16_t num_max = liste_NOTES.length();
  4482. if (num_max == 0) {return 0;}
  4483. if (num_max < 3) {return 0;}
  4484.  
  4485.  
  4486. if (num_note_jouee >= num_max)
  4487. {
  4488. // fin du morceau !
  4489. lecture_en_cours = false;
  4490. Timer2->stop();
  4491. Bt_jouer_tout->setText(">");
  4492. return 0;
  4493. }
  4494. note_i1 = liste_NOTES[num_note_jouee];
  4495.  
  4496. if(num_note_jouee < num_max)
  4497. {
  4498. note_i2 = liste_NOTES[num_note_jouee+1];
  4499. }
  4500. else
  4501. {
  4502. note_i2 = liste_NOTES[num_note_jouee];
  4503. }
  4504.  
  4505.  
  4506. midi_i=note_i1.midi;
  4507.  
  4508. if(mode == 'T')
  4509. {
  4510. barre1 = note_i1.n_barreT;
  4511. barre2 = note_i2.n_barreT;
  4512. }
  4513. if(mode == 'M')
  4514. {
  4515. barre1 = note_i1.n_barreM;
  4516. barre2 = note_i2.n_barreM;
  4517. }
  4518.  
  4519. d_barre = barre2 - barre1;
  4520. if (d_barre < 0){d_barre = -d_barre;}
  4521.  
  4522. if (barre1 == barre2) // detection d'un accord (notes simultanées)
  4523. {
  4524. // surbrille_note(num_note_jouee, false);
  4525. // surbrille_note(num_note_jouee+1, false);
  4526. nb_acc++;
  4527. }
  4528. else
  4529. {
  4530. if (nb_acc == 0) {effacer_calque(scene4, calque_notes_jouee);}
  4531. surbrille_note(num_note_jouee, false, 1);
  4532. surbrille_barre(barre1, "#FFFFFF");
  4533. if (midi_i >45) // on laisse résonner les basses
  4534. {
  4535. //player1->stop();
  4536. //player2->stop();
  4537. //player3->stop();
  4538. }
  4539. nb_acc--; if (nb_acc<0) {nb_acc=0;}
  4540. }
  4541.  
  4542. s1.setNum(num_note_jouee); lineEdit_7c->setText(s1);
  4543. lineEdit_7->setText("");
  4544. lineEdit_7b->setText("");
  4545.  
  4546. s1.setNum(midi_i) ;
  4547.  
  4548. if(num_note_jouee == num_max) {d_barre = 2;}
  4549.  
  4550. if ( ! (checkBox_basses->isChecked() && midi_i > spinBox_filtre_2->value() ))
  4551. {
  4552. play_note(midi_i);
  4553. // encadre_midi(midi_i);
  4554. }
  4555.  
  4556. num_note_jouee++;
  4557. if(num_note_jouee > num_note_max)
  4558. {
  4559. Timer2->stop();
  4560. effacer_calque(scene4, calque_notes_jouee);
  4561. //num_note_jouee=0;
  4562. }
  4563.  
  4564. return d_barre; // permet de retrouver l'espacement temporel entre la note et celle qui suit.
  4565. }
  4566.  
  4567.  
  4568.  
  4569.  
  4570. void MainWindow::on_Bt_toggle_grille_T_clicked()
  4571. {
  4572. Bt_toggle_grille_T->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4573. Bt_toggle_grille_M->setStyleSheet("background-color: rgb(200, 200, 200);");
  4574.  
  4575. mode = 'T';
  4576. mode_grille_T();
  4577.  
  4578. // tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4579. // numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  4580. // affiche_liste_notes();
  4581. trace_liste_notes();
  4582. //effacer_calque(scene4, calque_echelle_temporelle_T);
  4583.  
  4584. }
  4585.  
  4586.  
  4587. void MainWindow::on_Bt_toggle_visu_notes_clicked()
  4588. {
  4589. if(visu_notes == true)
  4590. {
  4591. visu_notes = false;
  4592. Bt_toggle_visu_notes->setStyleSheet("background-color: rgb(200, 200, 200);");
  4593. effacer_calque(scene4, calque_notes_manuelles);
  4594. }
  4595. else
  4596. {
  4597. visu_notes = true;
  4598. Bt_toggle_visu_notes->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4599. trace_liste_notes();
  4600. }
  4601. }
  4602.  
  4603.  
  4604.  
  4605.  
  4606. void MainWindow::on_Bt_toggle_grille_M_clicked()
  4607. {
  4608. Bt_toggle_grille_M->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4609. Bt_toggle_grille_T->setStyleSheet("background-color: rgb(200, 200, 200);");
  4610.  
  4611. mode = 'M';
  4612. mode_grille_M();
  4613.  
  4614. //tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4615. // numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  4616. // affiche_liste_notes();
  4617. trace_liste_notes();
  4618. }
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624. void MainWindow::mode_grille_T()
  4625. {
  4626. effacer_calque(scene4, calque_grille_T);
  4627. effacer_calque(scene4, calque_grille_M);
  4628. effacer_calque(scene4, calque_echelle_temporelle_T);
  4629. effacer_calque(scene4, calque_echelle_temporelle_M);
  4630.  
  4631. frame_7->setVisible(true);
  4632. frame_10->setVisible(false);
  4633. Bt_copie_notes->setVisible(false);
  4634. pushButton_12->setVisible(false);
  4635. //spinBox_dxa->setVisible(false);
  4636. doubleSpinBox_dxb->setVisible(false);
  4637. spinBox_x0a->setVisible(false);
  4638. doubleSpinBox_x0b->setVisible(false);
  4639.  
  4640. Bt_decale_notes_L->setVisible(true);
  4641. Bt_decale_notes_R->setVisible(true);
  4642. Bt_durees_div2->setVisible(true);
  4643. Bt_durees_mult2->setVisible(true);
  4644.  
  4645. tracer_grille_T();
  4646. }
  4647.  
  4648.  
  4649.  
  4650. void MainWindow::mode_grille_M()
  4651. {
  4652. effacer_calque(scene4, calque_grille_T);
  4653. effacer_calque(scene4, calque_grille_M);
  4654. effacer_calque(scene4, calque_echelle_temporelle_T);
  4655. effacer_calque(scene4, calque_echelle_temporelle_M);
  4656.  
  4657. frame_7->setVisible(false);
  4658. frame_10->setVisible(true);
  4659. Bt_copie_notes->setVisible(true);
  4660. pushButton_12->setVisible(true);
  4661.  
  4662. //spinBox_dxa->setVisible(true);
  4663. doubleSpinBox_dxb->setVisible(true);
  4664. spinBox_x0a->setVisible(true);
  4665. doubleSpinBox_x0b->setVisible(true);
  4666.  
  4667. Bt_decale_notes_L->setVisible(false);
  4668. Bt_decale_notes_R->setVisible(false);
  4669. Bt_durees_div2->setVisible(false);
  4670. Bt_durees_mult2->setVisible(false);
  4671.  
  4672. tracer_grille_M();
  4673. }
  4674.  
  4675.  
  4676.  
  4677. void MainWindow::on_Bt_save_notes_clicked()
  4678. {
  4679. int r1, r2;
  4680.  
  4681. QDate date_systeme = QDate::currentDate();
  4682. QTime heure_systeme = QTime::currentTime();
  4683.  
  4684. QString date1 = date_systeme.toString("yyyyMMdd");
  4685. QString heure1 = heure_systeme.toString();
  4686. QString date_out = date1 + "_" + heure1;
  4687.  
  4688. r1 = save_fichier_NOTES(date_out);
  4689. r2 = save_fichier_FRQ(date_out);
  4690.  
  4691. if ((r1 + r2) != 2) // si = 2 -> aucun fichier enregistré, alors on n'affiche pas le message
  4692. {
  4693. QMessageBox msgBox;
  4694. QString s1="Fichiers enregistrés dans : \n" + string_currentDir + "/";
  4695. msgBox.setText(s1); msgBox.exec();
  4696. }
  4697. }
  4698.  
  4699.  
  4700.  
  4701. void MainWindow::on_Bt_load_notes_clicked()
  4702. {
  4703. uint16_t n_max = liste_NOTES.length();
  4704.  
  4705. if (n_max != 0) // pour éviter d'enregistrer un fichier vide lors du 1er chargement des notes
  4706. {
  4707. QMessageBox msgBox;
  4708.  
  4709. msgBox.setText("Confirmation de chargement");
  4710. msgBox.setInformativeText("Un enregistrement des notes va être effectué au préalable.\n \n"
  4711. "Si clic sur No, les notes actuelles seront perdues.\n \n"
  4712. "Si clic sur Cancel, opération annulée");
  4713.  
  4714. msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Ok | QMessageBox::Cancel);
  4715. msgBox.setDefaultButton(QMessageBox::Cancel);
  4716. int ret = msgBox.exec();
  4717. if (ret == QMessageBox::Cancel ) { return; }
  4718. if (ret == QMessageBox::Ok ) { on_Bt_save_notes_clicked(); }
  4719. }
  4720.  
  4721.  
  4722. liste_NOTES.clear();
  4723. effacer_calque(scene4,calque_notes_manuelles);
  4724. effacer_calque(scene4,calque_notes_auto);
  4725. effacer_calque(scene4,calque_notes_jouee);
  4726. effacer_calque(scene5, calque_histogramme );
  4727. effacer_calque(scene4, calque_echelle_temporelle_T);
  4728. effacer_calque(scene4, calque_echelle_temporelle_M);
  4729.  
  4730. load_fichier_NOTES("");
  4731.  
  4732. suppression_notes_invalides();
  4733.  
  4734. tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  4735. numerotation_liste_notes();
  4736.  
  4737. calcul_histogramme_durees();
  4738. affiche_histogramme_durees();
  4739. on_Bt_toggle_grille_M_clicked();
  4740. }
  4741.  
  4742.  
  4743. void MainWindow::on_Bt_joue_passage_clicked()
  4744. {
  4745. if (liste_NOTES.length() == 0) {return;}
  4746.  
  4747. if (lecture_en_cours == true)
  4748. {
  4749. Timer2->stop();
  4750. Bt_joue_passage->setText(">");
  4751. Timer2->setInterval(0);
  4752. lecture_en_cours = false;
  4753. }
  4754. else
  4755. {
  4756. Bt_joue_passage->setText("[]");
  4757.  
  4758. Timer2->start(500);
  4759.  
  4760. int note_de_depart = spinBox_10->value();
  4761. int nb_notes_a_jouer = spinBox_11->value()-1;
  4762.  
  4763. num_note_jouee = note_de_depart;
  4764. num_note_max = note_de_depart + nb_notes_a_jouer;
  4765. if (num_note_max > liste_NOTES.length()-1) { num_note_max = liste_NOTES.length()-1;}
  4766.  
  4767. // NOTE note_i = liste_NOTES[note_de_depart];
  4768. //double x_note = 80 + note_i.n_barreT * spinBox_dxa->value()/2.0 * zoom_x;
  4769. // graphicsView4->horizontalScrollBar()->setValue(x_note - 100);
  4770.  
  4771. Timer2->start(500);
  4772. lecture_en_cours = true;
  4773. }
  4774.  
  4775. }
  4776.  
  4777.  
  4778. void MainWindow::on_Bt_joue_wav_clicked()
  4779. {
  4780. QStringList arguments;
  4781. arguments << string_currentFile;
  4782. QString program = "audacity"; //"audacious"
  4783. QProcess *myProcess = new QProcess();
  4784. myProcess->start(program, arguments);
  4785. }
  4786.  
  4787.  
  4788.  
  4789. void MainWindow::on_Bt_joue_wav_2_clicked()
  4790. {
  4791. on_Bt_joue_wav_clicked();
  4792. }
  4793.  
  4794.  
  4795. void MainWindow::on_Btn_RAZ_notes_clicked()
  4796. {
  4797. QMessageBox msgBox;
  4798. msgBox.setText("Erase notes");
  4799. msgBox.setInformativeText("Effacer toutes les notes ?");
  4800. msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
  4801. msgBox.setDefaultButton(QMessageBox::Cancel);
  4802. int ret = msgBox.exec();
  4803.  
  4804. if (ret == QMessageBox::Ok )
  4805. {
  4806. liste_NOTES.clear();
  4807. num_barre_en_cours=0;
  4808. effacer_calque(scene4, calque_notes_manuelles);
  4809. effacer_calque(scene4, calque_notes_auto);
  4810. affiche_liste_notes();
  4811. effacer_calque(scene4, calque_surbrillance);
  4812. num_barre_saisie=0;
  4813. surbrille_barre(num_barre_saisie, "#00FF00");
  4814. }
  4815. }
  4816.  
  4817.  
  4818. void MainWindow::on_Btn_RAZ_notes_2_clicked()
  4819. {
  4820. QMessageBox msgBox;
  4821. msgBox.setText("Erase certaines notes");
  4822. msgBox.setInformativeText("Effacer des notes ?");
  4823. msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
  4824. msgBox.setDefaultButton(QMessageBox::Cancel);
  4825. int ret = msgBox.exec();
  4826.  
  4827. if (ret == QMessageBox::Ok )
  4828. {
  4829. int n = spinBox_n_raz->value();
  4830. //int n_max = liste_NOTES.length();
  4831.  
  4832. int n_max = liste_NOTES.length();
  4833. if (n<n_max)
  4834. {
  4835. liste_NOTES.remove(n, n_max-n);
  4836. }
  4837.  
  4838. int n_max2 = liste_ENR_FFT.length();
  4839. int n2= 300*n;
  4840. if (n2<n_max2)
  4841. {
  4842. liste_ENR_FFT.remove(n2, n_max2-n2);
  4843. }
  4844.  
  4845. effacer_calque(scene4, calque_notes_manuelles);
  4846. trace_liste_notes();
  4847.  
  4848. effacer_calque(scene4, calque_TAB_FRQ);
  4849. retracer_TAB_FRQ();
  4850.  
  4851. //effacer_calque(scene4,calque_notes_manuelles);
  4852. //effacer_calque(scene4, calque_notes_auto);
  4853. //affiche_liste_notes();
  4854. }
  4855. }
  4856.  
  4857.  
  4858.  
  4859. void MainWindow::on_spinBox_8_textChanged()
  4860. {
  4861. effacer_calque(scene4, calque_echelle_temporelle_T);
  4862. effacer_calque(scene4, calque_echelle_temporelle_M);
  4863. tracer_echelle_temps_TAB_NOTES();
  4864. }
  4865.  
  4866.  
  4867. void MainWindow::on_doubleSpinBox_x0_valueChanged(double arg1)
  4868. {
  4869.  
  4870. //double pas_grille = spinBox_dt->value()/2.0 * zoom_x;
  4871. //double offset_x = 10 * arg1 + spinBox_d_barres->value() * pas_grille;
  4872. // calque_TAB_FRQ->setPos(offset_x, 0);
  4873. // calque_notes_auto->setPos(offset_x, 0);
  4874.  
  4875. effacer_calque(scene4, calque_grille_M);
  4876. tracer_grille_M();
  4877. // effacer_calque(scene4, calque_notes_manuelles);
  4878. // affiche_liste_notes();
  4879. // trace_liste_notes();
  4880. // effacer_calque(scene4, calque_echelle_temporelle_T);
  4881. // tracer_echelle_temps_TAB_NOTES();
  4882. }
  4883.  
  4884.  
  4885. void MainWindow::on_spinBox_dxa_valueChanged(int arg1)
  4886. {
  4887.  
  4888. //doubleSpinBox_dxb->setValue(0);
  4889. effacer_calque(scene4, calque_echelle_temporelle_T);
  4890. effacer_calque(scene4, calque_grille_M);
  4891. tracer_grille_M();
  4892. effacer_calque(scene4, calque_notes_manuelles);
  4893. affiche_liste_notes();
  4894. //trace_liste_notes();
  4895.  
  4896. tracer_echelle_temps_TAB_NOTES();
  4897. if (visu_notes == true) {trace_liste_notes();}
  4898.  
  4899. // on_Bt_copy_nt_T_to_M_clicked();
  4900. }
  4901.  
  4902.  
  4903. void MainWindow::on_doubleSpinBox_dxb_valueChanged(double arg1)
  4904. {
  4905. effacer_calque(scene4, calque_grille_M);
  4906. effacer_calque(scene4, calque_echelle_temporelle_T);
  4907. effacer_calque(scene4, calque_echelle_temporelle_M);
  4908. effacer_calque(scene4, calque_notes_manuelles);
  4909.  
  4910. on_Bt_copy_nt_T_to_M_clicked();
  4911.  
  4912. affiche_liste_notes();
  4913. trace_liste_notes();
  4914. tracer_grille_M();
  4915. tracer_echelle_temps_TAB_NOTES();
  4916.  
  4917. //if (visu_notes == true) {trace_liste_notes();}
  4918.  
  4919. // on_Bt_copy_nt_T_to_M_clicked();
  4920.  
  4921. }
  4922.  
  4923.  
  4924. void MainWindow::on_Bt_mode_R_clicked() // LECTURE
  4925. {
  4926. write_mode=0;
  4927. //mode_select=false;
  4928. MainWindow::setCursor(Qt::ArrowCursor);
  4929. Bt_mode_R->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  4930. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4931. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4932. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  4933.  
  4934. }
  4935.  
  4936.  
  4937. void MainWindow::on_Bt_mode_W_clicked() // AJOUT
  4938. {
  4939. write_mode=1;
  4940. //mode_select=false;
  4941. //MainWindow::setCursor(Qt::SplitHCursor);
  4942. effacer_calque(scene4, calque_notes_jouee);
  4943. Bt_mode_W->setStyleSheet("background-color: rgb(255, 0, 0);"); // rouge
  4944. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4945. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  4946. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  4947.  
  4948. }
  4949.  
  4950.  
  4951. void MainWindow::on_Bt_mode_E_clicked() // EFFACE 1 note puis quitte ce mode
  4952. {
  4953. write_mode=2;
  4954. //mode_select=false;
  4955. //MainWindow::setCursor(Qt::SplitHCursor);
  4956. Bt_mode_E->setStyleSheet("background-color: rgb(0, 200, 200);"); // cyan
  4957. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  4958. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  4959. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  4960.  
  4961. }
  4962.  
  4963.  
  4964.  
  4965. void MainWindow::on_Bt_mode_E_2_clicked() // efface plusieurs notes (c.a.d reste dans ce mode)
  4966. {
  4967. if (write_mode == 4)
  4968. {
  4969. deselect_notes();
  4970. effacer_calque(scene4, calque_rect_select);
  4971.  
  4972. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  4973. write_mode=0;
  4974. }
  4975.  
  4976. else
  4977. {
  4978. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 0, 0);"); //rouge
  4979. if (checkBox_sel_boite->isChecked())
  4980. {
  4981. int n_max = liste_NOTES.length();
  4982. for(int n=0; n<n_max; n++)
  4983. {
  4984. if (n>=0)
  4985. {
  4986. if ((liste_NOTES[n].statut & 0b00000001) == 0b00000001)
  4987. {
  4988. supprime_note(n);
  4989. if (n>0) {n--;}
  4990. n_max = liste_NOTES.length();
  4991. }
  4992. }
  4993.  
  4994. }
  4995. deselect_notes();
  4996. effacer_calque(scene4, calque_rect_select);
  4997.  
  4998. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  4999. write_mode=0;
  5000.  
  5001. }
  5002. else
  5003. {
  5004. write_mode=4; // mode effacement plusieur notes une à la fois par clics successifs
  5005. }
  5006.  
  5007. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  5008. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  5009. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  5010.  
  5011. }
  5012.  
  5013. }
  5014.  
  5015.  
  5016.  
  5017. void MainWindow::on_Bt_deplace_L_clicked()
  5018. {
  5019. write_mode=3;
  5020.  
  5021. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  5022. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  5023. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  5024. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  5025.  
  5026. effacer_calque(scene4, calque_notes_manuelles);
  5027. effacer_calque(scene4, calque_notes_jouee);
  5028.  
  5029. int n_max = liste_NOTES.length();
  5030. for(int n=0; n<n_max; n++)
  5031. {
  5032. if ( (liste_NOTES[n].statut & 0b00000001) == 0b00000001) {deplace_note(n, -1, 0);}
  5033. }
  5034.  
  5035. affiche_liste_notes();
  5036. trace_liste_notes();
  5037.  
  5038. write_mode=0;
  5039. surbrille_note(num_note_cliquee, false, 1);
  5040. }
  5041.  
  5042.  
  5043. void MainWindow::on_Bt_deplace_R_clicked()
  5044. {
  5045. write_mode=3;
  5046. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  5047. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  5048. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  5049. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  5050.  
  5051. effacer_calque(scene4, calque_notes_manuelles);
  5052. effacer_calque(scene4, calque_notes_jouee);
  5053.  
  5054. int n_max = liste_NOTES.length();
  5055. for(int n=0; n<n_max; n++)
  5056. {
  5057. if ( (liste_NOTES[n].statut & 0b00000001) == 0b00000001) {deplace_note(n, 1, 0);}
  5058. }
  5059.  
  5060. affiche_liste_notes();
  5061. trace_liste_notes();
  5062.  
  5063. write_mode=0;
  5064. surbrille_note(num_note_cliquee, false, 1);
  5065. }
  5066.  
  5067.  
  5068. void MainWindow::on_Bt_deplace_H_clicked()
  5069. {
  5070. write_mode=3;
  5071. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  5072. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  5073. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  5074. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  5075.  
  5076. effacer_calque(scene4, calque_notes_manuelles);
  5077. effacer_calque(scene4, calque_notes_jouee);
  5078.  
  5079. int n_max = liste_NOTES.length();
  5080. for(int n=0; n<n_max; n++)
  5081. {
  5082. if ( (liste_NOTES[n].statut & 0b00000001) == 0b00000001)
  5083. {
  5084. deplace_note(n, 0, 1);
  5085. }
  5086. }
  5087.  
  5088. affiche_liste_notes();
  5089. trace_liste_notes();
  5090. }
  5091.  
  5092.  
  5093. void MainWindow::on_Bt_deplace_B_clicked()
  5094. {
  5095. write_mode=3;
  5096. Bt_mode_E->setStyleSheet("background-color: rgb(200, 200, 200);");
  5097. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);");
  5098. Bt_mode_W->setStyleSheet("background-color: rgb(200, 200, 200);");
  5099. Bt_mode_R->setStyleSheet("background-color: rgb(200, 200, 200);");
  5100.  
  5101. effacer_calque(scene4, calque_notes_manuelles);
  5102. effacer_calque(scene4, calque_notes_jouee);
  5103.  
  5104. int n_max = liste_NOTES.length();
  5105. for(int n=0; n<n_max; n++)
  5106. {
  5107. if ( (liste_NOTES[n].statut & 0b00000001) == 0b00000001) {deplace_note(n, 0, -1);}
  5108. }
  5109.  
  5110. affiche_liste_notes();
  5111. trace_liste_notes();
  5112. }
  5113.  
  5114.  
  5115.  
  5116. void MainWindow::on_Bt_scan_auto_clicked()
  5117. {
  5118. if (! wav_ok) {return;}
  5119. if ( ! liste_ENR_FFT.isEmpty()) {on_Bt_efface_clicked();}
  5120.  
  5121. on_Bt_toggle_visu_notes_clicked();
  5122.  
  5123. if (rapide)
  5124. {
  5125. tabWidget_Global->setCurrentIndex(1);
  5126.  
  5127. on_Bt_RAZ_clicked();
  5128.  
  5129. MainWindow::setCursor(Qt::WaitCursor);
  5130. effacer_calque(scene4, calque_TAB_FRQ );
  5131. effacer_calque(scene4, calque_echelle_temporelle_T);
  5132.  
  5133. mode_grille_T();
  5134. analyse_tout();
  5135. MainWindow::setCursor(Qt::ArrowCursor);
  5136. }
  5137. else {Timer1->start(10);}
  5138.  
  5139. }
  5140.  
  5141.  
  5142.  
  5143. void MainWindow::on_Bt_jouer_tout_clicked()
  5144. {
  5145. if (liste_NOTES.length() == 0) {return;}
  5146.  
  5147. if (lecture_en_cours == true)
  5148. {
  5149. lecture_en_cours = false;
  5150. Timer2->stop();
  5151. Bt_jouer_tout->setText(">");
  5152. }
  5153. else
  5154. {
  5155. Bt_jouer_tout->setText("[]");
  5156.  
  5157. graphicsView4->horizontalScrollBar()->setValue(0);
  5158. memo_scroll_x = 0;
  5159.  
  5160. Timer2->stop();
  5161. num_note_depart = 0;
  5162. num_note_max = liste_NOTES.length();//-1;
  5163. if (num_note_max < 1) {return;}
  5164. num_note_jouee = 0;
  5165. num_barre_en_cours=0;
  5166.  
  5167. temps_0 = QDateTime::currentDateTime();
  5168. Timer2->start(100); //voir la fonction 'Tic2()' qui va jouer les notes
  5169. lecture_en_cours = true;
  5170. }
  5171. }
  5172.  
  5173.  
  5174.  
  5175. void MainWindow::on_Bt_toggle_visu_freq_clicked()
  5176. {
  5177. effacer_calque(scene4, calque_notes_manuelles);
  5178.  
  5179. if(visu_freq == 0)
  5180. {
  5181. visu_freq = 1;
  5182. Bt_toggle_visu_freq->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  5183. calque_TAB_FRQ->setVisible(true);
  5184.  
  5185. }
  5186. else
  5187. {
  5188. visu_freq = 0;
  5189. Bt_toggle_visu_freq->setStyleSheet("background-color: rgb(200, 200, 200);");
  5190. calque_TAB_FRQ->setVisible(false);
  5191. on_Bt_toggle_grille_M_clicked();
  5192. }
  5193. }
  5194.  
  5195.  
  5196. void MainWindow::on_Bt_efface_2_clicked() // sur tab FREQ-NOTES
  5197. {
  5198. on_Bt_efface_clicked(); // (celui de l'autre tab FFT)
  5199. }
  5200.  
  5201.  
  5202.  
  5203.  
  5204.  
  5205. void MainWindow::on_doubleSpinBox_t0_valueChanged()
  5206. {
  5207. effacer_calque(scene4, calque_grille_M);
  5208. effacer_calque(scene4, calque_echelle_temporelle_T);
  5209. effacer_calque(scene4, calque_notes_manuelles);
  5210.  
  5211. affiche_liste_notes();
  5212. trace_liste_notes();
  5213.  
  5214. tracer_echelle_temps_TAB_NOTES();
  5215. tracer_grille_M();
  5216. }
  5217.  
  5218.  
  5219.  
  5220. void MainWindow::maj_TAB_NOTES()
  5221. {
  5222. effacer_calque(scene4, calque_grille_M);
  5223. effacer_calque(scene4, calque_notes_manuelles);
  5224. effacer_calque(scene4, calque_notes_auto);
  5225. effacer_calque(scene4, calque_echelle_temporelle_T);
  5226. effacer_calque(scene4, calque_TAB_FRQ);
  5227.  
  5228. retracer_TAB_FRQ();
  5229. trace_liste_notes();
  5230. tracer_echelle_temps_TAB_NOTES();
  5231. tracer_grille_M();
  5232. }
  5233.  
  5234.  
  5235.  
  5236. void MainWindow::on_spinBox_zoom_2_valueChanged(int arg1)
  5237. {
  5238. zoom_x = arg1;
  5239. MainWindow::setCursor(Qt::WaitCursor);
  5240. effacer_calque(scene4, calque_grille_T);
  5241. maj_TAB_NOTES();
  5242. MainWindow::setCursor(Qt::ArrowCursor);
  5243. }
  5244.  
  5245.  
  5246.  
  5247. void MainWindow::on_pushButton_9_clicked()
  5248. {
  5249. QMessageBox msgBox;
  5250. QString s1;
  5251. s1 = "Le n° barre est compté depuis le début.";
  5252. s1 += "\n";
  5253. s1 += "La durée est exprimée en nombre de barres. Elle est calculée à postériori :"; s1 += "\n";
  5254. s1 += "La durée des notes n'est (volontairement) pas enregistrée dans les notes ";
  5255. s1 += "ce qui permet de ne PAS affecter l'emplacement de toutes les notes ";
  5256. s1 += "dans la trame temporelle lors de la modification, l'ajout ou la suppression d'une note"; s1 += "\n";
  5257. s1 += "Le tempo et le rythme sont ainsi conservés."; s1 += "\n";
  5258. s1 += "C'est d'ailleurs (me semble-t-il) l'approche retenue dans la norme midi."; s1 += "\n";
  5259.  
  5260. msgBox.setText(s1);
  5261. msgBox.exec();
  5262. }
  5263.  
  5264.  
  5265. void MainWindow::on_spinBox_offset_valueChanged()
  5266. {
  5267. //do_FFT_freq_midi();
  5268. }
  5269.  
  5270.  
  5271.  
  5272. void MainWindow::on_spinBox_d_barres_valueChanged()
  5273. {
  5274. double pas_grille = doubleSpinBox_dxb->value()/2.0 * zoom_x;
  5275. double offset_x = 10 * doubleSpinBox_x0b->value() + spinBox_d_barres->value() * pas_grille;
  5276. calque_TAB_FRQ->setPos(offset_x, 0);
  5277. }
  5278.  
  5279.  
  5280. void MainWindow::on_Bt_decale_notes_L_clicked()
  5281. {
  5282. decalle_notes(-1);
  5283. effacer_calque(scene4,calque_notes_manuelles);
  5284. affiche_liste_notes(); // en texte
  5285. trace_liste_notes(); // ellipses
  5286. }
  5287.  
  5288.  
  5289. void MainWindow::on_Bt_decale_notes_R_clicked()
  5290. {
  5291. decalle_notes(1);
  5292. effacer_calque(scene4,calque_notes_manuelles);
  5293. affiche_liste_notes(); // en texte
  5294. trace_liste_notes(); // ellipses
  5295. }
  5296.  
  5297.  
  5298.  
  5299. void MainWindow::on_tableWidget_type_M_cellClicked(int row, int column)
  5300. {
  5301. switch (row)
  5302. {
  5303. case 0: {lineEdit_10->setText("2/4"); Ta=2; Tb=4;} break; // Ta et Tb variables globales
  5304. case 1: {lineEdit_10->setText("3/4"); Ta=3; Tb=4;} break;
  5305. case 2: {lineEdit_10->setText("4/4"); Ta=4; Tb=4;} break;
  5306. default: break;
  5307. }
  5308. effacer_calque(scene4, calque_grille_M);
  5309. tracer_grille_M();
  5310. }
  5311.  
  5312.  
  5313.  
  5314. void MainWindow::on_checkBox_flitrer_clicked()
  5315. {
  5316. /*
  5317.   if (checkBox_flitrer->isChecked())
  5318.   {
  5319.   textEdit_ETAT->setText("Mode Filtré : \n Ne sont représentés que les signaux dont l'amplitude est supérieure au seuil choisi");
  5320.   }
  5321.   else
  5322.   {
  5323.   textEdit_ETAT->setText("Mode non-filtré : \n Tous les signaux issus de la FFT sont représentés");
  5324.   }
  5325. */
  5326.  
  5327. MainWindow::setCursor(Qt::WaitCursor);
  5328. maj_TAB_NOTES();
  5329. MainWindow::setCursor(Qt::ArrowCursor);
  5330. }
  5331.  
  5332. /*
  5333. void MainWindow::on_spinBox_filtre_valueChanged()
  5334. {
  5335.   if (checkBox_flitrer->isChecked())
  5336.   {
  5337.   MainWindow::setCursor(Qt::WaitCursor);
  5338.   maj_TAB_NOTES();
  5339.   MainWindow::setCursor(Qt::ArrowCursor);
  5340.   }
  5341. }
  5342. */
  5343. /*
  5344. void MainWindow::on_doubleSpinBox_gain_valueChanged()
  5345. {
  5346.   MainWindow::setCursor(Qt::WaitCursor);
  5347.   effacer_calque(scene4, calque_TAB_FRQ);
  5348.   retracer_TAB_FRQ();
  5349.   MainWindow::setCursor(Qt::ArrowCursor);
  5350. }
  5351. */
  5352.  
  5353. void MainWindow::on_Bt_open_DIR_clicked()
  5354. {
  5355. QString s1, path1;
  5356.  
  5357. path1 = string_currentDir;
  5358.  
  5359. QProcess process1;
  5360. process1.setProgram("caja");
  5361. process1.setArguments({path1});
  5362. process1.startDetached();
  5363. }
  5364.  
  5365.  
  5366.  
  5367. void MainWindow::on_Bt_goto_clicked()
  5368. {
  5369.  
  5370. QString s1;
  5371. int n = lineEdit_7c->text().toInt();
  5372. if ((n<0) || (n>=liste_NOTES.length())) {return;}
  5373.  
  5374. spinBox_10->setValue(n);
  5375. NOTE note_i = liste_NOTES[n];
  5376.  
  5377. //double x_note = 80 + note_i.n_barreT * spinBox_dxa->value()/2.0 * zoom_x;
  5378.  
  5379. num_note_jouee = n;
  5380. surbrille_note(n, false, 1);
  5381.  
  5382. int midi = note_i.midi;
  5383. s1.setNum(midi);
  5384.  
  5385. lineEdit_7->setText(s1);
  5386. affi_txt_en_couleur(midi, lineEdit_7b); // nom de la note
  5387. //affi_txt_en_couleur(midi, lineEdit_7e);
  5388.  
  5389. // graphicsView4->horizontalScrollBar()->setValue(x_note - 200);
  5390.  
  5391. }
  5392.  
  5393.  
  5394. void MainWindow::on_doubleSpinBox_T0_valueChanged(double arg1)
  5395. {
  5396. tracer_echelle_temps_TAB_NOTES();
  5397. }
  5398.  
  5399.  
  5400. void MainWindow::on_Bt_test1_clicked()
  5401. {
  5402. QString s1;
  5403. double valeur;
  5404.  
  5405. for (int n = 0; n <= 255; n+=1)
  5406. {
  5407. valeur = (double )n / 255;
  5408. s1 = calcul_couleur(valeur);
  5409.  
  5410. rectangle1 = new QGraphicsRectItem(n, 200, 2, 5);
  5411. QPen pen1;
  5412. pen1.setColor(s1);
  5413. pen1.setWidth(2);
  5414. rectangle1->setPen(pen1);
  5415. calque_grille_M->addToGroup(rectangle1);
  5416. }
  5417. }
  5418.  
  5419.  
  5420. void MainWindow::on_Bt_durees_div2_clicked()
  5421. {
  5422. uint16_t n_max = liste_NOTES.length();
  5423. if (n_max == 0) {return;}
  5424.  
  5425. NOTE note_i;
  5426. for(int n=0; n<n_max; n++) //n_max
  5427. {
  5428. note_i=liste_NOTES[n];
  5429.  
  5430. int n_barre =note_i.n_barreT;
  5431. n_barre /=2;
  5432. note_i.n_barreT = n_barre;
  5433.  
  5434. liste_NOTES[n] = note_i;
  5435. }
  5436.  
  5437. effacer_calque(scene4,calque_notes_manuelles);
  5438. affiche_liste_notes(); // en texte
  5439. trace_liste_notes(); // ellipses
  5440. }
  5441.  
  5442.  
  5443. void MainWindow::on_Bt_durees_mult2_clicked()
  5444. {
  5445.  
  5446. uint16_t n_max = liste_NOTES.length();
  5447. if (n_max == 0) {return;}
  5448.  
  5449. NOTE note_i;
  5450. for(int n=0; n<n_max; n++) //n_max
  5451. {
  5452. note_i=liste_NOTES[n];
  5453.  
  5454. int n_barre =note_i.n_barreT;
  5455. n_barre *=2;
  5456. note_i.n_barreT = n_barre;
  5457.  
  5458. liste_NOTES[n] = note_i;
  5459. }
  5460.  
  5461. effacer_calque(scene4,calque_notes_manuelles);
  5462. affiche_liste_notes(); // en texte
  5463. trace_liste_notes(); // ellipses
  5464.  
  5465. }
  5466.  
  5467.  
  5468.  
  5469. void MainWindow::on_Bt_div2_clicked()
  5470. {
  5471. gain /=sqrt(2); // en fait / par racine carrée de deux pour plus de finesse
  5472. MainWindow::setCursor(Qt::WaitCursor);
  5473. effacer_calque(scene4, calque_TAB_FRQ);
  5474. retracer_TAB_FRQ();
  5475. MainWindow::setCursor(Qt::ArrowCursor);
  5476. }
  5477.  
  5478.  
  5479. void MainWindow::on_pushButton_clicked()
  5480. {
  5481. gain *=sqrt(2);
  5482. MainWindow::setCursor(Qt::WaitCursor);
  5483. effacer_calque(scene4, calque_TAB_FRQ);
  5484. retracer_TAB_FRQ();
  5485. MainWindow::setCursor(Qt::ArrowCursor);
  5486. }
  5487.  
  5488.  
  5489. void MainWindow::on_Bt_next_clicked()
  5490. {
  5491. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  5492. graphicsView4->horizontalScrollBar()->setValue(scroll_x + 800);
  5493.  
  5494. }
  5495.  
  5496.  
  5497. void MainWindow::on_Bt_prev_clicked()
  5498. {
  5499. double scroll_x = graphicsView4->horizontalScrollBar()->value();
  5500. graphicsView4->horizontalScrollBar()->setValue(scroll_x - 800);
  5501. }
  5502.  
  5503.  
  5504. void MainWindow::on_Bt_debut_clicked()
  5505. {
  5506. graphicsView4->horizontalScrollBar()->setValue(0);
  5507. }
  5508.  
  5509.  
  5510. void MainWindow::on_Bt_fin_clicked()
  5511. {
  5512. graphicsView4->horizontalScrollBar()->setValue(10000);
  5513. }
  5514.  
  5515.  
  5516.  
  5517. void MainWindow::on_bt_test_clicked()
  5518. {
  5519.  
  5520.  
  5521. }
  5522.  
  5523.  
  5524. void MainWindow::on_Bt_detection_notes_clicked()
  5525. {
  5526. effacer_calque(scene4,calque_notes_manuelles);
  5527. effacer_calque(scene4,calque_notes_auto);
  5528. detection_notes_auto();
  5529. on_Bt_toggle_visu_notes_clicked();
  5530.  
  5531. }
  5532.  
  5533.  
  5534. void MainWindow::on_Bt_toggle_visu_notes_auto_clicked()
  5535. {
  5536. if(visu_notes_auto == 0)
  5537. {
  5538. visu_notes_auto = 1;
  5539. Bt_toggle_visu_notes_auto->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  5540. calque_notes_auto->setVisible(true);
  5541. //detection_notes_auto();
  5542. // tri_liste_notes_par_num_barre(); //les notes seront triées par temps croissant
  5543. //numerotation_liste_notes(); //les notes seront numérotées par temps croissant
  5544. // affiche_liste_notes();
  5545. // trace_liste_notes();
  5546. }
  5547. else
  5548. {
  5549. Bt_toggle_visu_notes_auto->setStyleSheet("background-color: rgb(200, 200, 200);");
  5550. visu_notes_auto = 0;
  5551. //effacer_calque(scene4,calque_notes_auto);
  5552. calque_notes_auto->setVisible(false);
  5553. }
  5554. }
  5555.  
  5556.  
  5557. void MainWindow::on_Bt_m10_clicked()
  5558. {
  5559. doubleSpinBox_vitesse->setValue(doubleSpinBox_vitesse->value()-10);
  5560. }
  5561.  
  5562.  
  5563. void MainWindow::on_Bt_p10_clicked()
  5564. {
  5565. doubleSpinBox_vitesse->setValue(doubleSpinBox_vitesse->value()+10);
  5566. }
  5567.  
  5568.  
  5569. void MainWindow::on_doubleSpinBox_gain_valueChanged(double arg1)
  5570. {
  5571. tracer_signal_complet();
  5572. }
  5573.  
  5574.  
  5575. void MainWindow::on_Bt_test2_clicked()
  5576. {
  5577. // load fichier wav qui contient les fréquences test
  5578. // Le fichier .wav comprend un signal audio stéréo échantilloné à 48 000 octets/seconde pour chaque canal
  5579. // ce qui fait 96000 octets/s pour l'ensemble du signal stéréo
  5580.  
  5581. effacer_calque(scene1,calque_trace_signal1 );
  5582. effacer_calque(scene1,calque_trace_FFT );
  5583. effacer_calque(scene1,calque_lignes_F_zero );
  5584. effacer_calque(scene1,calque_encadrement1 );
  5585.  
  5586. string_currentFile = QDir::homePath() + "/GUITARE/ACCORDS/tonalites_midi/48 kHz/28-82.wav";
  5587. save_fichier_ini();
  5588. lineEdit_1->setText(string_currentFile);
  5589. int p1= string_currentFile.lastIndexOf('/');
  5590. string_currentDir = string_currentFile.left(p1);
  5591. lineEdit_current_dir->setText(string_currentDir);
  5592. save_fichier_ini();
  5593. file_wav.setFileName(string_currentFile);
  5594. if (!file_wav.open(QIODevice::ReadOnly))
  5595. {
  5596. wav_ok = false;
  5597. Bt_scan_auto->setStyleSheet("background-color: rgb(200, 200, 200);");
  5598. return ;
  5599. }
  5600. else
  5601. {
  5602. binStream1.setDevice(&file_wav); // accès à la totalité du fichier wav
  5603. wav_ok = true;
  5604. Bt_scan_auto->setStyleSheet("background-color: rgb(0, 255, 0);"); // vert
  5605.  
  5606. }
  5607. // le fichier reste ouvert pour toute la session
  5608.  
  5609. decode_entete();
  5610.  
  5611. MainWindow::setCursor(Qt::WaitCursor);
  5612. liste_ENR_FFT.clear();
  5613. effacer_calque(scene1,calque_trace_signal1 );
  5614. effacer_calque(scene1, calque_trace_FFT);
  5615. clear_temp_data();
  5616. garnis_temp_data(0);
  5617. // ajustement_gain();
  5618. // donne accès à la totalité (2MB) du fichier wav (dans le 'temp_data')
  5619. tracer_signal_complet();
  5620. MainWindow::setCursor(Qt::ArrowCursor);
  5621. tracer_gradu_temporelle_signal_entree();
  5622.  
  5623. // frame_3->setVisible(true);
  5624. // Bt_scan_auto->setVisible(true);
  5625. // checkBox_rapide->setVisible(true);
  5626.  
  5627.  
  5628. if ( ! liste_ENR_FFT.isEmpty()) {on_Bt_efface_clicked();}
  5629.  
  5630. spinBox_6->setValue(0);
  5631. Timer3->start(100);
  5632.  
  5633. }
  5634.  
  5635.  
  5636. void MainWindow::on_Bt_open_DIR_2_clicked()
  5637. {
  5638. on_Bt_open_DIR_clicked();
  5639. }
  5640.  
  5641.  
  5642. void MainWindow::on_spinBox_nb_barres_valueChanged(int arg1)
  5643. {
  5644. effacer_calque(scene4, calque_grille_T);
  5645. tracer_grille_T();
  5646. }
  5647.  
  5648.  
  5649. void MainWindow::on_spinBox_barre_zero_valueChanged(int arg1)
  5650. {
  5651. effacer_calque(scene4, calque_grille_T);
  5652. tracer_grille_T();
  5653. }
  5654.  
  5655.  
  5656. void MainWindow::on_pushButton_10_clicked()
  5657. {
  5658. QMessageBox msgBox;
  5659. QString s1;
  5660. s1 = "Les notes sont dans une premier temps attachées à la grille T (Temporelle, fixe, 1/40s)"; s1 += "\n";
  5661. s1 += "Ensuite la grille M (Mesures) permet"; s1 += "\n";
  5662. s1 += "de placer leur double au plus près du tempo théorique"; s1 += "\n";
  5663. s1 += "La grille M (Mesures) doit être configurée manuellement"; s1 += "\n";
  5664. s1 += "(par 'x0' et 'dt' en haut)"; s1 += "\n";
  5665. s1 += "Le bouton 'Place T->M' sert à créer ces doubles"; s1 += "\n";
  5666. s1 += "et les place automatiquement sur la barre de mesure la plus proche"; s1 += "\n";
  5667.  
  5668. s1 += ""; s1 += "\n";
  5669.  
  5670. msgBox.setText(s1);
  5671. msgBox.exec();
  5672. }
  5673.  
  5674.  
  5675. void MainWindow::on_pushButton_11_clicked()
  5676. {
  5677. QMessageBox msgBox;
  5678. QString s1;
  5679.  
  5680. s1 += "Pour déplacer une note sur la grille:"; s1 += "\n";
  5681. s1 += "1) cliquez sur la note pour la sélectionner"; s1 += "\n";
  5682. s1 += "2) cliquez sur les boutons '<' et '>' et '^' et 'v' "; s1 += "\n";
  5683. s1 += "\n";
  5684.  
  5685. s1 += ""; s1 += "\n";
  5686.  
  5687. s1 += "Pour déplacer plusieurs notes sur la grille:"; s1 += "\n";
  5688. s1 += "Cochez Sélect/boite" ; s1 += "\n";
  5689. s1 += "sélectonnez les notes par un rectangle (en déplaçant la souris avec bouton gauche restant appuyé)"; s1 += "\n";
  5690. s1 += "Puis cliquez sur les boutons '<' et '>' et '^' et 'v' "; s1 += "\n";
  5691. s1 += "Idem pour supprimer plusieurs notes, sélectionner puis clic sur le bouton 'xx' "; s1 += "\n";
  5692. s1 += "\n";
  5693.  
  5694. s1 += "Les petits tirets colorés horizontaux indiquent les Harmoniques freq x2(prem. H) et freq x3 (second H)";
  5695.  
  5696. msgBox.setText(s1);
  5697. msgBox.exec();
  5698. }
  5699.  
  5700.  
  5701.  
  5702. void MainWindow::on_Bt_RAZ_general_clicked()
  5703. {
  5704. liste_NOTES.clear();
  5705. liste_ENR_FFT.clear();
  5706. parametrages();
  5707. graphicsView4->horizontalScrollBar()->setValue(0);
  5708. }
  5709.  
  5710.  
  5711.  
  5712. void MainWindow::on_spinBox_x0a_valueChanged(int arg1)
  5713. {
  5714. effacer_calque(scene4, calque_echelle_temporelle_T);
  5715. effacer_calque(scene4, calque_echelle_temporelle_M);
  5716. effacer_calque(scene4, calque_grille_M);
  5717.  
  5718. on_Bt_copy_nt_T_to_M_clicked();
  5719.  
  5720. trace_liste_notes();
  5721. tracer_grille_M();
  5722. tracer_echelle_temps_TAB_NOTES();
  5723. }
  5724.  
  5725.  
  5726. void MainWindow::on_doubleSpinBox_x0b_valueChanged(double arg1)
  5727. {
  5728. effacer_calque(scene4, calque_echelle_temporelle_T);
  5729. effacer_calque(scene4, calque_echelle_temporelle_M);
  5730. effacer_calque(scene4, calque_grille_M);
  5731.  
  5732. on_Bt_copy_nt_T_to_M_clicked();
  5733.  
  5734. trace_liste_notes();
  5735. tracer_grille_M();
  5736. tracer_echelle_temps_TAB_NOTES();
  5737. }
  5738.  
  5739.  
  5740.  
  5741. void MainWindow::on_Bt_copy_nt_T_to_M_clicked()
  5742. {
  5743. if(checkBox_GI->isChecked()) {return;}
  5744.  
  5745. uint16_t n_max = liste_NOTES.length();
  5746. uint16_t nb_M;
  5747.  
  5748. for(int n=0; n<n_max; n++)
  5749. {
  5750. nb_M = calcul_n_barreM_note(n);
  5751. liste_NOTES[n].n_barreM = nb_M;
  5752. }
  5753. mode='M';
  5754. affiche_liste_notes();
  5755. trace_liste_notes();
  5756. }
  5757.  
  5758.  
  5759. void efface_notes_T()
  5760. {
  5761. int16_t n_max = liste_NOTES.length();
  5762. for(int n=0; n<n_max; n++)
  5763. {
  5764. liste_NOTES[n].n_barreT = 0;
  5765. }
  5766. }
  5767.  
  5768.  
  5769.  
  5770. void MainWindow::on_Bt_copy_nt_M_to_T_clicked()
  5771. {
  5772. if(checkBox_GI->isChecked()) {return;}
  5773.  
  5774. int n_max = liste_NOTES.length();
  5775. int nb_T;
  5776.  
  5777. efface_notes_T();
  5778.  
  5779. for(int n=0; n<n_max; n++)
  5780. {
  5781. nb_T = calcul_n_barreT_note(n);
  5782. //nb_T = liste_NOTES[n].n_barreM * 14 ; //8.5; // méthode directe. à voir...
  5783. if (nb_T < 5000) {liste_NOTES[n].n_barreT = nb_T;}
  5784. }
  5785. mode='T';
  5786. mode_grille_T();
  5787. affiche_liste_notes();
  5788. trace_liste_notes();
  5789. }
  5790.  
  5791.  
  5792.  
  5793. void MainWindow::on_radioButton_D_clicked()
  5794. {
  5795. affiche_histogramme();
  5796. }
  5797.  
  5798.  
  5799. void MainWindow::on_radioButton_M_clicked()
  5800. {
  5801. affiche_histogramme();
  5802. }
  5803.  
  5804.  
  5805. void MainWindow::on_radioButton_H_clicked()
  5806. {
  5807. affiche_histogramme();
  5808. }
  5809.  
  5810.  
  5811. void MainWindow::on_Bt_dedoubleM_clicked()
  5812. {
  5813. int n_max = liste_NOTES.length();
  5814. for(int n=0; n<n_max; n++)
  5815. {
  5816. liste_NOTES[n].n_barreM = liste_NOTES[n].n_barreM *2;
  5817. }
  5818. tracer_grille_M();
  5819. trace_liste_notes();
  5820.  
  5821. }
  5822.  
  5823.  
  5824. void MainWindow::on_Bt_bak1_clicked()
  5825. {
  5826.  
  5827. QString filename1 = string_currentDir+ "/BAK.NTS";
  5828. QFile file1(filename1);
  5829. if (file1.exists())
  5830. {
  5831. liste_NOTES.clear();
  5832. effacer_calque(scene4,calque_notes_manuelles);
  5833. effacer_calque(scene4,calque_notes_auto);
  5834. effacer_calque(scene4,calque_notes_jouee);
  5835. effacer_calque(scene5, calque_histogramme );
  5836. effacer_calque(scene4, calque_echelle_temporelle_T);
  5837. effacer_calque(scene4, calque_echelle_temporelle_M);
  5838.  
  5839. load_fichier_NOTES("BAK");
  5840. on_Bt_toggle_grille_M_clicked();
  5841. }
  5842. else
  5843. {
  5844. QMessageBox msgBox;
  5845. QString s1="pas de Fichier BAK.NTS !";
  5846. msgBox.setText(s1); msgBox.exec();
  5847. }
  5848. }
  5849.  
  5850.  
  5851. void MainWindow::on_checkBox_numerotation_toggled(bool checked)
  5852. {
  5853. tracer_grille_M();
  5854. }
  5855.  
  5856.  
  5857. void MainWindow::on_Bt_copie_notes_clicked()
  5858. {
  5859. write_mode = 5;
  5860. MainWindow::setCursor(Qt::CrossCursor);
  5861. // voir le write_mode 5 dans la fonction 'mousePressEvent' pour la suite évènementielle..
  5862. }
  5863.  
  5864.  
  5865. void MainWindow::on_pushButton_12_clicked()
  5866. {
  5867. QMessageBox msgBox;
  5868. QString s1;
  5869. s1 = "COPIE D'UN ACCORD (=notes alignées verticalement sur la même barre)"; s1 += "\n";
  5870. s1 += "1) cliquez sur le bouton jaune pour lancer le mode copie d'accord"; s1 += "\n";
  5871. s1 += "2) cliquez sur la barre temporelle contenant les notes de l'accord à copier"; s1 += "\n";
  5872. s1 += "3) puis cliquez sur une autre barre (destination)"; s1 += "\n";
  5873. msgBox.setText(s1);
  5874. msgBox.exec();
  5875. }
  5876.  
  5877.  
  5878.  
  5879.  
  5880. void MainWindow::on_checkBox_GI_clicked(bool checked)
  5881. {
  5882. if (checked == true)
  5883. {
  5884. Bt_copy_nt_M_to_T->setStyleSheet("background-color: rgb(100, 100, 100);");
  5885. Bt_copy_nt_T_to_M->setStyleSheet("background-color: rgb(100, 100, 100);");
  5886. }
  5887. else
  5888. {
  5889. Bt_copy_nt_M_to_T->setStyleSheet("background-color: rgb(0, 255, 0);");
  5890. Bt_copy_nt_T_to_M->setStyleSheet("background-color: rgb(0, 255, 0);");
  5891. }
  5892. }
  5893.  
  5894.  
  5895. void MainWindow::on_pushButton_13_clicked()
  5896. {
  5897. QMessageBox msgBox;
  5898. QString s1;
  5899. s1 = "Rendre les grilles M et T indépendantes permet de travailler uniquement sur la grille M"; s1 += "\n";
  5900. s1 += "par exemple pour composer un morceau ou des accords manuellement"; s1 += "\n";
  5901. s1 += "en évitant des surprises lors du changement d'échelle temporelle"; s1 += "\n";
  5902. s1 += "(Les notes resteront attachées à la même barre temporelle)"; s1 += "\n";
  5903. msgBox.setText(s1);
  5904. msgBox.exec();
  5905. }
  5906.  
  5907.  
  5908. void MainWindow::on_pushButton_14_clicked()
  5909. {
  5910. QMessageBox msgBox;
  5911. QString s1;
  5912. s1 = "La roulette de la souris permet de modifier la valeur rapidement"; s1 += "\n";
  5913. s1 += "CTRL + roulette permet encore + de rapidité"; s1 += "\n";
  5914. s1 += ""; s1 += "\n";
  5915. s1 += ""; s1 += "\n";
  5916. msgBox.setText(s1);
  5917. msgBox.exec();
  5918. }
  5919.  
  5920.  
  5921. void MainWindow::on_pushButton_15_clicked()
  5922. {
  5923. QMessageBox msgBox;
  5924. QString s1;
  5925. s1 ="Les instruments de musique ne sont pas toujours 'bien' accordés (La=440Hz) involontairement ou volontairement..."; s1 += "\n";
  5926. s1 += "Si cette appli détecte mal les frq (hésitation +/-1/2 ton) cette valeur permet d'ajuster la détection."; s1 += "\n";
  5927. s1 += "Vous trouverez aussi des notes 'pures' dans le dossier 'tonalites_midi' dans le fichier documents.zip";
  5928.  
  5929. msgBox.setText(s1);
  5930. msgBox.exec();
  5931. }
  5932.  
  5933. void MainWindow::on_spinBox_offset_valueChanged(int arg1)
  5934. {
  5935. calcul_ofsset();
  5936. traitement_signal();
  5937. }
  5938.  
  5939.  
  5940. void MainWindow::on_spinBox_echx_valueChanged(int arg1)
  5941. {
  5942. calcul_ofsset();
  5943. traitement_signal();
  5944. }
  5945.  
  5946.  
  5947.  
  5948. void MainWindow::on_Bt_par_defaut_clicked()
  5949. {
  5950. doubleSpinBox_gain->setValue(0.20);
  5951. spinBox_offset->setValue(-1250); // -1348 ; +/- 22 pour un décalage de +/-1/4 de ton
  5952. doubleSpinBox_echx->setValue(388); // 401
  5953. }
  5954.  
  5955.  
  5956. void MainWindow::on_Bt_composition_clicked()
  5957. {
  5958. spinBox_duree->setValue(1);
  5959. on_spinBox_duree_valueChanged(2);// noire
  5960. visu_freq = true;
  5961. on_Bt_toggle_visu_freq_clicked(); // ce qui le repasse à false, avec actions correspondantes
  5962.  
  5963. mode_composition = true;
  5964. on_Bt_toggle_grille_M_clicked();
  5965. frame_cle_de_sol->setVisible(true);
  5966.  
  5967. affi_clef();
  5968.  
  5969.  
  5970.  
  5971. frame_composeur->setVisible(true);
  5972.  
  5973. on_spinBox_hauteur_valueChanged(0);
  5974.  
  5975. spinBox_duree->setValue(1);
  5976. //on_spinBox_duree_valueChanged(1);
  5977. }
  5978.  
  5979.  
  5980. void MainWindow::on_pushButton_5_clicked()
  5981. {
  5982. mode_composition = false;
  5983. frame_cle_de_sol->setVisible(false);
  5984. frame_composeur->setVisible(false);
  5985. }
  5986.  
  5987.  
  5988. void MainWindow::on_spinBox_hauteur_valueChanged(int arg1)
  5989. {
  5990. if (arg1==12) { spinBox_hauteur->setValue(0); spinBox_octave->stepUp(); return;}
  5991. if (arg1==-1) { spinBox_hauteur->setValue(11); spinBox_octave->stepDown(); return;}
  5992.  
  5993. QString s1;
  5994. s1 = gamme_chromatique[spinBox_hauteur->value()];
  5995. lineEdit_nom->setText(s1);
  5996.  
  5997. int midi = 36 + arg1 + 12*spinBox_octave->value();
  5998. affi_txt_en_couleur(midi, lineEdit_nom);
  5999. s1.setNum(midi);
  6000. lineEdit_midi->setText(s1);
  6001.  
  6002. effacer_calque(scene4, calque_surbrillance);
  6003.  
  6004. surbrille_barre(num_barre_saisie, "#00FF00");
  6005. encadre_midi(midi);
  6006. }
  6007.  
  6008.  
  6009.  
  6010. void MainWindow::on_spinBox_octave_valueChanged(int arg1)
  6011. {
  6012. QString s1;
  6013. s1 = gamme_chromatique[spinBox_hauteur->value()];
  6014. lineEdit_nom->setText(s1);
  6015.  
  6016. int midi = 36 + spinBox_hauteur->value() + 12*arg1;
  6017. s1.setNum(midi);
  6018. lineEdit_midi->setText(s1);
  6019. effacer_calque(scene4, calque_surbrillance);
  6020. surbrille_barre(num_barre_saisie, "#00FF00");
  6021. encadre_midi(midi);
  6022. }
  6023.  
  6024.  
  6025.  
  6026.  
  6027.  
  6028. void MainWindow::on_spinBox_duree_valueChanged(int arg1)
  6029. {
  6030. QString s1, s2;
  6031. duree_int = pow(2, 4-arg1); // variable globale
  6032. s1.setNum(duree_int);
  6033. lineEdit_duree_int->setText(s1);
  6034.  
  6035. if (! checkBox_silence->isChecked()) {s2 = types_note[arg1];}
  6036. else
  6037. {
  6038. s2 = types_silence[arg1];
  6039. affi_silence();
  6040. }
  6041.  
  6042. lineEdit_duree_txt->setText(s2);
  6043. surbrille_barre(num_barre_saisie, "#00FF00");
  6044. }
  6045.  
  6046.  
  6047. void MainWindow::on_pushButton_16_clicked()
  6048. {
  6049. QMessageBox msgBox;
  6050. QString s1;
  6051. s1 = "Le trait vertical (vert) indique la barre ou se placera la note suivante ";
  6052. s1 += "(en fonction de la durée choisie pour la note précédente)"; s1 += "\n";
  6053. s1 += "La durée des notes n'est (volontairement) pas enregistrée dans les notes ";
  6054. s1 += "ce qui permet de ne PAS affecter l'emplacement de toutes les notes ";
  6055. s1 += "dans la trame temporelle lors de la modification, l'ajout ou la suppression d'une note"; s1 += "\n";
  6056. s1 += "Le tempo et le rythme sont ainsi conservés."; s1 += "\n";
  6057. s1 += "C'est d'ailleurs (me semble-t-il) l'approche retenue dans la norme midi."; s1 += "\n";
  6058. s1 += "On peut à tout moment ajouter 'manuellement' une note avec le bouton 'W' du panneau Gestion notes"; s1 += "\n";
  6059. s1 += "Ce qui fait basculer dans le mode Write, puis clic sur la grille"; s1 += "\n";
  6060. msgBox.setText(s1);
  6061. msgBox.exec();
  6062. }
  6063.  
  6064.  
  6065. void MainWindow::Ajouter_note(int midi)
  6066. {
  6067. if (checkBox_pause->isChecked()) {midi =0;}
  6068. ajout_note(midi, 0, num_barre_saisie);
  6069. play_note(midi);
  6070.  
  6071. //int d1 = 4 - spinBox_duree->value();
  6072. //int d2 = pow(2, d1);
  6073. num_barre_saisie += duree_int;
  6074.  
  6075. effacer_calque(scene4,calque_notes_manuelles);
  6076. //effacer_calque(scene4,calque_notes_jouee);
  6077. tri_liste_notes_par_num_barre(); // les notes seront triées par num_barre croissant
  6078. numerotation_liste_notes(); // les notes seront numérotées par num_barre croissant
  6079. affiche_liste_notes();
  6080. trace_liste_notes();
  6081. surbrille_barre(num_barre_saisie, "#00FF00");
  6082. spinBox_num_barre->setValue(num_barre_saisie);
  6083. }
  6084.  
  6085.  
  6086.  
  6087. void MainWindow::on_Bt_ajout_clicked()
  6088. {
  6089. if(!checkBox_silence->isChecked())
  6090. {
  6091. int midi = 36 + spinBox_hauteur->value() + 12*spinBox_octave->value();
  6092. Ajouter_note(midi);
  6093.  
  6094. }
  6095. else
  6096. {
  6097. //n'ajoute pas de note, décalle juste la barre de saisie de la note suivante vers la droite
  6098. num_barre_saisie += duree_int;
  6099. surbrille_barre(num_barre_saisie, "#00FF00");
  6100. }
  6101. }
  6102.  
  6103.  
  6104.  
  6105. void MainWindow::on_Bt_aj_MAJ_clicked()
  6106. {
  6107. int tonique = 36 + spinBox_hauteur->value() + 12*spinBox_octave->value();
  6108. int A = tonique;
  6109. int B = tonique +4;
  6110. int C = tonique +7;
  6111.  
  6112. Ajouter_note(A);
  6113. num_barre_saisie -= duree_int; Ajouter_note(B);
  6114. num_barre_saisie -= duree_int; Ajouter_note(C);
  6115. }
  6116.  
  6117.  
  6118. void MainWindow::on_Bt_aj_Min_clicked()
  6119. {
  6120. int tonique = 36 + spinBox_hauteur->value() + 12*spinBox_octave->value();
  6121. int A = tonique;
  6122. int B = tonique +3;
  6123. int C = tonique +7;
  6124.  
  6125. Ajouter_note(A);
  6126. num_barre_saisie -= duree_int; Ajouter_note(B);
  6127. num_barre_saisie -= duree_int; Ajouter_note(C);
  6128. }
  6129.  
  6130.  
  6131. void MainWindow::on_Bt_aj_7dom_clicked()
  6132. {
  6133. int tonique = 36 + spinBox_hauteur->value() + 12*spinBox_octave->value();
  6134. int A = tonique;
  6135. int B = tonique +4;
  6136. int C = tonique +7;
  6137. int D = tonique +10;
  6138.  
  6139. Ajouter_note(A);
  6140. num_barre_saisie -= duree_int; Ajouter_note(B);
  6141. num_barre_saisie -= duree_int; Ajouter_note(C);
  6142. num_barre_saisie -= duree_int; Ajouter_note(D);
  6143. }
  6144.  
  6145.  
  6146.  
  6147. void MainWindow::on_Bt_transposer_clicked()
  6148. {
  6149. int n_max = liste_NOTES.length();
  6150. for(int n=0; n<n_max; n++)
  6151. {
  6152. liste_NOTES[n].midi += spinBox_transposition->value();
  6153. }
  6154. affiche_liste_notes();
  6155. trace_liste_notes();
  6156. }
  6157.  
  6158.  
  6159. /*
  6160. void MainWindow::on_Bt_deselect_clicked()
  6161. {
  6162.   deselect_notes();
  6163.   effacer_calque(scene4, calque_surbrillance);
  6164.   effacer_calque(scene4, calque_notes_jouee);
  6165.   effacer_calque(scene4, calque_rect_select);
  6166. }
  6167. */
  6168.  
  6169.  
  6170. void MainWindow::on_checkBox_sel_boite_clicked()
  6171. {
  6172. if(checkBox_sel_boite->isChecked())
  6173. {
  6174. Bt_mode_E->setVisible(false);
  6175. frame_move->setVisible(true);
  6176. label_SEL_P_BOITE->setVisible(true);
  6177. Bt_mode_E_2->setStyleSheet("background-color: rgb(255, 0, 0);"); // rouge
  6178. }
  6179. else
  6180. {
  6181. Bt_mode_E->setVisible(true);
  6182. frame_move->setVisible(false);
  6183. label_SEL_P_BOITE->setVisible(false);
  6184. Bt_mode_E_2->setStyleSheet("background-color: rgb(200, 200, 200);"); // gris
  6185. effacer_calque(scene4, calque_rect_select);
  6186. deselect_notes();
  6187. effacer_calque(scene4, calque_notes_jouee);
  6188.  
  6189. }
  6190. }
  6191.  
  6192.  
  6193. void MainWindow::affi_clef()
  6194. {
  6195. QString image_filename;
  6196. QImage image1;
  6197. image_filename = "./cles3r.jpg";
  6198. image1.load(image_filename);
  6199.  
  6200. label_image1->setGeometry(0, 0, 131, 101);
  6201. label_image1->setPixmap(QPixmap::fromImage(image1));
  6202. label_image1->adjustSize();
  6203. }
  6204.  
  6205.  
  6206. void MainWindow::affi_silence()
  6207. {
  6208. QString image_filename;
  6209. QString s1;
  6210.  
  6211. int n =spinBox_duree->value();
  6212.  
  6213. s1.setNum(n);
  6214. QImage image1;
  6215.  
  6216. image_filename = "./silence" + s1 + ".jpg";
  6217. image1.load(image_filename);
  6218.  
  6219. label_image1->setGeometry(20, 100, 131, 101);
  6220. label_image1->setPixmap(QPixmap::fromImage(image1));
  6221. label_image1->adjustSize();
  6222.  
  6223. }
  6224.  
  6225.  
  6226.  
  6227. void MainWindow::on_checkBox_silence_clicked()
  6228. {
  6229. if(checkBox_silence->isChecked()) { affi_silence(); } else { affi_clef(); }
  6230. on_spinBox_duree_valueChanged(spinBox_duree->value());
  6231. }
  6232.  
  6233.  
  6234. void MainWindow::on_spinBox_num_barre_valueChanged(int arg1)
  6235. {
  6236. num_barre_saisie = arg1;
  6237. surbrille_barre(num_barre_saisie, "#00FF00");
  6238. }
  6239.  
  6240.  
  6241. void MainWindow::on_spinBox_num_note_valueChanged(int arg1)
  6242. {
  6243. num_note_jouee = arg1;
  6244. spinBox_10->setValue(num_note_jouee); // 'debut'
  6245. joue_1_note_de_la_liste();
  6246. }
  6247.  
  6248.  

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 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; code midi. (et =0 pour un silence)
  43. int16_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. uint8_t statut; // 1 octet (8 bits); statut[0] -> selected
  46. // total 8 octets
  47. };
  48.  
  49.  
  50.  
  51. /* FFT */
  52.  
  53. class MainWindow : public QMainWindow, public Ui::MainWindow
  54. {
  55. Q_OBJECT
  56.  
  57. public:
  58. explicit MainWindow(QWidget *parent = 0);
  59. ~MainWindow();
  60.  
  61. protected:
  62.  
  63. void mousePressEvent(QMouseEvent *event);
  64. void mouseReleaseEvent(QMouseEvent *event);
  65.  
  66. void mouseMoveEvent(QMouseEvent *event);
  67. void contextMenuEvent(QContextMenuEvent *event); // clic de droite
  68.  
  69.  
  70. private slots:
  71. void Tic1();
  72. void Tic2();
  73. void Tic3();
  74. void save_fichier_ini();
  75. void load_fichier_ini();
  76. void choix_dossier_de_travail();
  77. void open_fichier_wav();
  78.  
  79. void on_Bt_load_wav_clicked();
  80. void ajustement_gain();
  81. void load_fichier_FRQ();
  82. int save_fichier_FRQ(QString date_i);
  83. void load_fichier_NOTES(QString s0);
  84. int save_fichier_NOTES(QString date_i);
  85.  
  86. void decode_entete();
  87. void garnis_temp_data(qint32 offset);
  88.  
  89. void parametrages();
  90. void init_TW_1();
  91. void init_TAB_FRQ();
  92. void init_TAB_lst_notes();
  93. void init_TW_type_M();
  94. void init_Autres();
  95.  
  96. void Etiquette(int x, int dx, int y, QString s, QString coul_txt, QString coul_fond, QString coul_cadre , QGraphicsItemGroup *calque_i);
  97.  
  98. void afficher_titre_calque(QString titre, int x, int y, QGraphicsItemGroup *calque_i);
  99. void tracer_graduations_signal();
  100. void tracer_graduations_FFT(); // sur onglet 'Source wav'
  101. void tracer_signal_complet(); // sur onglet 'Source wav'
  102. void tracer_gradu_temporelle_signal_entree(); // sur onglet 'Source wav'
  103. void tracer_signal_a_convertir(); // sur onglet 'Source wav'
  104. void tracer_graduation_TAB_NOTES(); // midi ; en colonne à gauche + noms des notes
  105. void tracer_echelle_temps_TAB_NOTES(); //en secondes (scene4 sur l'onglet NOTES)
  106. void tracer_grille_M();
  107. void tracer_grille_T();
  108. double calcul_pas_grille();
  109. //double calcul_pas_grille_M();
  110. double calcul_x_barre(int n_barre);
  111. int calcul_tempo();
  112. //double calcul_x_barre_M(int n_barre);
  113. void trace_1_barre_M(double xi, QString couleur_i);
  114. void tracer_1enr(ENR_FFT enr_i);
  115. void detection_notes_auto(); // notes secondaires (affi par petits cercles colorés)
  116. void retracer_TAB_FRQ();
  117. void maj_TAB_NOTES();
  118.  
  119. void encadrement_signal(int x, int dx);
  120. void encadrement_note(int n_midi);
  121. void encadre_midi(int n_midi);
  122. int calcul_num_midi(double x);
  123. void tracer_segments_FFT();
  124.  
  125. void complete_case(int row, int column, QString s1, QString c1, QString c2, bool bold1, QTableWidget *QTI);
  126. void affiche_liste_notes();
  127. void trace_liste_notes(); //dessine des cercles colorés (couleur midi) sur la grille
  128. void deselect_notes();
  129.  
  130.  
  131. void calcul_histogramme_durees();
  132. void affiche_histogramme_durees();
  133.  
  134. void calcul_histogramme_midi();
  135. void affiche_histogramme_midi();
  136.  
  137. void calcul_histogramme_degre(); // degrés de la gamme chromatique = 1..12
  138. void affiche_histogramme_degre();
  139.  
  140. void affiche_histogramme();
  141.  
  142. QString denombre_diezes_a_la_cle();
  143. int test_if_note_in_liste(int16_t n_barre, int midi);
  144. void affi_txt_en_couleur(int midi_i, QLineEdit *lineEdit_i);
  145.  
  146. int recherche_note(double y_i);
  147. void recherche_notes_rect();
  148. int num_barre(double xi);
  149. void ajout_note(int midi, int n_barreT, int n_barreM);
  150. void deplace_note(int num, int DG, int HB);
  151. void duplique_notes(int n_barreM_1, int n_barreM_2, int nombre);
  152. void supprime_note(int16_t n);
  153. uint16_t calcul_n_barreM_note(uint16_t n); // barre M la plus proche de la note posée sur une barre T
  154. uint16_t calcul_n_barreT_note(uint16_t n); // barre T la plus proche de la note posée sur une barre M
  155.  
  156. void remplir_tableau_echantillons_signal();
  157. void calcul_compression();
  158. void bit_reverse_tableau_X();
  159.  
  160. int calcul_y_note(int midi); // en pixels sur la grille
  161. int calcul_hauteur_note(int mid);
  162. void calcul_tableau_W();
  163. void calcul_FFT();
  164. void calcul_ofsset();
  165. void traitement_signal();
  166. void analyse_tout();
  167. QString nom_note(int mid);
  168. QString nom_note_GB(int mid);
  169. QString nom_octave_GB(int mid);
  170.  
  171. void affi_details_note(int midi);
  172.  
  173. void numerotation_liste_notes();
  174. void tri_liste_notes_par_num_barre();
  175. void suppression_notes_invalides();
  176. void suppression_mesures();
  177.  
  178. void play_note(int midi);// sortie audio
  179. int joue_1_note_de_la_liste();
  180. // void surbrille_barre(num_barre);
  181. void surbrille_note(uint16_t n, bool HRM, int type);
  182. void surbrille_barre(int n_barre, QString couleur);
  183. void encadre_groupe_notes(int n_barre_i, int nombre);
  184. void trace_time_line();
  185.  
  186. void effacer_calque(QGraphicsScene *scene_i, QGraphicsItemGroup *calque_i);
  187.  
  188. void mode_grille_T();
  189. void mode_grille_M();
  190.  
  191. void on_spinBox_1_valueChanged(int arg1);
  192. void on_spinBox_2_valueChanged(int arg1);
  193. void on_spinBox_3_valueChanged(int arg1);
  194. void on_spinBox_4_valueChanged(int arg1);
  195. void on_spinBox_5_valueChanged(int arg1);
  196. void on_spinBox_6_valueChanged();
  197. void on_spinBox_7_valueChanged(int arg1);
  198. void on_pushButton_8_clicked();
  199. void on_doubleSpinBox_1_valueChanged();
  200. void on_Bt_RAZ_clicked();
  201. void on_Bt_scan_auto_clicked();
  202. void on_pushButton_2_clicked();
  203. void on_Btn_52_clicked();
  204. void on_Btn_94_clicked();
  205. void on_pushButton_3_clicked();
  206. void on_Bt_close_entete_clicked();
  207. void on_pushButton_6_clicked();
  208. void on_Bt_efface_clicked();
  209. //void on_pushButton_5_clicked();
  210. void on_checkBox_rapide_stateChanged(int arg1);
  211. void on_doubleSpinBox_seuil_valueChanged(double arg1);
  212. void on_checkBox_norm_clicked();
  213. void on_Bt_jouer_tout_clicked();
  214. void on_Bt_toggle_grille_T_clicked();
  215. void on_Bt_toggle_grille_M_clicked();
  216. void on_Bt_toggle_visu_notes_clicked();
  217. void on_Bt_save_notes_clicked();
  218. void on_Bt_load_notes_clicked();
  219. void on_Bt_joue_passage_clicked();
  220. void on_Bt_joue_wav_clicked();
  221. void on_Btn_RAZ_notes_clicked();
  222. void on_Bt_mode_R_clicked();
  223. void on_Bt_mode_W_clicked();
  224. void on_Bt_toggle_visu_freq_clicked();
  225. void on_Bt_efface_2_clicked();
  226. void on_Bt_copy_nt_T_to_M_clicked();
  227. void on_Bt_copy_nt_M_to_T_clicked();
  228. void on_Bt_joue_wav_2_clicked();
  229. void on_Bt_choix_current_dir_clicked();
  230. void on_pushButton_9_clicked();
  231. void on_Bt_load_FREQ_clicked();
  232. void on_Bt_decale_notes_L_clicked();
  233. void on_Bt_decale_notes_R_clicked();
  234. void on_tableWidget_type_M_cellClicked(int row, int column);
  235. void on_checkBox_flitrer_clicked();
  236. void on_Bt_open_DIR_clicked();
  237. void on_Bt_goto_clicked();
  238.  
  239. void on_bt_test_clicked();
  240. void on_Bt_test1_clicked();
  241. void on_Bt_test2_clicked();
  242.  
  243. void on_Bt_div2_clicked();
  244. void on_pushButton_clicked();
  245. void on_Bt_next_clicked();
  246. void on_Bt_prev_clicked();
  247. void on_Bt_debut_clicked();
  248. void on_Bt_fin_clicked();
  249. void on_Bt_durees_div2_clicked();
  250. void on_Bt_durees_mult2_clicked();
  251. void on_Bt_detection_notes_clicked();
  252. void on_Bt_toggle_visu_notes_auto_clicked();
  253. void on_Bt_m10_clicked();
  254. void on_Bt_p10_clicked();
  255. void on_doubleSpinBox_gain_valueChanged(double arg1);
  256.  
  257. void on_Bt_open_DIR_2_clicked();
  258. void on_spinBox_nb_barres_valueChanged(int arg1);
  259. void on_spinBox_barre_zero_valueChanged(int arg1);
  260. void on_pushButton_10_clicked();
  261. void on_Bt_mode_E_clicked();
  262. void on_Bt_RAZ_general_clicked();
  263. void on_Bt_deplace_L_clicked();
  264. void on_Bt_deplace_R_clicked();
  265. void on_doubleSpinBox_dxb_valueChanged(double arg1);
  266. void on_pushButton_11_clicked();
  267. void on_radioButton_D_clicked();
  268. void on_radioButton_M_clicked();
  269. void on_radioButton_H_clicked();
  270. void on_Btn_RAZ_notes_2_clicked();
  271. void on_Bt_dedoubleM_clicked();
  272. void on_Bt_bak1_clicked();
  273. void on_Bt_mode_E_2_clicked();
  274. void on_checkBox_numerotation_toggled(bool checked);
  275. void on_Bt_copie_notes_clicked();
  276. void on_pushButton_12_clicked();
  277. void on_doubleSpinBox_x0_valueChanged(double arg1);
  278. void on_doubleSpinBox_T0_valueChanged(double arg1);
  279. void on_spinBox_8_textChanged();
  280. void on_doubleSpinBox_t0_valueChanged();
  281. void on_spinBox_offset_valueChanged();
  282. void on_spinBox_zoom_2_valueChanged(int arg1);
  283. void on_spinBox_d_barres_valueChanged();
  284. void on_spinBox_x0a_valueChanged(int arg1);
  285. void on_doubleSpinBox_x0b_valueChanged(double arg1);
  286. void on_spinBox_dxa_valueChanged(int arg1);
  287. void on_checkBox_GI_clicked(bool checked);
  288. void on_pushButton_13_clicked();
  289. void on_pushButton_14_clicked();
  290.  
  291. void on_spinBox_offset_valueChanged(int arg1);
  292. void on_pushButton_15_clicked();
  293. void on_spinBox_echx_valueChanged(int arg1);
  294. void on_Bt_deplace_H_clicked();
  295. void on_Bt_deplace_B_clicked();
  296. void on_Bt_par_defaut_clicked();
  297.  
  298. void on_Bt_composition_clicked();
  299. void on_pushButton_5_clicked();
  300. void on_spinBox_hauteur_valueChanged(int arg1);
  301. void on_spinBox_octave_valueChanged(int arg1);
  302. void Ajouter_note(int midi);
  303. void on_Bt_ajout_clicked();
  304. void on_spinBox_duree_valueChanged(int arg1);
  305. void on_pushButton_16_clicked();
  306. void on_Bt_aj_MAJ_clicked();
  307. void on_Bt_aj_Min_clicked();
  308. void on_Bt_aj_7dom_clicked();
  309.  
  310. void on_Bt_transposer_clicked();
  311.  
  312. // void on_Bt_deselect_clicked();
  313.  
  314. void on_checkBox_sel_boite_clicked();
  315.  
  316. void affi_clef();
  317. void affi_silence();
  318.  
  319. void on_checkBox_silence_clicked();
  320.  
  321. void on_spinBox_num_barre_valueChanged(int arg1);
  322.  
  323. void on_spinBox_num_note_valueChanged(int arg1);
  324.  
  325. private:
  326.  
  327. QPoint Zoom_point2_;
  328.  
  329. // QImage image1;
  330.  
  331. QGraphicsScene *scene1; // sur l'onglet 'Source' - Trace FFT
  332. QGraphicsItemGroup *calque_reticule1;
  333. QGraphicsItemGroup *calque_trace_signal1;
  334. QGraphicsItemGroup *calque_trace_FFT;
  335. QGraphicsItemGroup *calque_curseur;
  336. QGraphicsItemGroup *calque_encadrement1;
  337. QGraphicsItemGroup *calque_lignes_F_zero;
  338.  
  339. QGraphicsScene *scene2; // sur l'onglet 'Source' - Signal d'entrée
  340. QGraphicsItemGroup *calque_reticule2;
  341. QGraphicsItemGroup *calque_encadrement2;
  342. QGraphicsItemGroup *calque_trace_signal2;
  343.  
  344. QGraphicsScene *scene3;
  345. QGraphicsItemGroup *calque_gradu_TAB_FRQ;
  346.  
  347. QGraphicsScene *scene4; // sur l'onglet 'NOTES'
  348. QGraphicsItemGroup *calque_TAB_FRQ;
  349.  
  350. QGraphicsScene *scene5; // sur l'onglet 'NOTES'
  351. QGraphicsItemGroup *calque_histogramme;
  352.  
  353. QGraphicsItemGroup *calque_grille_T;
  354. QGraphicsItemGroup *calque_grille_M;
  355. QGraphicsItemGroup *calque_echelle_temporelle_T; // pour grille T
  356. QGraphicsItemGroup *calque_echelle_temporelle_M; // pour grille M
  357. QGraphicsItemGroup *calque_notes_manuelles;
  358. QGraphicsItemGroup *calque_notes_auto;
  359. QGraphicsItemGroup *calque_notes_jouee;
  360. QGraphicsItemGroup *calque_surbrillance;
  361. QGraphicsItemGroup *calque_rect_select;
  362.  
  363. QGraphicsLineItem *ligne1;
  364. QGraphicsLineItem *segment_trace;
  365. QGraphicsLineItem *segment_trace2;
  366. QGraphicsRectItem *rectangle1;
  367. QGraphicsRectItem *rectangle2;
  368. QGraphicsEllipseItem *ellipse1;
  369. QGraphicsRectItem *rect1;
  370. QGraphicsRectItem *rect2;
  371. QGraphicsRectItem *rect3;
  372.  
  373. QGraphicsTextItem *GraphicsTextItem;
  374.  
  375. QMediaPlayer *player1;
  376. QMediaPlayer *player2;
  377. QMediaPlayer *player3;
  378. QMediaPlayer *player4;
  379. QMediaPlayer *player5;
  380.  
  381. QAudioOutput *audioOutput1;
  382. QAudioOutput *audioOutput2;
  383. QAudioOutput *audioOutput3;
  384. QAudioOutput *audioOutput4;
  385. QAudioOutput *audioOutput5;
  386.  
  387. QTimer *Timer1; // pour analyse auto à faible vitesse
  388. QTimer *Timer2; // pour rejouer les notes détectées
  389. QTimer *Timer3; // pour tests
  390.  
  391. };
  392.  
  393.  
  394.  
  395. #endif // MAINWINDOW_H
  396.  

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.  

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


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

12 Nouvelle version très prochainement !

12 juin 2025 : Vous l'aurez sans doute remarqué en voyant défiler les numéros de version : je publie presque quotidiennement de nouvelles versions de ces deux programmes.

Aujourd’hui je prends la plume pour vous annoncer que je suis en train de fusionner ces deux programmes en un seul, qui reprendra la totalité des fonctions de chacun d'eux, accessibles par trois onglets de la fenêtre principale :
  • premier onglet : Fonctions d'acquisition et transformée de Fourier
  • deuxième onglet : GESTION DES NOTES sur les grilles temporelles, avec possibilité d'ajout et de suppression manuelle
  • troisième onglet : INSTRUMENTS : Clavier et Guitare

Le tout en inter-connexion permanente, opérant sur les mêmes données communes.
Je vous avoue que cela ne se fait pas tout seul, interconnexion ne signifie pas fusionner simplement les codes sources...
Des variables globales, des fonctions, des widgets, homonymes mais différents, ne peuvent pas cohabiter, il faut renommer beaucoup de choses, puis assurer rigoureusement les échanges d'informations.

C'est passionnant mais demande pas mal de temps. Toutefois j'y travaille depuis plusieurs jours et cette nouvelle application est bien avancée.

13 Documents

Important : Le dossier 'notes2' contenant les échantillons audios des notes midi (midi 28 à 82) 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. Idem pour les images 'cle3.jpg'

14 -

Liens...

878