~ubuntu-branches/ubuntu/karmic/mhwaveedit/karmic

« back to all changes in this revision

Viewing changes to src/pipedialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-01-08 22:20:37 UTC
  • mfrom: (2.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080108222037-tsazhckl5vmc8yih
Tags: 1.4.14-2
Added desktop file (Closes: #457849), thanks to Marco Rodrigues

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2002 2003 2004 2005, Magnus Hjorth
 
2
 * Copyright (C) 2002 2003 2004 2005 2006, Magnus Hjorth
3
3
 *
4
4
 * This file is part of mhWaveEdit.
5
5
 *
56
56
     gchar *cmd;
57
57
     gboolean sendwav;
58
58
     PipeDialog *pd = PIPE_DIALOG(user_data);
 
59
     Chunk *r;
 
60
     off_t clipcount = 0;
59
61
     cmd = history_box_get_value(pd->cmd);
60
62
     sendwav = gtk_toggle_button_get_active(pd->sendwav);
61
63
     inifile_set_gboolean("PipeDialog_sendWav",sendwav);
62
 
     return pipe_dialog_pipe_chunk(chunk,cmd,sendwav,dither_editing,bar);
 
64
     r = pipe_dialog_pipe_chunk(chunk,cmd,sendwav,dither_editing,bar,
 
65
                                &clipcount);
 
66
     if (r != NULL && clipwarn(clipcount,TRUE)) {
 
67
          gtk_object_sink(GTK_OBJECT(r));
 
68
          r = NULL;
 
69
     }
 
70
 
 
71
     return r;
63
72
}
64
73
 
65
74
static gboolean pipe_dialog_apply(EffectDialog *ed)
314
323
static Chunk *pipe_dialog_pipe_chunk_main(Chunk *chunk, gchar *command, 
315
324
                                          gboolean sendwav, gboolean do_read, 
316
325
                                          StatusBar *bar, gboolean *sent_all, 
317
 
                                          int dither_mode)
 
326
                                          int dither_mode, off_t *clipcount)
318
327
{
319
328
     int fds[3],bs,bp,i;
320
329
     gboolean writing=TRUE;
321
330
     gboolean send_header = sendwav;
322
331
     off_t ui,read_bytes=0;
323
 
     gchar *c=NULL;
 
332
     gchar *inbuf=NULL,*outbuf,*c;
324
333
     ChunkHandle *ch=NULL;
325
334
     TempFile ct=0;
326
335
     fd_set rset,wset;
327
336
     gpointer pipehandle;
 
337
 
 
338
     /*
 
339
     puts("---");
 
340
     puts(command);
 
341
     puts("///");
 
342
     */
328
343
     
329
344
     if (sent_all) *sent_all = FALSE;
330
345
 
345
360
               return NULL;
346
361
          }
347
362
     }
348
 
     status_bar_begin_progress(bar,ch->length,NULL);
349
 
     c = g_malloc(BZ);
 
363
     status_bar_begin_progress(bar,ch->size,NULL);     
 
364
     if (do_read) inbuf = g_malloc(BZ);
 
365
     outbuf = g_malloc(BZ);
350
366
     ui = 0;
351
367
     bs = bp = 0;
352
368
     /* We want to handle broken pipes ourselves. */
374
390
          /* Read data from standard output */
375
391
          if (FD_ISSET(fds[1],&rset)) {
376
392
               /* printf("Reading from stdin..\n"); */
377
 
               i = read(fds[1],c,BZ);
 
393
               i = read(fds[1],inbuf,BZ);
378
394
               /* printf("Read finished\n"); */
379
395
               if (i == -1) { if (errno != EINTR) goto errno_error_exit; }
380
396
               else if (i == 0) { break; }
381
 
               else { if (tempfile_write(ct,c,i)) goto error_exit; }
 
397
               else { if (tempfile_write(ct,inbuf,i)) goto error_exit; }
382
398
               read_bytes += i;
383
399
               continue;
384
400
          }
