Skip to content

Commit 08b0cfc

Browse files
Chaircrusherakx
authored andcommittedFeb 13, 2020
ENH: Add flac reading and writing
1 parent f1bb901 commit 08b0cfc

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed
 

‎Control.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bool Control::set_input_filename(string filename,FILE_TYPE intype){
6262
if (intype==FILE_VORBIS) ai=new VorbisInputS;
6363
if (intype==FILE_MP3) ai=new MP3InputS;
6464
if (intype==FILE_WAV) ai=new AInputS;
65+
if (intype==FILE_FLAC) ai=new AInputS;
6566
if (!ai) return false;
6667
wavinfo.filename=filename;
6768
wavinfo.intype=intype;

‎GUI.fl

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
# data file for the Fltk User Interface Designer (fluid)
2-
version 1.0110
3-
header_name {.h}
2+
version 1.0110
3+
header_name {.h}
44
code_name {.cxx}
55
decl {//Copyright (c) Nasca Octavian Paul. Released under GNU General Public License version 2} {public
6-
}
6+
}
77

8-
decl {\#include <FL/Fl_File_Chooser.H>} {}
8+
decl {\#include <FL/Fl_File_Chooser.H>} {}
99

1010
decl {\#include <FL/Fl_Box.H>} {public
11-
}
11+
}
1212

1313
decl {\#include <FL/Fl_Group.H>} {public
14-
}
14+
}
1515

1616
decl {\#include <FL/Fl_Box.H>} {public
17-
}
17+
}
1818

1919
decl {\#include <FL/fl_draw.H>} {public
20-
}
20+
}
2121

2222
decl {\#include <FL/Fl_Value_Input.H>} {public
23-
}
23+
}
2424

2525
decl {\#include <FL/fl_ask.H>} {public
26-
}
26+
}
2727

28-
decl {\#include<sys/stat.h>} {}
28+
decl {\#include<sys/stat.h>} {}
2929

30-
decl {\#include <stdio.h>} {}
30+
decl {\#include <stdio.h>} {}
3131

32-
decl {\#include <string>} {}
32+
decl {\#include <string>} {}
3333

34-
decl {\#include <math.h>} {}
34+
decl {\#include <math.h>} {}
3535

3636
decl {\#include "Control.h"} {public
37-
}
37+
}
3838

3939
decl {\#include "FreeEditUI.h"} {public
40-
}
40+
}
4141

4242
decl {\#include "version.h"} {public
43-
}
43+
}
4444

4545
Function {hex4n(char c)} {return_type int
4646
} {
@@ -49,7 +49,7 @@ if ((c>='0')&&(c<='9')) return (c-'0');
4949
if ((c>='A')&&(c<='F')) return (c-'A')+10;
5050

5151
return 0;} {}
52-
}
52+
}
5353

5454
Function {unescape(std::string s)} {return_type {std::string}
5555
} {
@@ -73,7 +73,7 @@ while (sk<slen){
7373

7474
//printf("%s\\n%s\\n",s.c_str(),result.c_str());
7575
return result;} {}
76-
}
76+
}
7777

7878
class DDBox {: {public Fl_Box}
7979
} {
@@ -99,7 +99,7 @@ return Fl_Box::handle(event);} {}
9999
}
100100
decl {bool new_drag_file;} {public
101101
}
102-
}
102+
}
103103

