1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Philipp Pertermann
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #ifdef HAVE_LCD_BITMAP
27 /* variable button definitions */
28 #if CONFIG_KEYPAD == RECORDER_PAD
29 #define SPLITEDIT_QUIT BUTTON_OFF
30 #define SPLITEDIT_PLAY BUTTON_PLAY
31 #define SPLITEDIT_SAVE BUTTON_F1
32 #define SPLITEDIT_LOOP_MODE BUTTON_F2
33 #define SPLITEDIT_SCALE BUTTON_F3
34 #define SPLITEDIT_SPEED50 (BUTTON_ON | BUTTON_LEFT)
35 #define SPLITEDIT_SPEED100 (BUTTON_ON | BUTTON_PLAY)
36 #define SPLITEDIT_SPEED150 (BUTTON_ON | BUTTON_RIGHT)
37 #define SPLITEDIT_MENU_RUN BUTTON_PLAY
39 #elif CONFIG_KEYPAD == ONDIO_PAD
40 #define SPLITEDIT_QUIT BUTTON_OFF
41 #define SPLITEDIT_PLAY_PRE BUTTON_MENU
42 #define SPLITEDIT_PLAY (BUTTON_MENU | BUTTON_REL)
43 #define SPLITEDIT_SAVE (BUTTON_MENU | BUTTON_LEFT)
44 #define SPLITEDIT_LOOP_MODE (BUTTON_MENU | BUTTON_UP)
45 #define SPLITEDIT_SCALE (BUTTON_MENU | BUTTON_RIGHT)
46 #define SPLITEDIT_MENU_RUN BUTTON_RIGHT
48 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
49 #define SPLITEDIT_QUIT BUTTON_OFF
50 #define SPLITEDIT_PLAY BUTTON_ON
51 #define SPLITEDIT_SAVE BUTTON_SELECT
52 #define SPLITEDIT_LOOP_MODE BUTTON_MODE
53 #define SPLITEDIT_SCALE (BUTTON_REC | BUTTON_UP)
54 #define SPLITEDIT_SPEED50 (BUTTON_REC | BUTTON_LEFT)
55 #define SPLITEDIT_SPEED100 (BUTTON_REC | BUTTON_DOWN)
56 #define SPLITEDIT_SPEED150 (BUTTON_REC | BUTTON_RIGHT)
57 #define SPLITEDIT_MENU_RUN BUTTON_RIGHT
59 #define SPLITEDIT_RC_QUIT BUTTON_RC_STOP
64 unsigned char LOOP_BMP
[][13] =
66 {0xfc,0x00,0x10,0x11,0x93,0x7f,0x13,0x11,0x7c,0x38,0x10,0x00,0x7c}, /*ALL */
67 {0x81,0x03,0x7f,0x03,0x91,0x10,0x10,0x10,0x7c,0x38,0x10,0x00,0x7c}, /*FROM*/
68 {0xfc,0x00,0x10,0x10,0x90,0x10,0x7c,0x38,0x11,0x03,0x7f,0x03,0x01}, /*TO */
69 {0x80,0x10,0x10,0x11,0x93,0x7f,0x13,0x11,0x10,0x7c,0x38,0x10,0x00}, /*FREE*/
72 unsigned char CUT_BMP
[] =
74 0xc1,0x63,0x63,0x36,0xb6,0x1c,0x1c,0x36,0x77,0x55,0x55,0x55,0x32,
77 unsigned char SCALE_BMP
[][13] =
79 {0x80,0x06,0x49,0x66,0xb0,0x18,0x0c,0x06,0x33,0x49,0x30,0x00,0x00}, /*lin*/
80 {0x80,0x30,0x78,0x48,0xff,0x7f,0x00,0x7f,0x7f,0x48,0x78,0x30,0x00}, /*db*/
84 #define TIMEBAR_HEIGHT 4
87 #define OSCI_Y (TIMEBAR_Y + TIMEBAR_HEIGHT + 1)
88 #define OSCI_WIDTH LCD_WIDTH
89 #define OSCI_HEIGHT (LCD_HEIGHT - BMPHEIGHT - OSCI_Y - 1)
91 /* Indices of the menu items in the save editor, see save_editor */
92 #define SE_PART1_SAVE 0
93 #define SE_PART1_NAME 1
94 #define SE_PART2_SAVE 2
95 #define SE_PART2_NAME 3
99 /* the global api pointer */
100 static struct plugin_api
* rb
;
102 /* contains the file name of the song that is to be split */
103 static char path_mp3
[MAX_PATH
];
105 /* Exit code of this plugin */
106 static enum plugin_status splitedit_exit_code
= PLUGIN_OK
;
108 /* The range in time that the displayed aerea comprises */
109 static unsigned int range_start
= 0;
110 static unsigned int range_end
= 0;
112 /* The range in time that is being looped */
113 static unsigned int play_start
= 0;
114 static unsigned int play_end
= 0;
116 /* Point in time (pixel) at which the split mark is set */
117 static int split_x
= OSCI_X
+ (OSCI_WIDTH
/ 2);
119 /* Contains the peak values */
120 static unsigned char osci_buffer
[OSCI_WIDTH
];
122 /* if true peak values from a previous loop are only overwritten
123 if the new value is greater than the old value */
124 static bool osci_valid
= false;
127 * point in time from which on the osci_buffer is invalid
128 * if set to ~(unsigned int)0 the entire osci_buffer is invalid
130 static unsigned int validation_start
= ~(unsigned int)0;
132 /* all the visible aerea is looped */
133 #define LOOP_MODE_ALL 0
135 /* loop starts at split point, ends at right visible border */
136 #define LOOP_MODE_FROM 1
138 /* loop start at left visible border, ends at split point */
139 #define LOOP_MODE_TO 2
141 /* let the song play without looping */
142 #define LOOP_MODE_FREE 3
144 /* see LOOP_MODE_XXX constants vor valid values */
145 static int loop_mode
= LOOP_MODE_FREE
;
147 /* minimal allowed timespan (ms) of the visible (and looped) aerea*/
148 #define MIN_RANGE_SIZE 1000
150 /* Format time into buf.
152 * buf - buffer to format to.
153 * buf_size - size of buffer.
154 * time - time to format, in milliseconds.
156 static void format_time_ms(char* buf
, int buf_size
, int time
)
158 rb
->snprintf(buf
, buf_size
, "%d:%02d:%03d", time
/ 60000,
159 time
% 60000 / 1000, (time
% 60000) % 1000);
163 * converts screen coordinate (pixel) to time (ms)
165 static int xpos_to_time(int xpos
)
168 int range
= range_end
- range_start
;
169 retval
= range_start
+ (((xpos
- OSCI_X
) * range
) / OSCI_WIDTH
);
174 * Converts time (ms) to screen coordinates (pixel).
176 static int time_to_xpos(unsigned int time
)
181 if (time
< range_start
)
186 if (time
>= range_end
)
188 retval
= OSCI_X
+ OSCI_WIDTH
;
191 /* do the calculation */
194 int range
= range_end
- range_start
;
195 retval
= OSCI_X
+ ((time
- range_start
) * OSCI_WIDTH
) / range
;
201 * Updates the display of the textual data only.
203 static void update_data(void)
210 format_time_ms(timebuf
, sizeof buf
, xpos_to_time(split_x
));
211 rb
->snprintf(buf
, sizeof buf
, "Split at: %s", timebuf
);
213 rb
->lcd_getstringsize(buf
, &w
, &h
);
215 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
216 rb
->lcd_fillrect(0, 0, LCD_WIDTH
, h
);
217 rb
->lcd_set_drawmode(DRMODE_SOLID
);
218 rb
->lcd_puts(0, 0, buf
);
219 rb
->lcd_update_rect(0, 0, LCD_WIDTH
, h
);
223 * Displays which part of the song is visible
226 static void update_timebar(struct mp3entry
*mp3
)
228 rb
->gui_scrollbar_draw
230 rb
->screens
[SCREEN_MAIN
],0, TIMEBAR_Y
, LCD_WIDTH
, TIMEBAR_HEIGHT
,
231 mp3
->length
, range_start
, range_end
,
234 rb
->lcd_update_rect(0, TIMEBAR_Y
, LCD_WIDTH
, TIMEBAR_HEIGHT
);
238 * Marks the entire area of the osci buffer invalid.
239 * It will be drawn with new values in the next loop.
241 void splitedit_invalidate_osci(void)
244 validation_start
= ~(unsigned int)0;
248 * Returns the loop mode. See the LOOP_MODE_XXX constants above.
250 int splitedit_get_loop_mode(void)
256 * Updates the icons that display the Fn key hints.
258 static void update_icons(void)
260 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
261 rb
->lcd_fillrect(0, LCD_HEIGHT
- BMPHEIGHT
, LCD_WIDTH
, BMPHEIGHT
);
262 rb
->lcd_set_drawmode(DRMODE_SOLID
);
265 rb
->lcd_mono_bitmap(CUT_BMP
,
266 LCD_WIDTH
/ 3 / 2 - BMPWIDTH
/ 2, LCD_HEIGHT
- BMPHEIGHT
,
267 BMPWIDTH
, BMPHEIGHT
);
269 /* The loop mode icon */
270 rb
->lcd_mono_bitmap(LOOP_BMP
[splitedit_get_loop_mode()],
271 LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
272 BMPWIDTH
, BMPHEIGHT
);
274 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
276 rb
->lcd_mono_bitmap(SCALE_BMP
[rb
->peak_meter_get_use_dbfs() ? 1 : 0],
277 2 *LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
278 BMPWIDTH
, BMPHEIGHT
);
282 if (idx
< 0 || idx
> 1) idx
= 0;
284 rb
->lcd_mono_bitmap(SCALE_BMP
[idx
],
285 2 *LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
286 BMPWIDTH
, BMPHEIGHT
);
290 rb
->lcd_update_rect(0, LCD_HEIGHT
- BMPHEIGHT
, LCD_WIDTH
, BMPHEIGHT
);
294 * Sets the loop mode. See the LOOP_MODE_XXX constants above.
296 void splitedit_set_loop_mode(int mode
)
298 int old_loop_mode
= loop_mode
;
299 /* range restriction */
300 loop_mode
= mode
% (LOOP_MODE_FREE
+ 1);
304 play_start
= range_start
;
305 play_end
= range_end
;
309 play_start
= xpos_to_time(split_x
);
310 play_end
= range_end
;
314 play_start
= range_start
;
315 play_end
= xpos_to_time(split_x
);
319 /* play_start is used when the song plays beyond its end */
320 play_start
= range_start
;
321 play_end
= range_end
;
325 if (loop_mode
!= old_loop_mode
)
332 * Readraws the osci without clear.
334 static void redraw_osci(void)
337 for (x
= 0; x
< OSCI_WIDTH
; x
++)
339 if (osci_buffer
[x
] > 0)
343 OSCI_X
+ x
, OSCI_Y
+ OSCI_HEIGHT
- 1,
344 OSCI_X
+ x
, OSCI_Y
+ OSCI_HEIGHT
- osci_buffer
[x
] - 1
351 * Sets the range of time in which the user can finetune the split
352 * point. The split point is the center of the time range.
354 static void set_range_by_time(
355 struct mp3entry
*mp3
,
356 unsigned int split_time
,
361 if (range
< MIN_RANGE_SIZE
)
363 range
= MIN_RANGE_SIZE
;
365 range_start
= (split_time
> range
/ 2) ? (split_time
- range
/ 2) : 0;
366 range_end
= MIN(range_start
+ range
, mp3
->length
);
367 split_x
= time_to_xpos(split_time
);
369 splitedit_invalidate_osci();
371 /* this sets the play_start / play_end */
372 splitedit_set_loop_mode(splitedit_get_loop_mode());
380 * Set the split point in screen coordinates
382 void splitedit_set_split_x(int newx
)
384 int minx
= split_x
- 2 > 0 ? split_x
- 2: 0;
386 /* remove old split point from screen, only if moved */
389 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
390 rb
->lcd_fillrect(minx
, OSCI_Y
, 5, 1);
391 rb
->lcd_fillrect(split_x
-1 > 0 ? split_x
- 1: 0, OSCI_Y
+ 1, 3, 1);
392 rb
->lcd_fillrect(split_x
, OSCI_Y
+ 2, 1, OSCI_HEIGHT
- 2);
393 rb
->lcd_set_drawmode(DRMODE_SOLID
);
394 rb
->lcd_update_rect(minx
, OSCI_Y
, 5, OSCI_HEIGHT
);
397 if (newx
>= OSCI_X
&& newx
< OSCI_X
+ OSCI_WIDTH
)
400 /* in LOOP_FROM / LOOP_TO modes play_start /play_end must be updated */
401 splitedit_set_loop_mode(splitedit_get_loop_mode());
403 /* display new split time */
407 /* display new split point */
408 minx
= split_x
- 2 > 0 ? split_x
- 2: 0;
409 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
410 rb
->lcd_fillrect(minx
, OSCI_Y
, 5, 1);
411 rb
->lcd_fillrect(split_x
- 1 > 0 ? split_x
- 1: 0, OSCI_Y
+ 1, 3, 1);
412 rb
->lcd_fillrect(split_x
, OSCI_Y
+ 2, 1, OSCI_HEIGHT
- 2);
413 rb
->lcd_set_drawmode(DRMODE_SOLID
);
414 rb
->lcd_update_rect(minx
, OSCI_Y
, 5, OSCI_HEIGHT
);
418 * returns the split point in screen coordinates
420 int splitedit_get_split_x(void)
426 * Clears the osci area and redraws it
428 static void update_osci(void)
430 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
431 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
432 rb
->lcd_set_drawmode(DRMODE_SOLID
);
434 splitedit_set_split_x(splitedit_get_split_x());
435 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
439 * Zooms the visable and loopable range by the factor
440 * (counter / denominator). The split point is used as
441 * center point of the new selected range.
443 static void zoom(struct mp3entry
*mp3
, int counter
, int denominator
)
445 unsigned char oldbuf
[OSCI_WIDTH
];
446 int oldrange
= range_end
- range_start
;
447 int range
= oldrange
* counter
/ denominator
;
454 /* for stretching / shrinking a second buffer is needed */
455 rb
->memcpy(&oldbuf
, &osci_buffer
, sizeof osci_buffer
);
457 /* recalculate the new range and split point */
459 split
= xpos_to_time(split_x
);
461 set_range_by_time(mp3
, split
, range
);
462 range
= range_end
- range_start
;
464 splitx
= time_to_xpos(split
);
466 /* strech / shrink the existing osci buffer */
467 for (i
= 0; i
< OSCI_WIDTH
; i
++)
469 /* oldindex = (i + OSCI_X - splitx) * range / oldrange + oldsplitx ;*/
470 oldindex
= (i
*range
/ oldrange
) + oldsplitx
- (splitx
*range
/oldrange
);
471 if (oldindex
>= 0 && oldindex
< OSCI_WIDTH
)
473 osci_buffer
[i
] = oldbuf
[oldindex
];
481 splitx
= time_to_xpos(split
);
482 splitedit_set_split_x(splitx
);
483 splitedit_invalidate_osci();
487 static void scroll(struct mp3entry
*mp3
)
490 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
498 void splitedit_zoom_in(struct mp3entry
*mp3
)
500 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
501 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
502 rb
->lcd_set_drawmode(DRMODE_SOLID
);
504 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
512 void splitedit_zoom_out(struct mp3entry
*mp3
)
514 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
515 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
516 rb
->lcd_set_drawmode(DRMODE_SOLID
);
518 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
524 * Append part_no to the file name.
526 static void generateFileName(char* file_name
, int part_no
)
528 if (rb
->strlen(file_name
) <MAX_PATH
)
530 int len
= rb
->strlen(file_name
);
531 int ext_len
= rb
->strlen(".mp3");
533 &file_name
[len
- ext_len
],
537 /* shift the extension one position to the right*/
538 for (i
= len
; i
> len
- ext_len
; i
--)
540 file_name
[i
] = file_name
[i
- 1];
542 file_name
[len
- ext_len
] = '0' + part_no
;
546 rb
->splash(0, "wrong extension");
547 rb
->button_get(true);
548 rb
->button_get(true);
553 rb
->splash(0, "name too long");
554 rb
->button_get(true);
555 rb
->button_get(true);
562 * Copy bytes from src to dest while displaying a progressbar.
563 * The files must be already open.
565 static int copy_file(
573 unsigned char *buffer
;
575 ssize_t bytes_read
= 1; /* ensure the for loop is executed */
577 buffer
= rb
->plugin_get_buffer(&buffer_size
);
579 for (i
= 0; i
< bytes
&& bytes_read
> 0; i
+= bytes_read
)
581 ssize_t bytes_written
;
582 unsigned int bytes_to_read
=
583 bytes
- i
> buffer_size
? buffer_size
: bytes
- i
;
584 bytes_read
= rb
->read(src
, buffer
, bytes_to_read
);
585 bytes_written
= rb
->write(dest
, buffer
, bytes_read
);
587 if (bytes_written
< 0) {
588 rb
->splash(0, "Write failed in copy.");
589 rb
->button_get(true);
590 rb
->button_get(true);
594 button
= rb
->button_get(false);
596 if (button
== SPLITEDIT_QUIT
597 #ifdef SPLITEDIT_RC_QUIT
598 || button
== SPLITEDIT_RC_QUIT
:
601 rb
->splash(0, "Aborting copy.");
602 rb
->button_get(true);
603 rb
->button_get(true);
607 rb
->gui_scrollbar_draw(rb
->screens
[SCREEN_MAIN
],0, prg_y
, LCD_WIDTH
,
608 prg_h
, bytes
, 0, i
, HORIZONTAL
);
609 rb
->lcd_update_rect(0, prg_y
, LCD_WIDTH
, prg_h
);
616 * Save the files, if the file_name is not NULL
619 struct mp3entry
*mp3
,
624 int file1
, file2
, src_file
;
625 unsigned int end
= 0;
628 /* Verify that file 1 doesn't exit yet */
629 if (file_name1
!= NULL
)
631 file1
= rb
->open(file_name1
, O_RDONLY
);
635 rb
->splash(0, "File 1 exists. Please rename.");
636 rb
->button_get(true);
637 rb
->button_get(true);
642 /* Verify that file 2 doesn't exit yet */
643 if (file_name2
!= NULL
)
645 file2
= rb
->open(file_name2
, O_RDONLY
);
649 rb
->splash(0, "File 2 exists. Please rename.");
650 rb
->button_get(true);
651 rb
->button_get(true);
656 /* find the file position of the split point */
658 rb
->audio_ff_rewind(splittime
);
661 end
= rb
->audio_get_file_pos();
663 /* open the source file */
664 src_file
= rb
->open(mp3
->path
, O_RDONLY
);
670 unsigned long last_header
= rb
->mpeg_get_last_header();
672 rb
->lcd_getstringsize("M", &x
, &y
);
674 /* Find the next frame boundary */
675 rb
->lseek(src_file
, end
, SEEK_SET
);
676 rb
->find_next_frame(src_file
, &offset
, 8000, last_header
);
677 rb
->lseek(src_file
, 0, SEEK_SET
);
680 /* write the file 1 */
681 if (file_name1
!= NULL
)
683 file1
= rb
->open (file_name1
, O_WRONLY
| O_CREAT
);
686 int rc
= copy_file(file1
, src_file
, end
, y
*2 + 1, y
-1);
687 close_stat
= rb
->close(file1
);
691 rb
->splash(0, "failed closing file1: error %d", close_stat
);
692 rb
->button_get(true);
693 rb
->button_get(true);
695 /* If there was an error, cleanup */
697 rb
->remove(file_name1
);
703 rb
->splash(0, "Can't write File1: error %d", file1
);
704 rb
->button_get(true);
705 rb
->button_get(true);
709 /* if file1 hasn't been written we're not at the split point yet */
712 if (rb
->lseek(src_file
, end
, SEEK_SET
) < (off_t
)end
)
714 rb
->splash(0, "Src file to short: error %d", src_file
);
715 rb
->button_get(true);
716 rb
->button_get(true);
720 if (file_name2
!= NULL
)
723 file2
= rb
->open (file_name2
, O_WRONLY
| O_CREAT
);
726 end
= mp3
->filesize
- end
;
727 int rc
= copy_file(file2
, src_file
, end
, y
* 5 + 1, y
-1);
728 close_stat
= rb
->close(file2
);
732 rb
->splash(0, "failed: closing file2: error %d",
734 rb
->button_get(true);
735 rb
->button_get(true);
737 /* If there was an error, cleanup */
739 rb
->remove(file_name2
);
745 rb
->splash(0, "Can't write File2: error %d", file2
);
746 rb
->button_get(true);
747 rb
->button_get(true);
752 close_stat
= rb
->close(src_file
);
755 rb
->splash(0, "failed: closing src: error %d", close_stat
);
756 rb
->button_get(true);
757 rb
->button_get(true);
762 rb
->splash(0, "Source file not found");
763 rb
->button_get(true);
764 rb
->button_get(true);
774 * Let the user choose which file to save with which name
776 static void save_editor(struct mp3entry
*mp3
, int splittime
)
778 bool exit_request
= false;
780 int button
= BUTTON_NONE
;
781 char part1_name
[MAX_PATH
];
782 char part2_name
[MAX_PATH
];
783 bool part1_save
= true;
784 bool part2_save
= true;
786 /* file name for left part */
787 rb
->strncpy(part1_name
, mp3
->path
, MAX_PATH
);
788 generateFileName(part1_name
, 1);
790 /* file name for right part */
791 rb
->strncpy(part2_name
, mp3
->path
, MAX_PATH
);
792 generateFileName(part2_name
, 2);
794 while (!exit_request
)
797 rb
->lcd_clear_display();
800 rb
->lcd_puts_style(0, 0, "Save part 1?", choice
== SE_PART1_SAVE
);
801 rb
->lcd_puts(13, 0, part1_save
?"yes":"no");
803 /* trim to display the filename without path */
804 for (pos
= rb
->strlen(part1_name
); pos
> 0; pos
--)
806 if (part1_name
[pos
] == '/')
812 rb
->lcd_puts_scroll_style(0, 1,
813 &part1_name
[pos
], choice
== SE_PART1_NAME
);
816 rb
->lcd_puts_style(0, 3, "Save part 2?", choice
== SE_PART2_SAVE
);
817 rb
->lcd_puts(13, 3, part2_save
?"yes":"no");
819 /* trim to display the filename without path */
820 for (pos
= rb
->strlen(part2_name
); pos
> 0; pos
--)
822 if (part2_name
[pos
] == '/')
828 rb
->lcd_puts_scroll_style(0, 4,
829 &part2_name
[pos
], choice
== SE_PART2_NAME
);
832 rb
->lcd_puts_style(0, 6, "Save", choice
== SE_SAVE
);
837 button
= rb
->button_get(true);
841 choice
= (choice
+ SE_COUNT
- 1) % SE_COUNT
;
845 choice
= (choice
+ 1) % SE_COUNT
;
848 case SPLITEDIT_MENU_RUN
:
854 part1_save
= !part1_save
;
858 rb
->kbd_input(part1_name
, MAX_PATH
);
862 part2_save
= !part2_save
;
866 rb
->kbd_input(part2_name
, MAX_PATH
);
870 rb
->lcd_stop_scroll();
871 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
872 rb
->lcd_fillrect(0, 6*8, LCD_WIDTH
, LCD_HEIGHT
);
873 rb
->lcd_set_drawmode(DRMODE_SOLID
);
877 part1_save
?part1_name
:NULL
,
878 part2_save
?part2_name
:NULL
,
882 /* if something failed the user may go on choosing */
890 #ifdef SPLITEDIT_RC_QUIT
891 case SPLITEDIT_RC_QUIT
:
898 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
900 splitedit_exit_code
= PLUGIN_USB_CONNECTED
;
909 * The main loop of the editor
911 unsigned long splitedit_editor(struct mp3entry
* mp3_to_split
,
912 unsigned int split_time
,
915 int button
= BUTTON_NONE
;
916 int lastbutton
= BUTTON_NONE
;
917 struct mp3entry
*mp3
= mp3_to_split
;
918 unsigned int last_elapsed
= 0;
919 int lastx
= OSCI_X
+ (OSCI_WIDTH
/ 2);
924 /*unsigned short scheme = SCHEME_SPLIT_EDITOR;*/
925 bool exit_request
= false;
926 set_range_by_time(mp3
, split_time
, range
);
927 splitedit_set_loop_mode(LOOP_MODE_ALL
);
930 /*while (scheme != SCHEME_RETURN) {*/
931 while (!exit_request
)
933 unsigned int elapsed
;
937 elapsed
= mp3
->elapsed
;
938 x
= time_to_xpos(elapsed
);
940 /* are we still in the zoomed range? */
941 if (elapsed
> play_start
&& elapsed
< play_end
)
943 /* read volume info */
944 unsigned short volume
;
945 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
946 volume
= rb
->mas_codec_readreg(0x0c);
947 volume
+= rb
->mas_codec_readreg(0x0d);
949 volume
= rb
->peak_meter_scale_value(volume
, OSCI_HEIGHT
);
951 volume
= OSCI_HEIGHT
/ 2;
954 /* update osci_buffer */
955 if (osci_valid
|| lastx
== x
)
957 int index
= x
- OSCI_X
;
958 osci_buffer
[index
] = MAX(osci_buffer
[index
], volume
);
963 osci_buffer
[x
- OSCI_X
] = volume
;
964 for (i
= lastx
+ 1; i
< x
; i
++)
966 osci_buffer
[i
- OSCI_X
] = 0;
971 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
972 rb
->lcd_fillrect(lastx
+ 1, OSCI_Y
, x
- lastx
, OSCI_HEIGHT
);
973 rb
->lcd_set_drawmode(DRMODE_SOLID
);
975 if (osci_buffer
[x
- OSCI_X
] > 0)
978 for (i
= lastx
+1; i
<= x
; i
++)
982 i
, OSCI_Y
+ OSCI_HEIGHT
- 1,
983 i
, OSCI_Y
+ OSCI_HEIGHT
- osci_buffer
[i
- OSCI_X
]-1
988 /* mark the current position */
991 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
992 rb
->lcd_fillrect(lastx
, OSCI_Y
, 1, OSCI_HEIGHT
);
993 rb
->lcd_fillrect(x
, OSCI_Y
, 1, OSCI_HEIGHT
);
994 rb
->lcd_set_drawmode(DRMODE_SOLID
);
997 /* mark the split point */
998 if ((x
> split_x
- 2) && (lastx
< split_x
+ 3))
1000 if ((lastx
< split_x
) && (x
>= split_x
))
1002 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1005 split_x
, OSCI_Y
+ 2,
1008 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1010 rb
->lcd_drawline(split_x
-2, OSCI_Y
, split_x
+ 2, OSCI_Y
);
1011 rb
->lcd_drawline(split_x
-1, OSCI_Y
+1, split_x
+1,OSCI_Y
+1);
1017 rb
->lcd_update_rect(lastx
, OSCI_Y
, x
-lastx
+1, OSCI_HEIGHT
);
1024 OSCI_X
+ OSCI_WIDTH
- lastx
, OSCI_HEIGHT
1026 rb
->lcd_update_rect(0, OSCI_Y
, x
+ 1, OSCI_HEIGHT
);
1032 /* we're not in the zoom range -> rewind */
1035 if (elapsed
>= play_end
)
1037 switch (splitedit_get_loop_mode())
1039 unsigned int range_width
;
1044 rb
->audio_ff_rewind(range_start
);
1046 /* MMC is slow - wait some time to allow track reload to finish */
1048 if (mp3
->elapsed
> play_end
) /* reload in progress */
1049 rb
->splash(10*HZ
, "Wait - reloading");
1054 case LOOP_MODE_FROM
:
1056 rb
->audio_ff_rewind(xpos_to_time(split_x
));
1058 /* MMC is slow - wait some time to allow track reload to finish */
1060 if (mp3
->elapsed
> play_end
) /* reload in progress */
1061 rb
->splash(10*HZ
, "Wait - reloading");
1066 case LOOP_MODE_FREE
:
1067 range_width
= range_end
- range_start
;
1068 set_range_by_time(mp3
,
1069 range_end
+ range_width
/ 2, range_width
);
1071 /* play_end und play_start anpassen */
1072 splitedit_set_loop_mode(LOOP_MODE_FREE
);
1073 rb
->memset(osci_buffer
, 0, sizeof osci_buffer
);
1081 button
= rb
->button_get(false);
1084 /* here the evaluation of the key scheme starts.
1085 All functions the user triggers are called from
1086 within execute_scheme */
1087 /* key_scheme_execute(button, &scheme); */
1090 case SPLITEDIT_PLAY
:
1091 #ifdef SPLITEDIT_PLAY_PRE
1092 if (lastbutton
!= SPLITEDIT_PLAY_PRE
)
1096 rb
->audio_ff_rewind(xpos_to_time(split_x
));
1101 splitedit_zoom_in(mp3
);
1102 lastx
= time_to_xpos(mp3
->elapsed
);
1106 splitedit_zoom_out(mp3
);
1107 lastx
= time_to_xpos(mp3
->elapsed
);
1110 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1111 #ifdef SPLITEDIT_SPEED100
1112 case SPLITEDIT_SPEED150
:
1113 rb
->sound_set_pitch(1500);
1114 splitedit_invalidate_osci();
1117 case SPLITEDIT_SPEED100
:
1118 rb
->sound_set_pitch(1000);
1119 splitedit_invalidate_osci();
1122 case SPLITEDIT_SPEED50
:
1123 rb
->sound_set_pitch(500);
1124 splitedit_invalidate_osci();
1130 case BUTTON_LEFT
| BUTTON_REPEAT
:
1131 if (splitedit_get_split_x() > OSCI_X
+ 2)
1133 splitedit_set_split_x(splitedit_get_split_x() - 1);
1138 lastx
= time_to_xpos(mp3
->elapsed
);
1143 case BUTTON_RIGHT
| BUTTON_REPEAT
:
1144 if (splitedit_get_split_x() < OSCI_X
+ OSCI_WIDTH
-3)
1146 splitedit_set_split_x(splitedit_get_split_x() + 1);
1151 lastx
= time_to_xpos(mp3
->elapsed
);
1155 case SPLITEDIT_SAVE
:
1156 save_editor(mp3
, xpos_to_time(split_x
));
1157 rb
->lcd_clear_display();
1159 update_timebar(mp3
);
1163 case SPLITEDIT_LOOP_MODE
:
1164 splitedit_set_loop_mode(splitedit_get_loop_mode() + 1);
1168 case SPLITEDIT_SCALE
:
1169 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1170 rb
->peak_meter_set_use_dbfs(!rb
->peak_meter_get_use_dbfs());
1172 splitedit_invalidate_osci();
1176 #ifdef SPLITEDIT_RC_QUIT
1177 case SPLITEDIT_RC_QUIT
:
1179 case SPLITEDIT_QUIT
:
1180 exit_request
= true;
1184 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
1186 splitedit_exit_code
= PLUGIN_USB_CONNECTED
;
1187 exit_request
= true;
1192 if (button
!= BUTTON_NONE
)
1193 lastbutton
= button
;
1195 if (validation_start
== ~(unsigned int)0)
1197 if (elapsed
< range_end
&& elapsed
> range_start
)
1199 validation_start
= elapsed
;
1203 int endx
= time_to_xpos(range_end
);
1204 validation_start
= xpos_to_time(endx
- 2);
1206 last_elapsed
= elapsed
+ 1;
1210 if ((last_elapsed
<= validation_start
) &&
1211 (elapsed
> validation_start
))
1216 last_elapsed
= elapsed
;
1220 if (mp3
!= rb
->audio_current_track())
1222 struct mp3entry
*new_mp3
= rb
->audio_current_track();
1223 if (rb
->strncasecmp(path_mp3
, new_mp3
->path
,
1226 rb
->splash(0, "Abort due to file change");
1227 rb
->button_get(true);
1228 rb
->button_get(true);
1229 exit_request
= true;
1235 rb
->audio_flush_and_reload_tracks();
1236 rb
->audio_ff_rewind(range_start
);
1241 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1242 #ifdef SPLITEDIT_SPEED100
1243 rb
->sound_set_pitch(1000); /* make sure to reset pitch */
1251 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
1253 struct mp3entry
* mp3
;
1257 rb
->lcd_clear_display();
1259 mp3
= rb
->audio_current_track();
1262 if (rb
->audio_status() & AUDIO_STATUS_PAUSE
)
1266 splitedit_editor(mp3
, mp3
->elapsed
, MIN_RANGE_SIZE
* 8);
1270 rb
->splash(0, "Play or pause a mp3 file first.");
1271 rb
->button_get(true);
1272 rb
->button_get(true);
1274 return splitedit_exit_code
;