Mercurial > audlegacy-plugins
comparison src/modplug/modplugbmp.cxx @ 1544:0cfbecddb647
It compiles, no segfault... So where is my title?
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Fri, 31 Aug 2007 23:48:45 +0100 |
parents | 488f7e6c36ed |
children | 1047d8a70a6c |
comparison
equal
deleted
inserted
replaced
1543:ec4e8ec829b1 | 1544:0cfbecddb647 |
---|---|
17 #include "audacious/configdb.h" | 17 #include "audacious/configdb.h" |
18 #include "audacious/output.h" | 18 #include "audacious/output.h" |
19 #include "audacious/tuple.h" | 19 #include "audacious/tuple.h" |
20 #include "audacious/tuple_formatter.h" | 20 #include "audacious/tuple_formatter.h" |
21 #include "audacious/vfs.h" | 21 #include "audacious/vfs.h" |
22 } | |
23 | |
24 static char* format_and_free_ti( Tuple* ti, int* length ) | |
25 { | |
26 char* result = tuple_formatter_make_title_string(ti, get_gentitle_format()); | |
27 if ( result ) | |
28 *length = tuple_get_int(ti, "length"); | |
29 tuple_free((void *) ti); | |
30 | |
31 return result; | |
22 } | 32 } |
23 | 33 |
24 // ModplugXMMS member functions =============================== | 34 // ModplugXMMS member functions =============================== |
25 | 35 |
26 // operations ---------------------------------------- | 36 // operations ---------------------------------------- |
499 } | 509 } |
500 | 510 |
501 void ModplugXMMS::GetSongInfo(const string& aFilename, char*& aTitle, int32& aLength) | 511 void ModplugXMMS::GetSongInfo(const string& aFilename, char*& aTitle, int32& aLength) |
502 { | 512 { |
503 aLength = -1; | 513 aLength = -1; |
504 fstream lTestFile; | 514 *aTitle = NULL; |
505 string lError; | 515 |
506 bool lDone; | 516 Tuple* ti = GetSongTuple( aFilename ); |
507 | 517 if ( ti ) |
508 lTestFile.open(aFilename.c_str(), ios::in); | 518 aTitle = format_and_free_ti( ti, &aLength ); |
509 if(!lTestFile) | |
510 { | |
511 lError = "**no such file: "; | |
512 lError += strrchr(aFilename.c_str(), '/') + 1; | |
513 aTitle = new char[lError.length() + 1]; | |
514 strcpy(aTitle, lError.c_str()); | |
515 return; | |
516 } | |
517 | |
518 lTestFile.close(); | |
519 | |
520 if(mModProps.mFastinfo) | |
521 { | |
522 if(mModProps.mUseFilename) | |
523 { | |
524 //Use filename as name | |
525 aTitle = new char[aFilename.length() + 1]; | |
526 strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); | |
527 *strrchr(aTitle, '.') = '\0'; | |
528 return; | |
529 } | |
530 | |
531 fstream lModFile; | |
532 string lExt; | |
533 uint32 lPos; | |
534 | |
535 lDone = true; | |
536 | |
537 // previously ios::nocreate was used (X Standard C++ Library) | |
538 lModFile.open(aFilename.c_str(), ios::in); | |
539 | |
540 lPos = aFilename.find_last_of('.'); | |
541 if((int)lPos == 0) | |
542 return; | |
543 lExt = aFilename.substr(lPos); | |
544 for(uint32 i = 0; i < lExt.length(); i++) | |
545 lExt[i] = tolower(lExt[i]); | |
546 | |
547 if (lExt == ".mod") | |
548 { | |
549 lModFile.read(mModName, 20); | |
550 mModName[20] = 0; | |
551 } | |
552 else if (lExt == ".s3m") | |
553 { | |
554 lModFile.read(mModName, 28); | |
555 mModName[28] = 0; | |
556 } | |
557 else if (lExt == ".xm") | |
558 { | |
559 lModFile.seekg(17); | |
560 lModFile.read(mModName, 20); | |
561 mModName[20] = 0; | |
562 } | |
563 else if (lExt == ".it") | |
564 { | |
565 lModFile.seekg(4); | |
566 lModFile.read(mModName, 28); | |
567 mModName[28] = 0; | |
568 } | |
569 else | |
570 lDone = false; //fall back to slow info | |
571 | |
572 lModFile.close(); | |
573 | |
574 if(lDone) | |
575 { | |
576 for(int i = 0; mModName[i] != 0; i++) | |
577 { | |
578 if(mModName[i] != ' ') | |
579 { | |
580 aTitle = new char[strlen(mModName) + 1]; | |
581 strcpy(aTitle, mModName); | |
582 | |
583 return; | |
584 } | |
585 } | |
586 | |
587 //mod name is blank. Use filename instead. | |
588 aTitle = new char[aFilename.length() + 1]; | |
589 strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); | |
590 *strrchr(aTitle, '.') = '\0'; | |
591 return; | |
592 } | |
593 } | |
594 | |
595 Archive* lArchive; | |
596 CSoundFile* lSoundFile; | |
597 const char* lTitle; | |
598 | |
599 //open and mmap the file | |
600 lArchive = OpenArchive(aFilename); | |
601 if(lArchive->Size() == 0) | |
602 { | |
603 lError = "**bad mod file: "; | |
604 lError += strrchr(aFilename.c_str(), '/') + 1; | |
605 aTitle = new char[lError.length() + 1]; | |
606 strcpy(aTitle, lError.c_str()); | |
607 delete lArchive; | |
608 return; | |
609 } | |
610 | |
611 lSoundFile = new CSoundFile; | |
612 lSoundFile->Create((uchar*)lArchive->Map(), lArchive->Size()); | |
613 | |
614 if(!mModProps.mUseFilename) | |
615 { | |
616 lTitle = lSoundFile->GetTitle(); | |
617 | |
618 for(int i = 0; lTitle[i] != 0; i++) | |
619 { | |
620 if(lTitle[i] != ' ') | |
621 { | |
622 aTitle = new char[strlen(lTitle) + 1]; | |
623 strcpy(aTitle, lTitle); | |
624 goto therest; //sorry | |
625 } | |
626 } | |
627 } | |
628 | |
629 //mod name is blank, or user wants the filename to be used as the title. | |
630 aTitle = new char[aFilename.length() + 1]; | |
631 strcpy(aTitle, strrchr(aFilename.c_str(), '/') + 1); | |
632 *strrchr(aTitle, '.') = '\0'; | |
633 | |
634 therest: | |
635 aLength = lSoundFile->GetSongTime() * 1000; //It wants milliseconds!?! | |
636 | |
637 //unload the file | |
638 lSoundFile->Destroy(); | |
639 delete lSoundFile; | |
640 delete lArchive; | |
641 } | 519 } |
642 | 520 |
643 Tuple* ModplugXMMS::GetSongTuple(const string& aFilename) | 521 Tuple* ModplugXMMS::GetSongTuple(const string& aFilename) |
644 { | 522 { |
645 CSoundFile* lSoundFile; | 523 CSoundFile* lSoundFile; |