104104
class GUI {open
105105
} {
@@ -122,6 +122,7 @@ set_mode(STOP);} {}
122122
FILE_TYPE intype=FILE_WAV;
123123
if ((strcmp(ext,".ogg")==0)||(strcmp(ext,".OGG")==0)||(strcmp(ext,".Ogg")==0)) intype=FILE_VORBIS;
124124
if ((strcmp(ext,".mp3")==0)||(strcmp(ext,".MP3")==0)||(strcmp(ext,".Mp3")==0)) intype=FILE_MP3;
125+
if ((strcmp(ext,".flac")==0)||(strcmp(ext,".FLAC") == 0)) intype = FILE_FLAC;
125126
bool result=control.set_input_filename(filename,intype);
126127
if (result) {
127128
infilename_output->copy_label(control.get_input_filename_and_info().c_str());
@@ -140,7 +141,7 @@ render_percent_slider->activate();
140141
cancel_render_button->activate();
141142
//char defaultfile[FL_PATH_MAX];
142143
//fl_filename_absolute(defaultfile,control.get_recommanded_output_filename().c_str());
143-
Fl_File_Chooser *fc=new Fl_File_Chooser(NULL,"Wave files (*.wav)\\tOgg Vorbis (*.ogg)",Fl_File_Chooser::CREATE,"Render to audio file...");
144+
Fl_File_Chooser *fc=new Fl_File_Chooser(NULL,"Wave files (*.wav)\\tOgg Vorbis (*.ogg)\\tFLAC (*.flac)",Fl_File_Chooser::CREATE,"Render to audio file...");
144145

145146
fc->preview(0);
146147
fc->filter_value(0);
@@ -151,7 +152,7 @@ while (fc->visible()){
151152
};
152153

153154
const char *newfile = fc->value();
154-
if (newfile != NULL) {
155+
if (newfile != NULL) {
155156
if (file_exists(newfile)){
156157
if (!fl_choice("The file exists. \\nOverwrite it?","No","Yes",NULL)) return;
157158
};
@@ -200,10 +201,10 @@ rendering=false;} {}
200201
} {
201202
MenuItem {} {
202203
label {Open audio file...}
203-
callback {char *newfile = fl_file_chooser("Open Audio(ogg,wav,mp3) File?", NULL, NULL);
204+
callback {char *newfile = fl_file_chooser("Open Audio(ogg,wav,mp3,flac) File?", NULL, NULL);
204205
if (newfile != NULL) {
205206
open_input_file(newfile);
206-
207+
207208
};
208209
selection_pos1->value(0.0);
209210
selection_pos2->value(100.0);
@@ -225,7 +226,7 @@ render();}
225226
if (newfile != NULL) {
226227
set_mode(STOP);
227228
control.stopplay();
228-
229+
229230
if (!control.load_parameters(newfile)){
230231
fl_alert("Error: Could not load parameter file:\\n%s",newfile);
231232
};
@@ -805,14 +806,14 @@ control.stopplay();}
805806
play_button->labelcolor(FL_BLACK);
806807
//mode_choice->activate();
807808
break;
808-
809+
809810
case PLAY:
810811
play_button->labelcolor(FL_RED);
811812
//mode_choice->deactivate();
812813
fftsize_slider->labelcolor(FL_BLACK);
813814
freeze_button->activate();
814815
break;
815-
816+
816817
case FREEZE:
817818
if (control.is_freeze()) freeze_button->labelcolor(FL_GREEN);
818819
else freeze_button->labelcolor(FL_BLACK);
@@ -836,7 +837,7 @@ resolution_box->copy_label(control.get_fftresolution_info().c_str());
836837

837838
bool may_render=false;
838839
if (infilename_output->label()!=NULL){
839-
if (strlen(infilename_output->label())!=0)
840+
if (strlen(infilename_output->label())!=0)
840841
may_render=true;
841842
};
842843
if (!rendering){//do not change the status of render button while rendering
@@ -938,7 +939,7 @@ Fl::add_timeout(1.0/3.0,tick,v);//3 fps} {}
938939
decl {bool playing_for_button;} {}
939940
decl {bool rendering;} {}
940941
decl {bool eof_for_button;} {}
941-
}
942+
}
942943

943944
Function {file_exists(const char *filename)} {return_type bool
944945
} {
@@ -947,7 +948,7 @@ int i = stat ( filename, &buf );
947948
// File exists
948949
if ( i == 0 ) return true;
949950
else return false;} {}
950-
}
951+
}
951952

952953
Function {main(int argc, char *argv[])} {open return_type int
953954
} {
@@ -970,4 +971,4 @@ Fl::run();
970971
delete gui;
971972

972973
return 0;} {}
973-
}
974+
}

‎globals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void sleep(int ms);
2929
#define ZERO(data,size) {char *data_=(char *) data;for (int i=0;i<size;i++) data_[i]=0;};
3030

3131
enum FILE_TYPE{
32-
FILE_WAV,FILE_VORBIS,FILE_MP3
32+
FILE_WAV,FILE_VORBIS,FILE_MP3,FILE_FLAC
3333
};
3434

3535

0 commit comments

Comments
 (0)
Please sign in to comment.