-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMelt.cpp
1939 lines (1598 loc) · 46.4 KB
/
Melt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
--------------------------------------------------------------------------------
Melt - A GUI Frontend for CDR Tools
©2000 Lukas Hartmann / Atomatrix
--------------------------------------------------------------------------------
Atomatrix Open Source License v1.0 [AOSL1]
--------------------------------------------------------------------------------
Terms and Conditions
Copyright 2000, Lukas Hartmann of Atomatrix. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software with limited restriction, including the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software as
long as there is no profit made by doing so, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
LUKAS HARTMANN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
Your Contact: Lukas Hartmann, atomatrix@gmx.de
http://www.atomatrix.com
Please be aware that some parts of this code are really shitty, because I'm
really lazy sometimes ;)
So Long, And Thanks For All The Fish!
*/
/*
fixed binary paths for Haiku. Note that THIS BREAKS BeOS R5 COMPATIBILITY
-- 2009-11-08 Matthias Rampke
*/
#define MELT_SIG "application/x-vnd.atomatrix-melt"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <AppKit.h>
#include <InterfaceKit.h>
#include <StorageKit.h>
#include "StyleUtils.h"
#include "Melt_List.h"
#include "Melt_Burn.h"
#include "Melt_NewProject.h"
#include "Melt_VirtualCD.h"
#include "Melt_App.h"
int scrw=1024;
int scrh=768;
int winw=400;
int winh=400;
char Possible_Devices[20*7];
bool DO_LOG=false;
bool MELT_MULTISESSION=false;
int MELT_CDTYPE=0; // 0: ISO Data, 1: Audio
char* MELT_FIX="";
char* MELT_DUMMY="";
char* MELT_DEVICE;
char* MELT_PATH;
char MELT_RELOCATE[2048];
int MELT_SPEED=1;
int MELT_CDSIZE=0;
#define BLANK_MODE_MAX 4
char* BLANK_MODE[BLANK_MODE_MAX]={"Full","Fast (TOC,TMA,pregap)","Blank last session","Unclose last session"};
char* BLANK_CMD[BLANK_MODE_MAX]={"all","fast","session","unclose"};
int MELT_BLANKMODE=0;
bool is_saved=false;
bool Global_Pattern=false;
// Debugging -----------------------------------
void Log(char* text)
{
if (!DO_LOG) return;
FILE* logfile=fopen("/boot/MELT.LOG","a");
fwrite(text,strlen(text),1,logfile);
fwrite("\n",1,1,logfile);
fclose(logfile);
};
// MeltNewProj ----------------------------------------------------------------------------------------------
FunkyLabel::FunkyLabel(BRect size,char* applylabel,char* gfx) : BView(size,"funkylabel",B_FOLLOW_NONE,B_WILL_DRAW)
{
bitmap=FetchStyleResource(gfx);
strcpy(label,applylabel);
};
FunkyLabel::~FunkyLabel()
{
delete bitmap;
};
void FunkyLabel::Draw(BRect dummy)
{
DrawBitmap(bitmap,BPoint(1,0));
SetFont(be_bold_font);
DrawString(label,BPoint(35,16));
};
MeltNewProj::MeltNewProj() : BWindow(BRect(scrw/2-winw/2,scrh/2-winh/2,scrw/2+winw/2,scrh/2+winh/2),
"Melt: New CD-R",B_TITLED_WINDOW,B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
{
AroundBox=new BBox(BRect(0,0,winw,winh),"BetterStyle",B_FOLLOW_NONE,B_WILL_DRAW|B_FRAME_EVENTS,B_PLAIN_BORDER);
LogBox=new BBox(BRect(3,3,winw-3,180),"LogBox",B_FOLLOW_NONE,B_WILL_DRAW,B_FANCY_BORDER);
LogBox->SetLabel("CDRecord Log:");
CDTypeBox=new BBox(BRect(3,181,winw-3,winh-73),"CDTypeBox",B_FOLLOW_NONE,B_WILL_DRAW,B_FANCY_BORDER);
CTLabel=new FunkyLabel(BRect(0,0,35+be_bold_font->StringWidth("Mode Options:"),23),"Mode Options:","label_1");
rgb_color grey={216,216,216};
CTLabel->SetViewColor(grey);
CDTypeBox->SetLabel(CTLabel);
OptionBox=new BBox(BRect(3,winh-72,winw-3,winh-3),"OptionBox",B_FOLLOW_NONE,B_WILL_DRAW,B_FANCY_BORDER);
OptionBox->SetLabel("Virtual CD Project:");
ProjectLabel=new FunkyLabel(BRect(0,0,35+be_bold_font->StringWidth("Virtual CD Project:"),27),"Virtual CD Project:","label_4");
ProjectLabel->SetViewColor(grey);
OptionBox->SetLabel(ProjectLabel);
LogView=new BTextView(BRect(8,18,winw-(15+B_V_SCROLL_BAR_WIDTH),winh-260),"cdrecord",BRect(5,15,winw-10,winh-160),B_FOLLOW_NONE);
LogView->SetStylable(true);
LogView->MakeEditable(false);
LogScroll=new BScrollView("logscroll",LogView,B_FOLLOW_NONE,0,false,true,B_FANCY_BORDER);
Recorders=new BMenu("Select");
Recorders->SetLabelFromMarked(true);
RecordPop=new BMenuField(BRect(5,winh-255,winw-10,winh-225),"recorder","Devices:",Recorders);
RecordPop->SetDivider(be_plain_font->StringWidth("Devices: "));
LogBox->AddChild(LogScroll);
LogBox->AddChild(RecordPop);
UseISO9660=new BRadioButton(BRect(160+34,40,180+78,60),"iso","ISO9660", new BMessage('uiso'));
UseISO9660->SetValue(B_CONTROL_ON);
UseBFS=new BRadioButton(BRect(200,32,winw-10,47),"bfs","BFS (Melt 1.5)", new BMessage('ubfs'));
UseAudio=new BRadioButton(BRect(180+114,40,winw-10,60),"bfs","Audio", new BMessage('uaud'));
DataIcon=new FunkyLabel(BRect(160,33,160+32,33+32),"","label_2");
DataIcon->SetViewColor(grey);
AudioIcon=new FunkyLabel(BRect(180+80,30,180+112,30+32),"","label_3");
AudioIcon->SetViewColor(grey);
MultiSession=new BCheckBox(BRect(5,25,159,40),"data2","Multisession", new BMessage('mses'));
CheckDAO=new BCheckBox(BRect(5,49,100,64),"dao","Disk At Once",new BMessage('cdao'));
CheckDAO->SetEnabled(false);
//Audio=new BRadioButton(BRect(5,49,100,64),"audio","Audio", new BMessage('audi'));
CDTypeBox->AddChild(UseISO9660);
//CDTypeBox->AddChild(UseBFS);
//CDTypeBox->AddChild(SingleSession);
CDTypeBox->AddChild(MultiSession);
CDTypeBox->AddChild(CheckDAO);
CDTypeBox->AddChild(UseAudio);
CDTypeBox->AddChild(DataIcon);
CDTypeBox->AddChild(AudioIcon);
CDRWBox=new BBox(BRect(5,75,winw-11,140),"CDRWBox",B_FOLLOW_NONE,B_WILL_DRAW,B_FANCY_BORDER);
CDRWBox->SetLabel("CDRW Tools:");
Modes=new BMenu("Select");
Modes->SetLabelFromMarked(true);
for (uint8 i=0; i<BLANK_MODE_MAX; i++)
Modes->AddItem(new BMenuItem(BLANK_MODE[i],new BMessage('blk\0'|i)));
ModePop=new BMenuField(BRect(5,15,230,40),"blankmode","Blank Mode:",Modes);
ModePop->SetDivider(be_plain_font->StringWidth("Blank Mode: "));
Blank=new BButton(BRect(300,22,winw-22,47),"blank","Blank",new BMessage('blnk'));
BlankStatus=new BStatusBar(BRect(5,28,30,60),"status","","");
BlankTxt=new BTextView(BRect(34,44,230,60),"txt",BRect(0,0,winw-52,15),B_FOLLOW_NONE);
BlankTxt->MakeSelectable(false);
BlankTxt->MakeEditable(false);
BlankTxt->SetStylable(true);
BlankTxt->SetViewColor(grey);
BlankTxt->Insert("Waiting.");
Speed=new BSlider(BRect(232,15,296,40),"speed","Speed [1x]",new BMessage('sped'),0,3,B_TRIANGLE_THUMB,B_FOLLOW_NONE);
Speed->SetHashMarks(B_HASH_MARKS_BOTTOM);
Speed->SetHashMarkCount(4);
Speed->SetModificationMessage(new BMessage('sped'));
CDRWBox->AddChild(ModePop);
CDRWBox->AddChild(Blank);
CDRWBox->AddChild(BlankStatus);
CDRWBox->AddChild(BlankTxt);
CDRWBox->AddChild(Speed);
CDTypeBox->AddChild(CDRWBox);
//SingleSession->SetValue(B_CONTROL_ON);
Done=new BButton(BRect(5,30,97,55),"done","New",new BMessage('done'));
Open=new BButton(BRect(102,30,195,55),"open","Open",new BMessage('open'));
//Open->SetEnabled(false);
OptionBox->AddChild(Done);
OptionBox->AddChild(Open);
char bufzer[1024];
sprintf (bufzer,"%s/Projects/",MELT_PATH);
BEntry myentry(bufzer,true);
entry_ref* ref=new entry_ref();
myentry.GetRef(ref);
OpenPanel=new BFilePanel(B_OPEN_PANEL,&be_app_messenger,ref,B_DIRECTORY_NODE,false,NULL,NULL,true,true);
AroundBox->AddChild(LogBox);
AroundBox->AddChild(CDTypeBox);
AroundBox->AddChild(OptionBox);
AddChild(AroundBox);
};
/*
**************************************************************
WARNING: Note that the following function has never been used.
And it's a shitty idea anyway.
**************************************************************
*/
void CreateBufferFile()
{
BAlert* myAlert=new BAlert("Melt Info",
"Before you can use the BFS mode for the first time, a 650MB buffer file has to be made on one of your harddrives.","Cancel","Relocate","Create");
int res=myAlert->Go();
if (res==2)
{
int awinw=250;
int awinh=50;
BWindow* AddWindow=new BWindow(BRect(scrw/2-awinw/2,scrh/2-awinh/2,scrw/2+awinw/2,scrh/2+awinh/2),
"Melt: Working",B_MODAL_WINDOW,B_NOT_RESIZABLE|B_NOT_ZOOMABLE);
BView* coverview=new BView(BRect(0,0,awinw,awinh),"Cover",B_FOLLOW_NONE,B_WILL_DRAW);
BStatusBar* status=new BStatusBar(BRect(8,5,awinw-10,awinh-10),"status","Creating buffer...","0/650 MB");
rgb_color grey={200,200,230};
coverview->SetViewColor(grey);
status->SetMaxValue(27);
coverview->AddChild(status);
AddWindow->AddChild(coverview);
AddWindow->Show();
char ddcommand[2048];
sprintf(ddcommand,"dd if=/dev/zero of=/lot/ddtest.iso bs=1024k count=24");
system(ddcommand);
for (int i=0; i<27; i++)
{
AddWindow->Lock();
status->Update(1);
AddWindow->Unlock();
system(ddcommand);
sprintf (ddcommand,"dd if=/dev/zero of=/lot/ddtest.iso bs=1024k seek=%d count=1",25*i+24);
};
sprintf (ddcommand,"mkbfs 2048 /lot/ddtest.iso");
system(ddcommand);
system("mkdir /dev/melt-buffer/");
system("mount /lot/ddtest.iso /dev/melt-buffer");
AddWindow->Lock();
AddWindow->Close();
sprintf (MELT_RELOCATE,"/lot/ddtest.iso");
sprintf (ddcommand,"%s/Temp/buf-location",MELT_PATH);
FILE* vcd_relocate=fopen (ddcommand,"w");
uint8 len=strlen(MELT_RELOCATE);
res=fwrite(&len,1,1,vcd_relocate);
if (res)
{
fwrite(MELT_RELOCATE,1,len,vcd_relocate);
};
MELT_RELOCATE[len]=0;
fclose(vcd_relocate);
};
};
int32 blink_control(void* p)
{
blinkinfo* universe=(blinkinfo*)p;
BStatusBar* bar=universe->bar;
rgb_color green={100,255,100};
rgb_color blue={100,100,255};
int ub=0;
while(universe->progress)
{
snooze(500000);
ub=1-ub;
if (ub)
{
bar->Window()->Lock();
bar->SetBarColor(green);
bar->Update(0);
bar->Window()->Unlock();
}
else
{
bar->Window()->Lock();
bar->SetBarColor(blue);
bar->Update(0);
bar->Window()->Unlock();
};
};
return 0;
};
int32 blank_control(void* p)
{
rgb_color red={200,0,0};
rgb_color black={0,0,0};
//rgb_color green={0,200,50};
rgb_color blue={0,0,200};
FILE* f;
char* command=(char*)p;
f=popen(command,"r");
MeltNewProj* universe=((MeltApp*)be_app)->NewProjWin;
universe->blink.progress=false;
char buf[1024];
char bufzer[1024];
bool progress_mode=false;
bool burn_error=false;
while (!feof(f) && !ferror(f))
{
buf[0]=0;
fgets(buf,1024,f);
Log(buf);
if (!strncmp(buf,"Sense Code:",11))
{
strcpy (bufzer,buf+11);
sprintf (buf,"The following error occured:\n\n%s",bufzer);
burn_error=true;
BAlert* myAlert=new BAlert("Melt Error",buf,"Damn");
myAlert->Go();
break;
};
if (!strncmp(buf,"Disk type:",10))
{
universe->Lock();
universe->BlankTxt->Delete(0,500);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&blue);
universe->BlankTxt->Insert(buf);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&black);
universe->Unlock();
};
if (!strncmp(buf,"Blanking",8) && !universe->blink.progress)
{
universe->Lock();
universe->BlankTxt->Delete(0,500);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&blue);
universe->BlankTxt->Insert(buf);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&black);
progress_mode=true;
universe->BlankStatus->Reset();
universe->BlankStatus->Update(100);
universe->Unlock();
universe->blink.progress=true;
universe->blink.bar=universe->BlankStatus;
resume_thread(spawn_thread(blink_control,"blink",5,&universe->blink));
};
};
universe->blink.progress=false;
if (!burn_error)
{
universe->Lock();
universe->BlankTxt->Delete(0,500);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&blue);
universe->BlankTxt->Insert("Done.");
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&black);
universe->Unlock();
}
else
{
universe->Lock();
universe->BlankTxt->Delete(0,500);
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&blue);
universe->BlankTxt->Insert("Failure.");
universe->BlankTxt->SetFontAndColor(0,0,be_plain_font,B_FONT_ALL,&black);
universe->BlankStatus->SetBarColor(red);
universe->BlankStatus->Update(0);
universe->Unlock();
};
pclose(f);
return 0;
};
void MeltNewProj::MessageReceived(BMessage* msg)
{
switch (msg->what)
{
case 'sped':
{
int valu=(int)Speed->Value();
MELT_SPEED=(int)pow(2,valu);
char buf[200];
sprintf (buf,"Speed [%dx]",MELT_SPEED);
Speed->SetLabel(buf);
}
break;
case 'blnk':
{
char command[1024];
sprintf (command,"cdrecord dev=%s speed=%d -v -blank=%s",MELT_DEVICE,MELT_SPEED,BLANK_CMD[MELT_BLANKMODE]);
Log(command);
thread_id blank=spawn_thread(blank_control,"blank",10,command);
resume_thread(blank);
}
break;
case 'open':
{
if (strncmp(MELT_DEVICE,"xxxxx",5))
{
OpenPanel->Show();
}
else
{
BAlert* myalert=new BAlert("Melt Warning","Please select a burner first.","OK");
myalert->Go();
};
}
break;
case 'done':
if (strncmp(MELT_DEVICE,"xxxxx",5))
{
/*char pbuf[2048];
sprintf (pbuf,"%s/Temp/buf-location",MELT_PATH);
FILE* vcd_relocate=fopen (pbuf,"r");
uint8 len;
int res=fread(&len,1,1,vcd_relocate);
if (res)
{
fread(MELT_RELOCATE,1,len,vcd_relocate);
};
MELT_RELOCATE[len]=0;
fclose(vcd_relocate);
FILE* image=fopen(MELT_RELOCATE,"r");
uint32 image_size=fseek(image,SEEK_END,0)+1;
fclose (image);
if (image_size!=665600)
{
CreateBufferFile();
};*/
MELT_MULTISESSION=(MultiSession->Value()==B_CONTROL_ON);
if (UseAudio->Value()==B_CONTROL_ON) MELT_CDTYPE=1;
be_app->PostMessage(new BMessage('opvw'));
}
else
{
BAlert* myalert=new BAlert("Melt Warning","Please select a burner first.","OK");
myalert->Go();
};
break;
};
if ((msg->what&0xffffff00)=='dev\0')
{
uint8 savedrec=msg->what&0xff;
strncpy(MELT_DEVICE,&Possible_Devices[savedrec*7],5);
FILE* config=fopen("/boot/home/config/settings/Melt.cfg","w");
fwrite(&savedrec,1,1,config);
fclose(config);
//SetTitle(MELT_DEVICE);
};
if ((msg->what&0xffffff00)=='blk\0')
{
uint8 bm=msg->what&0xff;
MELT_BLANKMODE=bm;
/*char buf[200];
sprintf (buf,"Blankmode: %d (%s)",MELT_BLANKMODE,BLANK_CMD[MELT_BLANKMODE]);
SetTitle(buf);*/
};
};
bool MeltNewProj::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
};
// MeltTools --------------------------------------------------------------------------------------------------
int vwinw=400;
int vwinh=500;
MeltTools::MeltTools() : BView(BRect(0,0,vwinw,49),"tools",B_FOLLOW_NONE,B_WILL_DRAW)
{
PrjName=new BTextControl(BRect(7,15,200,37),"name","Name:","Untitled",new BMessage('name'));
PrjName->SetDivider(be_plain_font->StringWidth("Name: "));
Save=new BButton(BRect(210,13,280,37),"save","Save As",new BMessage('save'));
//Save->SetEnabled(false);
Burn=new BButton(BRect(285,13,355,37),"burn","Done",new BMessage('burn'));
char bufzer[1024];
sprintf (bufzer,"%s/Projects/",MELT_PATH);
BEntry myentry(bufzer,true);
entry_ref* ref=new entry_ref();
myentry.GetRef(ref);
SavePanel=new BFilePanel(B_SAVE_PANEL,&be_app_messenger,ref,B_FILE_NODE|B_DIRECTORY_NODE,false,NULL,NULL,true,true);
SavePanel->SetSaveText("Untitled");
AddChild(PrjName);
AddChild(Save);
AddChild(Burn);
};
void MeltTools::Draw(BRect dummy)
{
rgb_color light={250,250,255};
rgb_color white={255,255,255};
rgb_color black={0,0,0};
rgb_color bgcol={200,200,200};
BRect bnds=Bounds();
float right=bnds.right;
for (int y=0; y<49; y++)
{
light.red-=2;
light.green-=2;
light.blue-=1;
SetHighColor(light);
FillRect(BRect(0,y,right,y));
};
SetHighColor(black);
FillRect(BRect(0,49,right,49));
SetHighColor(bgcol);
SetLowColor(bgcol);
FillRect(BRect(5,8,right-5,40));
SetHighColor(light);
FillRect(BRect(4,7,right-5,7));
FillRect(BRect(4,7,4,40));
SetHighColor(black);
FillRect(BRect(5,8,right-5,8));
FillRect(BRect(5,8,5,40));
SetHighColor(light);
FillRect(BRect(right-5,8,right-5,40));
FillRect(BRect(5,40,right-5,40));
SetHighColor(white);
FillRect(BRect(right-4,8,right-4,41));
FillRect(BRect(5,41,right-5,41));
};
// MeltTrackList ----------------------------------------------------------------------------------------------
bool MeltAdjust(BListItem* that)
{
that->SetHeight(34);
return false;
};
MeltList::MeltList() : BListView(BRect(0,52,vwinw-B_V_SCROLL_BAR_WIDTH,vwinh),"Tracks",B_SINGLE_SELECTION_LIST,B_FOLLOW_ALL)
{
// build menu
TrackPop = new BPopUpMenu("context menu");
TrackPop->SetRadioMode(false);
TrackPop->AddItem(new BMenuItem("Move Upward", new BMessage('mvup')));
TrackPop->AddItem(new BMenuItem("Remove", new BMessage('remt')));
TrackPop->AddItem(new BMenuItem("Move Downward", new BMessage('mvdn')));
if (MELT_CDTYPE==1) TrackPop->AddItem(new BMenuItem("Listen to this Track", new BMessage('hear')));
};
void MeltList::RePattern()
{
int num=CountItems();
if (num)
{
Global_Pattern=false;
for (int i=1; i<=num; i++)
{
MeltItem* manip=(MeltItem*)ItemAt(i-1);
manip->Pattern=Global_Pattern;
Global_Pattern=!Global_Pattern;
};
Invalidate();
};
};
void MeltList::MouseDown(BPoint where)
{
uint32 buttons;
BMessage* msg=Window()->CurrentMessage();
// retrieve the button state from the MouseDown message
if (msg->FindInt32("buttons", (int32 *)&buttons) == B_NO_ERROR) {
// find item at the mouse location
int32 item = IndexOf(where);
// make sure item is valid
if ((item >= 0) && (item < CountItems())) {
// if clicked with second mouse button, let's do a context-sensitive menu
if (buttons == B_SECONDARY_MOUSE_BUTTON) {
BPoint point = where;
ConvertToScreen(&point);
// select this item
Select(item);
TrackPop->Go(point, true, false, true);
return;
}
if (buttons == B_PRIMARY_MOUSE_BUTTON)
{
int32 clicks = msg->FindInt32("clicks");
if ((buttons == mLastButton) && (clicks > 1))
{
mClickCount++;
}
else mClickCount = 1; // no, it's the first click of a new button
mLastButton = buttons; // remember what the last button pressed was
if (clicks==2)
{
Window()->PostMessage(new BMessage('hear'));
};
};
}
}
// either the user dbl-clicked an item or clicked in an area with no
// items. either way, let BListView take care of it
BListView::MouseDown(where);
}
FILE* CLInput;
FILE* CLOutput;
int32 controller(void* p)
{
char* command=(char*)p;
CLInput=popen(command,"r");
return 0;
};
void CreateImage(MeltList* list,entry_ref* ref)
{
MeltVirtualCD* vc=((MeltApp*)be_app)->CDWin;
BEntry entry(ref,true);
BPath path;
entry.GetPath(&path);
char* temppath=(char*)path.Path();
int len=strlen(temppath);
char mypath[1024];
strcpy(mypath,temppath);
/*BNode node(&entry);
fprintf (debfile,"Created node.\n");
fclose(debfile);
debfile=fopen("/boot/home/MELT.DBG","a");
char typebuf[256];
int nodelen=node.ReadAttr("BEOS:TYPE",0,0,typebuf,255);
fprintf (debfile,"Read BEOS:TYPE attribute.\n");
fclose(debfile);
debfile=fopen("/boot/home/MELT.DBG","a");*/
/*if (nodelen)
{
typebuf[nodelen]=0;
bool isdir=false;
if (!strcmp(typebuf,"application/x-vnd.Be-directory")) isdir=true;
fprintf (debfile,"Dir Check 1.\n");
fclose(debfile);
debfile=fopen("/boot/home/MELT.DBG","a");
}
else
{
isdir=true;
};*/
bool isdir=false;
bool isiso=false;
char dumb[1];
FILE* test=fopen(mypath,"r");
int res=fread(&dumb,1,1,test);
if (res!=1) isdir=true;
fclose (test);
if (mypath[len-1]=='/') isdir=true;
uint32 i;
int j=0;
for (i=0; i<strlen(mypath); i++)
{
if (mypath[i]=='.') j=i;
};
i=j;
if (!strcmp(&mypath[i],".iso") || !strcmp(&mypath[i],".img"))
{
isiso=true;
};
int override=0;
char* trackname;
char command[2048];
for (i=strlen(mypath)-1; i>0; i--)
{
if (mypath[i]=='/') break;
};
trackname=&mypath[i+1];
if (MELT_CDTYPE==0)
{
// ISO 9660 - Data track layout folder
if (!isiso)
{
if (!isdir)
{
BAlert* myAlert=new BAlert("Melt Warning","Sorry, you can only drop folders or .iso and .img files onto the track list.\nSelect Override if this is a FAT32 (or similar) folder.","Override","OK");
override=myAlert->Go();
if (override) return;
};
sprintf (command,"/boot/common/bin/mkhybrid -a -r -J -V \"%s\" -o \"%s/Temp/%s.img\" \"%s\"",trackname,MELT_PATH,trackname,mypath);
Log("Creating image file:");
Log(command);
int awinw=250;
int awinh=50;
BWindow* AddWindow=new BWindow(BRect(scrw/2-awinw/2,scrh/2-awinh/2,scrw/2+awinw/2,scrh/2+awinh/2),
"Melt: Working",B_MODAL_WINDOW,B_NOT_RESIZABLE|B_NOT_ZOOMABLE);
BView* coverview=new BView(BRect(0,0,awinw,awinh),"Cover",B_FOLLOW_NONE,B_WILL_DRAW);
BStatusBar* status=new BStatusBar(BRect(8,5,awinw-10,awinh-10),"status","Processing Folder...","Please Wait");
rgb_color grey={200,200,230};
coverview->SetViewColor(grey);
coverview->AddChild(status);
AddWindow->AddChild(coverview);
AddWindow->Show();
AddWindow->Lock();
status->Update(100);
AddWindow->Unlock();
resume_thread(spawn_thread(controller,"Mkhybrid Controller",5,command));
snooze(200000);
char buf[1024];
rgb_color green={100,255,100};
rgb_color blue={100,100,255};
blinkinfo info;
info.bar=status;
info.progress=true;
resume_thread(spawn_thread(blink_control,"Mkhybrid Blink",5,&info));
while (!feof(CLInput) && !ferror(CLInput))
{
snooze(200000);
buf[0]=0;
fgets(buf,1024,CLInput);
};
info.progress=false;
pclose(CLInput);
snooze(1000000);
AddWindow->Lock();
AddWindow->Close();
sprintf (command,"%s/Temp/%s.img",MELT_PATH,trackname);
}
else
{
strcpy(command,mypath);
};
FILE* track=fopen(command,"r");
fseek(track,0,SEEK_END);
uint32 tracksize=(((ftell(track)+1)/1024)/1024);
fclose(track);
if (strlen(trackname)>40)
{
strcpy(trackname+40,"...");
};
if (!isiso) strcat(trackname,".img");
char itembuf[200];
sprintf (itembuf,"Data Track \"%s\" (%d MB)",trackname,(int)tracksize);
MELT_CDSIZE+=tracksize;
vc->MakeTitle();
list->AddItem(new MeltItem(command,itembuf,vc->Icon[0],vc->Icon[1],vc->Icon[2]));
list->DoForEach(MeltAdjust);
list->Invalidate();
is_saved=false;
}
else // Audio CD
{
bool accept=true;
for (i=strlen(mypath)-1; i>0; i--)
{
if (mypath[i]=='/') break;
};
char* trackname=&mypath[i+1];
int audiotype=0;
int offset=0;
bool got_it=false;
if (!isdir)
{
FILE* examine=fopen (mypath,"r");
fseek(examine,8,SEEK_SET);
uint32 id=0;
fread (&id,1,4,examine);
if (id=='EVAW')
{
audiotype=1;
for (i=0; i<40; i++)
{
fread(&id,1,4,examine);
if (id=='atad') got_it=true;
if (got_it) break;
};
if (got_it)
{
offset=ftell(examine);
}
else
{
audiotype=0;
};
};
/*if (id=='AIFF')
{
audiotype=2;
for (i=0; i<40; i++)
{
fread(&id,1,4,examine);
if (id=='SSND') got_it=true;
if (got_it) break;
};
if (got_it)
{
offset=ftell(examine);
}
else
{
audiotype=0;
};
};*/
if (audiotype==0) accept=false;
}
else
{
accept=false;
};
if (!accept)
{
BAlert* myAlert=new BAlert("Melt Warning",
"Please drop RIFF WAVE files (16 bit, 44kHz Stereo).\nYou could use SoundPlay (available on BeBits.com) to convert your files to this format if necessary.","OK");
myAlert->Go();
return;
};
FILE* track=fopen (mypath,"r");
fseek (track,0,SEEK_END);
uint32 audiobytes=ftell(track);
fclose (track);
// WAVE header=44 bytes
// AIFF header=54 bytes
if (audiotype==1)
{
audiobytes-=44;
};
int audiopad=2352*(1+audiobytes/2352)-audiobytes;
printf ("audiobytes = %d\n",(int)audiobytes);
printf ("audiobytes/2352+1 = %d\n",(int)1+audiobytes/2352);
printf ("*2352 = %d\n",(int)2352*(1+audiobytes/2352));
if (audiopad==2352) audiopad=0;
if (audiopad)
{
char message[1000];
sprintf (message,"The track size is not a multiple of 2352 bytes.\nDo you want Melt to resize the file to this boundary and fill the new part (%d bytes) with silence (zeroes)?",audiopad);
BAlert* myAlert=new BAlert("Melt Warning",message,"No","Yes");
int res=myAlert->Go();
if (!res) {return;};
uint8* nullbuffer=(uint8*)malloc(audiopad);
memset(nullbuffer,0,audiopad);
track=fopen(mypath,"a");
fwrite(nullbuffer,1,audiopad,track);
fclose(track);
audiobytes+=audiopad;
track=fopen(mypath,"r+");
if (audiotype==1)
{
// RIFF WAVE
fseek(track,0x28,SEEK_SET);
fwrite(&audiobytes,1,4,track);
}
else
{
// AIFF
fseek(track,0x2a,SEEK_SET);
fwrite(((uint8*)(&audiobytes))+3,1,1,track);
fwrite(((uint8*)(&audiobytes))+2,1,1,track);
fwrite(((uint8*)(&audiobytes))+1,1,1,track);
fwrite(((uint8*)(&audiobytes))+0,1,1,track);
};
fclose(track);
};
int tracksize=audiobytes/(1024*1024);
MELT_CDSIZE+=tracksize;
vc->MakeTitle();