1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Philipp Pertermann
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 /* variable button definitions */
27 #if CONFIG_KEYPAD == RECORDER_PAD
28 #define SPLITEDIT_QUIT BUTTON_OFF
29 #define SPLITEDIT_PLAY BUTTON_PLAY
30 #define SPLITEDIT_SAVE BUTTON_F1
31 #define SPLITEDIT_LOOP_MODE BUTTON_F2
32 #define SPLITEDIT_SCALE BUTTON_F3
33 #define SPLITEDIT_SPEED50 (BUTTON_ON | BUTTON_LEFT)
34 #define SPLITEDIT_SPEED100 (BUTTON_ON | BUTTON_PLAY)
35 #define SPLITEDIT_SPEED150 (BUTTON_ON | BUTTON_RIGHT)
36 #define SPLITEDIT_MENU_RUN BUTTON_PLAY
38 #elif CONFIG_KEYPAD == ONDIO_PAD
39 #define SPLITEDIT_QUIT BUTTON_OFF
40 #define SPLITEDIT_PLAY_PRE BUTTON_MENU
41 #define SPLITEDIT_PLAY (BUTTON_MENU | BUTTON_REL)
42 #define SPLITEDIT_SAVE (BUTTON_MENU | BUTTON_LEFT)
43 #define SPLITEDIT_LOOP_MODE (BUTTON_MENU | BUTTON_UP)
44 #define SPLITEDIT_SCALE (BUTTON_MENU | BUTTON_RIGHT)
45 #define SPLITEDIT_MENU_RUN BUTTON_RIGHT
47 #elif CONFIG_KEYPAD == IRIVER_H100_PAD
48 #define SPLITEDIT_QUIT BUTTON_OFF
49 #define SPLITEDIT_PLAY BUTTON_ON
50 #define SPLITEDIT_SAVE BUTTON_SELECT
51 #define SPLITEDIT_LOOP_MODE BUTTON_MODE
52 #define SPLITEDIT_SCALE (BUTTON_REC | BUTTON_UP)
53 #define SPLITEDIT_SPEED50 (BUTTON_REC | BUTTON_LEFT)
54 #define SPLITEDIT_SPEED100 (BUTTON_REC | BUTTON_DOWN)
55 #define SPLITEDIT_SPEED150 (BUTTON_REC | BUTTON_RIGHT)
56 #define SPLITEDIT_MENU_RUN BUTTON_RIGHT
58 #define SPLITEDIT_RC_QUIT BUTTON_RC_STOP
63 unsigned char LOOP_BMP
[][13] =
65 {0xfc,0x00,0x10,0x11,0x93,0x7f,0x13,0x11,0x7c,0x38,0x10,0x00,0x7c}, /*ALL */
66 {0x81,0x03,0x7f,0x03,0x91,0x10,0x10,0x10,0x7c,0x38,0x10,0x00,0x7c}, /*FROM*/
67 {0xfc,0x00,0x10,0x10,0x90,0x10,0x7c,0x38,0x11,0x03,0x7f,0x03,0x01}, /*TO */
68 {0x80,0x10,0x10,0x11,0x93,0x7f,0x13,0x11,0x10,0x7c,0x38,0x10,0x00}, /*FREE*/
71 unsigned char CUT_BMP
[] =
73 0xc1,0x63,0x63,0x36,0xb6,0x1c,0x1c,0x36,0x77,0x55,0x55,0x55,0x32,
76 unsigned char SCALE_BMP
[][13] =
78 {0x80,0x06,0x49,0x66,0xb0,0x18,0x0c,0x06,0x33,0x49,0x30,0x00,0x00}, /*lin*/
79 {0x80,0x30,0x78,0x48,0xff,0x7f,0x00,0x7f,0x7f,0x48,0x78,0x30,0x00}, /*db*/
83 #define TIMEBAR_HEIGHT 4
86 #define OSCI_Y (TIMEBAR_Y + TIMEBAR_HEIGHT + 1)
87 #define OSCI_WIDTH LCD_WIDTH
88 #define OSCI_HEIGHT (LCD_HEIGHT - BMPHEIGHT - OSCI_Y - 1)
90 /* Indices of the menu items in the save editor, see save_editor */
91 #define SE_PART1_SAVE 0
92 #define SE_PART1_NAME 1
93 #define SE_PART2_SAVE 2
94 #define SE_PART2_NAME 3
98 /* contains the file name of the song that is to be split */
99 static char path_mp3
[MAX_PATH
];
101 /* Exit code of this plugin */
102 static enum plugin_status splitedit_exit_code
= PLUGIN_OK
;
104 /* The range in time that the displayed aerea comprises */
105 static unsigned int range_start
= 0;
106 static unsigned int range_end
= 0;
108 /* The range in time that is being looped */
109 static unsigned int play_start
= 0;
110 static unsigned int play_end
= 0;
112 /* Point in time (pixel) at which the split mark is set */
113 static int split_x
= OSCI_X
+ (OSCI_WIDTH
/ 2);
115 /* Contains the peak values */
116 static unsigned char osci_buffer
[OSCI_WIDTH
];
118 /* if true peak values from a previous loop are only overwritten
119 if the new value is greater than the old value */
120 static bool osci_valid
= false;
123 * point in time from which on the osci_buffer is invalid
124 * if set to ~(unsigned int)0 the entire osci_buffer is invalid
126 static unsigned int validation_start
= ~(unsigned int)0;
128 /* all the visible aerea is looped */
129 #define LOOP_MODE_ALL 0
131 /* loop starts at split point, ends at right visible border */
132 #define LOOP_MODE_FROM 1
134 /* loop start at left visible border, ends at split point */
135 #define LOOP_MODE_TO 2
137 /* let the song play without looping */
138 #define LOOP_MODE_FREE 3
140 /* see LOOP_MODE_XXX constants vor valid values */
141 static int loop_mode
= LOOP_MODE_FREE
;
143 /* minimal allowed timespan (ms) of the visible (and looped) aerea*/
144 #define MIN_RANGE_SIZE 1000
146 /* Format time into buf.
148 * buf - buffer to format to.
149 * buf_size - size of buffer.
150 * time - time to format, in milliseconds.
152 static void format_time_ms(char* buf
, int buf_size
, int time
)
154 rb
->snprintf(buf
, buf_size
, "%d:%02d:%03d", time
/ 60000,
155 time
% 60000 / 1000, (time
% 60000) % 1000);
159 * converts screen coordinate (pixel) to time (ms)
161 static int xpos_to_time(int xpos
)
164 int range
= range_end
- range_start
;
165 retval
= range_start
+ (((xpos
- OSCI_X
) * range
) / OSCI_WIDTH
);
170 * Converts time (ms) to screen coordinates (pixel).
172 static int time_to_xpos(unsigned int time
)
177 if (time
< range_start
)
182 if (time
>= range_end
)
184 retval
= OSCI_X
+ OSCI_WIDTH
;
187 /* do the calculation */
190 int range
= range_end
- range_start
;
191 retval
= OSCI_X
+ ((time
- range_start
) * OSCI_WIDTH
) / range
;
197 * Updates the display of the textual data only.
199 static void update_data(void)
206 format_time_ms(timebuf
, sizeof buf
, xpos_to_time(split_x
));
207 rb
->snprintf(buf
, sizeof buf
, "Split at: %s", timebuf
);
209 rb
->lcd_getstringsize(buf
, &w
, &h
);
211 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
212 rb
->lcd_fillrect(0, 0, LCD_WIDTH
, h
);
213 rb
->lcd_set_drawmode(DRMODE_SOLID
);
214 rb
->lcd_puts(0, 0, buf
);
215 rb
->lcd_update_rect(0, 0, LCD_WIDTH
, h
);
219 * Displays which part of the song is visible
222 static void update_timebar(struct mp3entry
*mp3
)
224 rb
->gui_scrollbar_draw
226 rb
->screens
[SCREEN_MAIN
],0, TIMEBAR_Y
, LCD_WIDTH
, TIMEBAR_HEIGHT
,
227 mp3
->length
, range_start
, range_end
,
230 rb
->lcd_update_rect(0, TIMEBAR_Y
, LCD_WIDTH
, TIMEBAR_HEIGHT
);
234 * Marks the entire area of the osci buffer invalid.
235 * It will be drawn with new values in the next loop.
237 void splitedit_invalidate_osci(void)
240 validation_start
= ~(unsigned int)0;
244 * Returns the loop mode. See the LOOP_MODE_XXX constants above.
246 int splitedit_get_loop_mode(void)
252 * Updates the icons that display the Fn key hints.
254 static void update_icons(void)
256 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
257 rb
->lcd_fillrect(0, LCD_HEIGHT
- BMPHEIGHT
, LCD_WIDTH
, BMPHEIGHT
);
258 rb
->lcd_set_drawmode(DRMODE_SOLID
);
261 rb
->lcd_mono_bitmap(CUT_BMP
,
262 LCD_WIDTH
/ 3 / 2 - BMPWIDTH
/ 2, LCD_HEIGHT
- BMPHEIGHT
,
263 BMPWIDTH
, BMPHEIGHT
);
265 /* The loop mode icon */
266 rb
->lcd_mono_bitmap(LOOP_BMP
[splitedit_get_loop_mode()],
267 LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
268 BMPWIDTH
, BMPHEIGHT
);
270 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
272 rb
->lcd_mono_bitmap(SCALE_BMP
[rb
->peak_meter_get_use_dbfs() ? 1 : 0],
273 2 *LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
274 BMPWIDTH
, BMPHEIGHT
);
278 if (idx
< 0 || idx
> 1) idx
= 0;
280 rb
->lcd_mono_bitmap(SCALE_BMP
[idx
],
281 2 *LCD_WIDTH
/3 + LCD_WIDTH
/3 / 2 - BMPWIDTH
/2, LCD_HEIGHT
- BMPHEIGHT
,
282 BMPWIDTH
, BMPHEIGHT
);
286 rb
->lcd_update_rect(0, LCD_HEIGHT
- BMPHEIGHT
, LCD_WIDTH
, BMPHEIGHT
);
290 * Sets the loop mode. See the LOOP_MODE_XXX constants above.
292 void splitedit_set_loop_mode(int mode
)
294 int old_loop_mode
= loop_mode
;
295 /* range restriction */
296 loop_mode
= mode
% (LOOP_MODE_FREE
+ 1);
300 play_start
= range_start
;
301 play_end
= range_end
;
305 play_start
= xpos_to_time(split_x
);
306 play_end
= range_end
;
310 play_start
= range_start
;
311 play_end
= xpos_to_time(split_x
);
315 /* play_start is used when the song plays beyond its end */
316 play_start
= range_start
;
317 play_end
= range_end
;
321 if (loop_mode
!= old_loop_mode
)
328 * Readraws the osci without clear.
330 static void redraw_osci(void)
333 for (x
= 0; x
< OSCI_WIDTH
; x
++)
335 if (osci_buffer
[x
] > 0)
339 OSCI_X
+ x
, OSCI_Y
+ OSCI_HEIGHT
- 1,
340 OSCI_Y
+ OSCI_HEIGHT
- osci_buffer
[x
] - 1
347 * Sets the range of time in which the user can finetune the split
348 * point. The split point is the center of the time range.
350 static void set_range_by_time(
351 struct mp3entry
*mp3
,
352 unsigned int split_time
,
357 if (range
< MIN_RANGE_SIZE
)
359 range
= MIN_RANGE_SIZE
;
361 range_start
= (split_time
> range
/ 2) ? (split_time
- range
/ 2) : 0;
362 range_end
= MIN(range_start
+ range
, mp3
->length
);
363 split_x
= time_to_xpos(split_time
);
365 splitedit_invalidate_osci();
367 /* this sets the play_start / play_end */
368 splitedit_set_loop_mode(splitedit_get_loop_mode());
376 * Set the split point in screen coordinates
378 void splitedit_set_split_x(int newx
)
380 int minx
= split_x
- 2 > 0 ? split_x
- 2: 0;
382 /* remove old split point from screen, only if moved */
385 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
386 rb
->lcd_fillrect(minx
, OSCI_Y
, 5, 1);
387 rb
->lcd_fillrect(split_x
-1 > 0 ? split_x
- 1: 0, OSCI_Y
+ 1, 3, 1);
388 rb
->lcd_fillrect(split_x
, OSCI_Y
+ 2, 1, OSCI_HEIGHT
- 2);
389 rb
->lcd_set_drawmode(DRMODE_SOLID
);
390 rb
->lcd_update_rect(minx
, OSCI_Y
, 5, OSCI_HEIGHT
);
393 if (newx
>= OSCI_X
&& newx
< OSCI_X
+ OSCI_WIDTH
)
396 /* in LOOP_FROM / LOOP_TO modes play_start /play_end must be updated */
397 splitedit_set_loop_mode(splitedit_get_loop_mode());
399 /* display new split time */
403 /* display new split point */
404 minx
= split_x
- 2 > 0 ? split_x
- 2: 0;
405 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
406 rb
->lcd_fillrect(minx
, OSCI_Y
, 5, 1);
407 rb
->lcd_fillrect(split_x
- 1 > 0 ? split_x
- 1: 0, OSCI_Y
+ 1, 3, 1);
408 rb
->lcd_fillrect(split_x
, OSCI_Y
+ 2, 1, OSCI_HEIGHT
- 2);
409 rb
->lcd_set_drawmode(DRMODE_SOLID
);
410 rb
->lcd_update_rect(minx
, OSCI_Y
, 5, OSCI_HEIGHT
);
414 * returns the split point in screen coordinates
416 int splitedit_get_split_x(void)
422 * Clears the osci area and redraws it
424 static void update_osci(void)
426 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
427 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
428 rb
->lcd_set_drawmode(DRMODE_SOLID
);
430 splitedit_set_split_x(splitedit_get_split_x());
431 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
435 * Zooms the visable and loopable range by the factor
436 * (counter / denominator). The split point is used as
437 * center point of the new selected range.
439 static void zoom(struct mp3entry
*mp3
, int counter
, int denominator
)
441 unsigned char oldbuf
[OSCI_WIDTH
];
442 int oldrange
= range_end
- range_start
;
443 int range
= oldrange
* counter
/ denominator
;
450 /* for stretching / shrinking a second buffer is needed */
451 rb
->memcpy(&oldbuf
, &osci_buffer
, sizeof osci_buffer
);
453 /* recalculate the new range and split point */
455 split
= xpos_to_time(split_x
);
457 set_range_by_time(mp3
, split
, range
);
458 range
= range_end
- range_start
;
460 splitx
= time_to_xpos(split
);
462 /* strech / shrink the existing osci buffer */
463 for (i
= 0; i
< OSCI_WIDTH
; i
++)
465 /* oldindex = (i + OSCI_X - splitx) * range / oldrange + oldsplitx ;*/
466 oldindex
= (i
*range
/ oldrange
) + oldsplitx
- (splitx
*range
/oldrange
);
467 if (oldindex
>= 0 && oldindex
< OSCI_WIDTH
)
469 osci_buffer
[i
] = oldbuf
[oldindex
];
477 splitx
= time_to_xpos(split
);
478 splitedit_set_split_x(splitx
);
479 splitedit_invalidate_osci();
483 static void scroll(struct mp3entry
*mp3
)
486 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
494 void splitedit_zoom_in(struct mp3entry
*mp3
)
496 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
497 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, OSCI_WIDTH
, OSCI_HEIGHT
);
498 rb
->lcd_set_drawmode(DRMODE_SOLID
);
500 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
508 void splitedit_zoom_out(struct mp3entry
*mp3
)
510 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
511 rb
->lcd_fillrect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
512 rb
->lcd_set_drawmode(DRMODE_SOLID
);
514 rb
->lcd_update_rect(OSCI_X
, OSCI_Y
, LCD_WIDTH
, OSCI_HEIGHT
);
520 * Append part_no to the file name.
522 static void generateFileName(char* file_name
, int part_no
)
524 if (rb
->strlen(file_name
) <MAX_PATH
)
526 int len
= rb
->strlen(file_name
);
527 int ext_len
= rb
->strlen(".mp3");
529 &file_name
[len
- ext_len
],
533 /* shift the extension one position to the right*/
534 for (i
= len
; i
> len
- ext_len
; i
--)
536 file_name
[i
] = file_name
[i
- 1];
538 file_name
[len
- ext_len
] = '0' + part_no
;
542 rb
->splash(0, "wrong extension");
543 rb
->button_get(true);
544 rb
->button_get(true);
549 rb
->splash(0, "name too long");
550 rb
->button_get(true);
551 rb
->button_get(true);
558 * Copy bytes from src to dest while displaying a progressbar.
559 * The files must be already open.
561 static int copy_file(
569 unsigned char *buffer
;
571 ssize_t bytes_read
= 1; /* ensure the for loop is executed */
573 buffer
= rb
->plugin_get_buffer(&buffer_size
);
575 for (i
= 0; i
< bytes
&& bytes_read
> 0; i
+= bytes_read
)
577 ssize_t bytes_written
;
578 unsigned int bytes_to_read
=
579 bytes
- i
> buffer_size
? buffer_size
: bytes
- i
;
580 bytes_read
= rb
->read(src
, buffer
, bytes_to_read
);
581 bytes_written
= rb
->write(dest
, buffer
, bytes_read
);
583 if (bytes_written
< 0) {
584 rb
->splash(0, "Write failed in copy.");
585 rb
->button_get(true);
586 rb
->button_get(true);
590 button
= rb
->button_get(false);
592 if (button
== SPLITEDIT_QUIT
593 #ifdef SPLITEDIT_RC_QUIT
594 || button
== SPLITEDIT_RC_QUIT
:
597 rb
->splash(0, "Aborting copy.");
598 rb
->button_get(true);
599 rb
->button_get(true);
603 rb
->gui_scrollbar_draw(rb
->screens
[SCREEN_MAIN
],0, prg_y
, LCD_WIDTH
,
604 prg_h
, bytes
, 0, i
, HORIZONTAL
);
605 rb
->lcd_update_rect(0, prg_y
, LCD_WIDTH
, prg_h
);
612 * Save the files, if the file_name is not NULL
615 struct mp3entry
*mp3
,
620 int file1
, file2
, src_file
;
621 unsigned int end
= 0;
624 /* Verify that file 1 doesn't exit yet */
625 if (file_name1
!= NULL
)
627 file1
= rb
->open(file_name1
, O_RDONLY
);
631 rb
->splash(0, "File 1 exists. Please rename.");
632 rb
->button_get(true);
633 rb
->button_get(true);
638 /* Verify that file 2 doesn't exit yet */
639 if (file_name2
!= NULL
)
641 file2
= rb
->open(file_name2
, O_RDONLY
);
645 rb
->splash(0, "File 2 exists. Please rename.");
646 rb
->button_get(true);
647 rb
->button_get(true);
652 /* find the file position of the split point */
654 rb
->audio_ff_rewind(splittime
);
657 end
= rb
->audio_get_file_pos();
659 /* open the source file */
660 src_file
= rb
->open(mp3
->path
, O_RDONLY
);
666 unsigned long last_header
= rb
->mpeg_get_last_header();
668 rb
->lcd_getstringsize("M", &x
, &y
);
670 /* Find the next frame boundary */
671 rb
->lseek(src_file
, end
, SEEK_SET
);
672 rb
->find_next_frame(src_file
, &offset
, 8000, last_header
);
673 rb
->lseek(src_file
, 0, SEEK_SET
);
676 /* write the file 1 */
677 if (file_name1
!= NULL
)
679 file1
= rb
->open (file_name1
, O_WRONLY
| O_CREAT
);
682 int rc
= copy_file(file1
, src_file
, end
, y
*2 + 1, y
-1);
683 close_stat
= rb
->close(file1
);
687 rb
->splashf(0, "failed closing file1: error %d", close_stat
);
688 rb
->button_get(true);
689 rb
->button_get(true);
691 /* If there was an error, cleanup */
693 rb
->remove(file_name1
);
699 rb
->splashf(0, "Can't write File1: error %d", file1
);
700 rb
->button_get(true);
701 rb
->button_get(true);
705 /* if file1 hasn't been written we're not at the split point yet */
708 if (rb
->lseek(src_file
, end
, SEEK_SET
) < (off_t
)end
)
710 rb
->splashf(0, "Src file to short: error %d", src_file
);
711 rb
->button_get(true);
712 rb
->button_get(true);
716 if (file_name2
!= NULL
)
719 file2
= rb
->open (file_name2
, O_WRONLY
| O_CREAT
);
722 end
= mp3
->filesize
- end
;
723 int rc
= copy_file(file2
, src_file
, end
, y
* 5 + 1, y
-1);
724 close_stat
= rb
->close(file2
);
728 rb
->splashf(0, "failed: closing file2: error %d",
730 rb
->button_get(true);
731 rb
->button_get(true);
733 /* If there was an error, cleanup */
735 rb
->remove(file_name2
);
741 rb
->splashf(0, "Can't write File2: error %d", file2
);
742 rb
->button_get(true);
743 rb
->button_get(true);
748 close_stat
= rb
->close(src_file
);
751 rb
->splashf(0, "failed: closing src: error %d", close_stat
);
752 rb
->button_get(true);
753 rb
->button_get(true);
758 rb
->splash(0, "Source file not found");
759 rb
->button_get(true);
760 rb
->button_get(true);
770 * Let the user choose which file to save with which name
772 static void save_editor(struct mp3entry
*mp3
, int splittime
)
774 bool exit_request
= false;
776 int button
= BUTTON_NONE
;
777 char part1_name
[MAX_PATH
];
778 char part2_name
[MAX_PATH
];
779 bool part1_save
= true;
780 bool part2_save
= true;
782 /* file name for left part */
783 rb
->strncpy(part1_name
, mp3
->path
, MAX_PATH
);
784 generateFileName(part1_name
, 1);
786 /* file name for right part */
787 rb
->strncpy(part2_name
, mp3
->path
, MAX_PATH
);
788 generateFileName(part2_name
, 2);
790 while (!exit_request
)
793 rb
->lcd_clear_display();
796 rb
->lcd_puts_style(0, 0, "Save part 1?", choice
== SE_PART1_SAVE
);
797 rb
->lcd_puts(13, 0, part1_save
?"yes":"no");
799 /* trim to display the filename without path */
800 for (pos
= rb
->strlen(part1_name
); pos
> 0; pos
--)
802 if (part1_name
[pos
] == '/')
808 rb
->lcd_puts_scroll_style(0, 1,
809 &part1_name
[pos
], choice
== SE_PART1_NAME
);
812 rb
->lcd_puts_style(0, 3, "Save part 2?", choice
== SE_PART2_SAVE
);
813 rb
->lcd_puts(13, 3, part2_save
?"yes":"no");
815 /* trim to display the filename without path */
816 for (pos
= rb
->strlen(part2_name
); pos
> 0; pos
--)
818 if (part2_name
[pos
] == '/')
824 rb
->lcd_puts_scroll_style(0, 4,
825 &part2_name
[pos
], choice
== SE_PART2_NAME
);
828 rb
->lcd_puts_style(0, 6, "Save", choice
== SE_SAVE
);
833 button
= rb
->button_get(true);
837 choice
= (choice
+ SE_COUNT
- 1) % SE_COUNT
;
841 choice
= (choice
+ 1) % SE_COUNT
;
844 case SPLITEDIT_MENU_RUN
:
850 part1_save
= !part1_save
;
854 rb
->kbd_input(part1_name
, MAX_PATH
);
858 part2_save
= !part2_save
;
862 rb
->kbd_input(part2_name
, MAX_PATH
);
866 rb
->lcd_stop_scroll();
867 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
868 rb
->lcd_fillrect(0, 6*8, LCD_WIDTH
, LCD_HEIGHT
);
869 rb
->lcd_set_drawmode(DRMODE_SOLID
);
873 part1_save
?part1_name
:NULL
,
874 part2_save
?part2_name
:NULL
,
878 /* if something failed the user may go on choosing */
886 #ifdef SPLITEDIT_RC_QUIT
887 case SPLITEDIT_RC_QUIT
:
894 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
896 splitedit_exit_code
= PLUGIN_USB_CONNECTED
;
905 * The main loop of the editor
907 unsigned long splitedit_editor(struct mp3entry
* mp3_to_split
,
908 unsigned int split_time
,
911 int button
= BUTTON_NONE
;
912 int lastbutton
= BUTTON_NONE
;
913 struct mp3entry
*mp3
= mp3_to_split
;
914 unsigned int last_elapsed
= 0;
915 int lastx
= OSCI_X
+ (OSCI_WIDTH
/ 2);
920 /*unsigned short scheme = SCHEME_SPLIT_EDITOR;*/
921 bool exit_request
= false;
922 set_range_by_time(mp3
, split_time
, range
);
923 splitedit_set_loop_mode(LOOP_MODE_ALL
);
926 /*while (scheme != SCHEME_RETURN) {*/
927 while (!exit_request
)
929 unsigned int elapsed
;
933 elapsed
= mp3
->elapsed
;
934 x
= time_to_xpos(elapsed
);
936 /* are we still in the zoomed range? */
937 if (elapsed
> play_start
&& elapsed
< play_end
)
939 /* read volume info */
940 unsigned short volume
;
941 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
942 volume
= rb
->mas_codec_readreg(0x0c);
943 volume
+= rb
->mas_codec_readreg(0x0d);
945 volume
= rb
->peak_meter_scale_value(volume
, OSCI_HEIGHT
);
947 volume
= OSCI_HEIGHT
/ 2;
950 /* update osci_buffer */
951 if (osci_valid
|| lastx
== x
)
953 int index
= x
- OSCI_X
;
954 osci_buffer
[index
] = MAX(osci_buffer
[index
], volume
);
959 osci_buffer
[x
- OSCI_X
] = volume
;
960 for (i
= lastx
+ 1; i
< x
; i
++)
962 osci_buffer
[i
- OSCI_X
] = 0;
967 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
968 rb
->lcd_fillrect(lastx
+ 1, OSCI_Y
, x
- lastx
, OSCI_HEIGHT
);
969 rb
->lcd_set_drawmode(DRMODE_SOLID
);
971 if (osci_buffer
[x
- OSCI_X
] > 0)
974 for (i
= lastx
+1; i
<= x
; i
++)
978 i
, OSCI_Y
+ OSCI_HEIGHT
- 1,
979 OSCI_Y
+ OSCI_HEIGHT
- osci_buffer
[i
- OSCI_X
]-1
984 /* mark the current position */
987 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
988 rb
->lcd_fillrect(lastx
, OSCI_Y
, 1, OSCI_HEIGHT
);
989 rb
->lcd_fillrect(x
, OSCI_Y
, 1, OSCI_HEIGHT
);
990 rb
->lcd_set_drawmode(DRMODE_SOLID
);
993 /* mark the split point */
994 if ((x
> split_x
- 2) && (lastx
< split_x
+ 3))
996 if ((lastx
< split_x
) && (x
>= split_x
))
998 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
1001 split_x
, OSCI_Y
+ 2,
1004 rb
->lcd_set_drawmode(DRMODE_SOLID
);
1006 rb
->lcd_hline(split_x
-2, split_x
+ 2, OSCI_Y
);
1007 rb
->lcd_hline(split_x
-1, split_x
+1,OSCI_Y
+1);
1013 rb
->lcd_update_rect(lastx
, OSCI_Y
, x
-lastx
+1, OSCI_HEIGHT
);
1020 OSCI_X
+ OSCI_WIDTH
- lastx
, OSCI_HEIGHT
1022 rb
->lcd_update_rect(0, OSCI_Y
, x
+ 1, OSCI_HEIGHT
);
1028 /* we're not in the zoom range -> rewind */
1031 if (elapsed
>= play_end
)
1033 switch (splitedit_get_loop_mode())
1035 unsigned int range_width
;
1040 rb
->audio_ff_rewind(range_start
);
1041 #if (CONFIG_STORAGE & STORAGE_MMC)
1042 /* MMC is slow - wait some time to allow track reload to finish */
1044 if (mp3
->elapsed
> play_end
) /* reload in progress */
1045 rb
->splash(10*HZ
, "Wait - reloading");
1050 case LOOP_MODE_FROM
:
1052 rb
->audio_ff_rewind(xpos_to_time(split_x
));
1053 #if (CONFIG_STORAGE & STORAGE_MMC)
1054 /* MMC is slow - wait some time to allow track reload to finish */
1056 if (mp3
->elapsed
> play_end
) /* reload in progress */
1057 rb
->splash(10*HZ
, "Wait - reloading");
1062 case LOOP_MODE_FREE
:
1063 range_width
= range_end
- range_start
;
1064 set_range_by_time(mp3
,
1065 range_end
+ range_width
/ 2, range_width
);
1067 /* play_end und play_start anpassen */
1068 splitedit_set_loop_mode(LOOP_MODE_FREE
);
1069 rb
->memset(osci_buffer
, 0, sizeof osci_buffer
);
1077 button
= rb
->button_get(false);
1080 /* here the evaluation of the key scheme starts.
1081 All functions the user triggers are called from
1082 within execute_scheme */
1083 /* key_scheme_execute(button, &scheme); */
1086 case SPLITEDIT_PLAY
:
1087 #ifdef SPLITEDIT_PLAY_PRE
1088 if (lastbutton
!= SPLITEDIT_PLAY_PRE
)
1092 rb
->audio_ff_rewind(xpos_to_time(split_x
));
1097 splitedit_zoom_in(mp3
);
1098 lastx
= time_to_xpos(mp3
->elapsed
);
1102 splitedit_zoom_out(mp3
);
1103 lastx
= time_to_xpos(mp3
->elapsed
);
1106 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1107 #ifdef SPLITEDIT_SPEED100
1108 case SPLITEDIT_SPEED150
:
1109 rb
->sound_set_pitch(1500);
1110 splitedit_invalidate_osci();
1113 case SPLITEDIT_SPEED100
:
1114 rb
->sound_set_pitch(1000);
1115 splitedit_invalidate_osci();
1118 case SPLITEDIT_SPEED50
:
1119 rb
->sound_set_pitch(500);
1120 splitedit_invalidate_osci();
1126 case BUTTON_LEFT
| BUTTON_REPEAT
:
1127 if (splitedit_get_split_x() > OSCI_X
+ 2)
1129 splitedit_set_split_x(splitedit_get_split_x() - 1);
1134 lastx
= time_to_xpos(mp3
->elapsed
);
1139 case BUTTON_RIGHT
| BUTTON_REPEAT
:
1140 if (splitedit_get_split_x() < OSCI_X
+ OSCI_WIDTH
-3)
1142 splitedit_set_split_x(splitedit_get_split_x() + 1);
1147 lastx
= time_to_xpos(mp3
->elapsed
);
1151 case SPLITEDIT_SAVE
:
1152 save_editor(mp3
, xpos_to_time(split_x
));
1153 rb
->lcd_clear_display();
1155 update_timebar(mp3
);
1159 case SPLITEDIT_LOOP_MODE
:
1160 splitedit_set_loop_mode(splitedit_get_loop_mode() + 1);
1164 case SPLITEDIT_SCALE
:
1165 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1166 rb
->peak_meter_set_use_dbfs(!rb
->peak_meter_get_use_dbfs());
1168 splitedit_invalidate_osci();
1172 #ifdef SPLITEDIT_RC_QUIT
1173 case SPLITEDIT_RC_QUIT
:
1175 case SPLITEDIT_QUIT
:
1176 exit_request
= true;
1180 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
1182 splitedit_exit_code
= PLUGIN_USB_CONNECTED
;
1183 exit_request
= true;
1188 if (button
!= BUTTON_NONE
)
1189 lastbutton
= button
;
1191 if (validation_start
== ~(unsigned int)0)
1193 if (elapsed
< range_end
&& elapsed
> range_start
)
1195 validation_start
= elapsed
;
1199 int endx
= time_to_xpos(range_end
);
1200 validation_start
= xpos_to_time(endx
- 2);
1202 last_elapsed
= elapsed
+ 1;
1206 if ((last_elapsed
<= validation_start
) &&
1207 (elapsed
> validation_start
))
1212 last_elapsed
= elapsed
;
1216 if (mp3
!= rb
->audio_current_track())
1218 struct mp3entry
*new_mp3
= rb
->audio_current_track();
1219 if (rb
->strncasecmp(path_mp3
, new_mp3
->path
,
1222 rb
->splash(0, "Abort due to file change");
1223 rb
->button_get(true);
1224 rb
->button_get(true);
1225 exit_request
= true;
1231 rb
->audio_flush_and_reload_tracks();
1232 rb
->audio_ff_rewind(range_start
);
1237 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1238 #ifdef SPLITEDIT_SPEED100
1239 rb
->sound_set_pitch(1000); /* make sure to reset pitch */
1247 enum plugin_status
plugin_start(const void* parameter
)
1249 struct mp3entry
* mp3
;
1252 rb
->lcd_clear_display();
1254 mp3
= rb
->audio_current_track();
1257 if (rb
->audio_status() & AUDIO_STATUS_PAUSE
)
1261 splitedit_editor(mp3
, mp3
->elapsed
, MIN_RANGE_SIZE
* 8);
1265 rb
->splash(0, "Play or pause a mp3 file first.");
1266 rb
->button_get(true);
1267 rb
->button_get(true);
1269 return splitedit_exit_code
;