~ubuntu-branches/ubuntu/breezy/soundtracker/breezy

« back to all changes in this revision

Viewing changes to app/st-subs.c

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2005-04-18 07:19:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050418071914-b9m1ptfdnz8mqm7a
Tags: 0.6.7-5
* disable alsa (closes: #286350, #304711)
- it was doing double-free.
* update jack support, not enabled.
- 02_jack_output: Patch from Kai Vehmanen available as
  http://eca.cx/download/soundtracker-0.6.7-pre6-kv3.tar.gz
  applied.
- Build-Depend on libjack0.80.0-dev
- remove --disable-jack from configure line
* change soundtracker.1 section from 1x to 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
318
318
{
319
319
    int i, n;
320
320
 
321
 
    if(gui_settings.save_all_patterns) {
322
 
        for(i = 0, n = 0; i < 256; i++) {
323
 
            if(!st_is_empty_pattern(&xm->patterns[i]))
324
 
                n = i;
325
 
        }
326
 
    } else {
327
 
        for(i = 0, n = 0; i < 256; i++) {
328
 
            if(xm->pattern_order_table[i] > n)
329
 
                n = xm->pattern_order_table[i];
330
 
        }
 
321
    for(i = 0, n = 0; i < 256; i++) {
 
322
        if(!st_is_empty_pattern(&xm->patterns[i]))
 
323
            n = i;
331
324
    }
332
325
 
333
326
    return n + 1;
334
327
}
335
328
 
336
329
void
 
330
st_copy_instrument (STInstrument *src, STInstrument *dest)
 
331
{
 
332
    int i;
 
333
    guint32 length;
 
334
    GMutex *lock[16];
 
335
 
 
336
    st_clean_instrument(dest, NULL);
 
337
 
 
338
    for(i = 0; i < sizeof(dest->samples) / sizeof(dest->samples[0]); i++)
 
339
        lock[i] = dest->samples[i].sample.lock; // Preserve pointers to GMutex'es from modification
 
340
    memcpy(dest, src, sizeof(STInstrument));
 
341
    for(i = 0; i < sizeof(src->samples) / sizeof(src->samples[0]); i++){
 
342
        if ((length = dest->samples[i].sample.length * sizeof(dest->samples[i].sample.data[0]))){
 
343
            dest->samples[i].sample.data = malloc(length);
 
344
            memcpy(dest->samples[i].sample.data, src->samples[i].sample.data, length);
 
345
        }
 
346
        dest->samples[i].sample.lock = lock[i];
 
347
    }
 
348
}
 
349
 
 
350
void
337
351
st_clean_instrument (STInstrument *instr,
338
352
                     const char *name)
339
353
{
445
459
{
446
460
    int i;
447
461
 
448
 
    for(i = 0; i < sizeof(xm->patterns) / sizeof(xm->patterns[0]); i++)
449
 
        if(!st_is_pattern_used_in_song(xm, i) && st_is_empty_pattern(&xm->patterns[i]))
 
462
    for(i = 0; i < sizeof(xm->patterns) / sizeof(xm->patterns[0]); i++) {
 
463
        if(!st_is_pattern_used_in_song(xm, i) && st_is_empty_pattern(&xm->patterns[i])) {
450
464
            return i;
 
465
        }
 
466
    }
451
467
 
452
468
    return -1;
453
469
}
457
473
{
458
474
    int i;
459
475
    
460
 
    for(i = 0; i < 32; i++)
461
 
        if(p->channels[i])
462
 
            if(!st_is_empty_track(p->channels[i], p->length))
 
476
    for(i = 0; i < 32; i++) {
 
477
        if(p->channels[i]) {
 
478
            if(!st_is_empty_track(p->channels[i], p->length)) {
463
479
                return 0;
 
480
            }
 
481
        }
 
482
    }
464
483
 
465
484
    return 1;
466
485
}
469
488
st_is_empty_track (XMNote *notes,
470
489
                   int length)
471
490
{
472
 
    for(; length >= 0; length--)
 
491
    for(; length > 0; length--, notes++) {
473
492
        if(notes->note != 0 || notes->instrument != 0 || notes->volume != 0
474
 
           || notes->fxtype != 0 || notes->fxparam != 0)
 
493
           || notes->fxtype != 0 || notes->fxparam != 0) {
475
494
            return 0;
 
495
        }
 
496
    }
476
497
 
477
498
    return 1;
478
499
}
510
531
    }
511
532
}
512
533
 
 
534
gboolean
 
535
st_check_if_odd_are_not_empty (XMPattern *p)
 
536
{
 
537
    int i, j;
 
538
 
 
539
    for(i = 0; i < 32 && p->channels[i]; i++)
 
540
        for(j = 1; j < p->length; j += 2)
 
541
            if((p->channels[i][j].note && p->channels[i][j].instrument) ||
 
542
               (p->channels[i][j].volume > 15) ||
 
543
                p->channels[i][j].fxtype || p->channels[i][j].fxparam)
 
544
                return TRUE;
 
545
 
 
546
    return FALSE;
 
547
}
 
548
 
 
549
void
 
550
st_shrink_pattern (XMPattern *p)
 
551
{
 
552
    int i, j, length = p->length;
 
553
    
 
554
    for(i = 0; i < 32 && p->channels[i]; i++){
 
555
        for(j = 1; j <= (length - 1) / 2; j++)
 
556
            memcpy(&p->channels[i][j], &p->channels[i][2 * j], sizeof(XMNote));
 
557
        for(;j < p->alloc_length; j++){/* clear the rest of the pattern */
 
558
            p->channels[i][j].note = 0;
 
559
            p->channels[i][j].instrument = 0;
 
560
            p->channels[i][j].volume = 0;
 
561
            p->channels[i][j].fxtype = 0;
 
562
            p->channels[i][j].fxparam = 0;
 
563
        }
 
564
    }
 
565
    
 
566
    st_set_pattern_length(p, (length - 1) / 2 + 1);
 
567
}
 
568
 
 
569
void
 
570
st_expand_pattern (XMPattern *p)
 
571
{
 
572
    int i, j, length = MIN(p->length * 2, 256);
 
573
 
 
574
    st_set_pattern_length(p, length);
 
575
 
 
576
    for(i = 0; i < 32 && p->channels[i]; i++){
 
577
        for(j = length / 2 - 1; j >= 0; j--){
 
578
            /* copy to even positions and clear odd */
 
579
            memcpy(&p->channels[i][2 * j], &p->channels[i][j], sizeof(XMNote));
 
580
            p->channels[i][2 * j + 1].note = 0;
 
581
            p->channels[i][2 * j + 1].instrument = 0;
 
582
            p->channels[i][2 * j + 1].volume = 0;
 
583
            p->channels[i][2 * j + 1].fxtype = 0;
 
584
            p->channels[i][2 * j + 1].fxparam = 0;
 
585
        }
 
586
    }
 
587
}
 
588
 
513
589
void
514
590
st_convert_sample (void *src,
515
591
                   void *dst,
566
642
                                 int count)
567
643
{
568
644
    while(count) {
569
 
        *data = *data++ + 65536;
 
645
        *data = *data++ + 32768;
570
646
        count--;
571
647
    }
572
648
}