394
410
               if (bs == bp) {
395
411
                    if (send_header) {
396
412
                         /* FIXME: Broken for float on bigendian machines */
397
 
                         bs = get_wav_header(&(chunk->format),chunk->size,c);
 
413
                         bs = get_wav_header(&(chunk->format),chunk->size,
 
414
                                             outbuf);
398
415
                         bp = 0;
399
416
                         send_header = FALSE;
400
417
                    } else {
403
420
                              pipe_dialog_close_input(pipehandle);
404
421
                              continue; 
405
422
                         }
406
 
                         i = chunk_read_array(ch,ui,BZ,c, dither_mode);
 
423
                         i = chunk_read_array(ch,ui,BZ,outbuf, dither_mode,
 
424
                                              clipcount);
407
425
                         if (!i) goto error_exit;
408
426
                         bs = i;
409
427
                         bp = 0;
414
432
               }
415
433
               /* printf("Writing data...\n"); */
416
434
               /* Write data */
417
 
               i = write(fds[0],c+bp,MIN(bs-bp,PIPE_BUF));
 
435
               i = write(fds[0],outbuf+bp,MIN(bs-bp,PIPE_BUF));
 
436
               /* i = write(fds[0],outbuf+bp,1); */
418
437
               /* printf("Finished writing.\n"); */
419
438
               if (i == -1) {
420
439
                    /* Broken pipe - stop writing */
427
446
                    goto errno_error_exit;
428
447
               } 
429
448
               bp += i;
430
 
               if (status_bar_progress(bar, i / chunk->format.samplebytes)) 
 
449
               if (status_bar_progress(bar, i)) 
431
450
                    goto error_exit;
432
451
          }
433
452
     }
436
455
     while (pipe_dialog_error_check(pipehandle)) { }
437
456
     
438
457
     /* Finish */
439
 
     g_free(c);
 
458
     g_free(inbuf);
 
459
     g_free(outbuf);
440
460
     chunk_close(ch);
441
461
     pipe_dialog_close(pipehandle);
442
462
     status_bar_end_progress(bar);
448
468
     }
449
469
 
450
470
     if (sent_all) *sent_all = !writing;
451
 
 
 
471
     
452
472
     return do_read ? tempfile_finished(ct) : NULL;
453
473
 
454
474
errno_error_exit:
455
 
     g_free(c);
456
475
     c = g_strdup_printf(_("Error: %s"),strerror(errno));
457
476
     user_error(c);
 
477
     g_free(c);
458
478
error_exit:
459
 
     g_free(c);
 
479
     g_free(inbuf);
 
480
     g_free(outbuf);
460
481
     chunk_close(ch);
461
482
     if (do_read) tempfile_abort(ct);
462
483
     pipe_dialog_close(pipehandle);
465
486
}
466
487
 
467
488
Chunk *pipe_dialog_pipe_chunk(Chunk *chunk, gchar *command, gboolean sendwav,
468
 
                              int dither_mode, StatusBar *bar)
 
489
                              int dither_mode, StatusBar *bar, 
 
490
                              off_t *clipcount)
469
491
{
470
492
     return pipe_dialog_pipe_chunk_main(chunk,command,sendwav,TRUE,
471
 
                                        bar,NULL,dither_mode);
 
493
                                        bar,NULL,dither_mode,clipcount);
472
494
}
473
495
 
474
496
gboolean pipe_dialog_send_chunk(Chunk *chunk, gchar *command, gboolean sendwav,
475
 
                                int dither_mode, StatusBar *bar)
 
497
                                int dither_mode, StatusBar *bar,
 
498
                                off_t *clipcount)
476
499
{
477
500
     gboolean sent_all;
478
501
     pipe_dialog_pipe_chunk_main(chunk,command,sendwav,FALSE,
479
 
                                 bar,&sent_all,dither_mode);
 
502
                                 bar,&sent_all,dither_mode,clipcount);
480
503
     return !sent_all;
481
504
}