diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-04 17:20:41 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-04 17:20:41 +0300 |
commit | efb40105d657da935d3854e6ea7a513c6210224b (patch) | |
tree | 0327d88d68c0a402f0f90307756bb8536c54dc8b /src/gmdocument.c | |
parent | 25346114f96a29e8af6125e0cac3d5f8a2ffd551 (diff) |
Working on audio playback
Audio players are displayed the same way as images. When playing, a decoder runs in a background thread producing samples suitable for output.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 6e139e45..ff0e019b 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -308,6 +308,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
308 | run.color = white_ColorId; | 308 | run.color = white_ColorId; |
309 | run.linkId = 0; | 309 | run.linkId = 0; |
310 | run.imageId = 0; | 310 | run.imageId = 0; |
311 | run.audioId = 0; | ||
311 | enum iGmLineType type; | 312 | enum iGmLineType type; |
312 | int indent = 0; | 313 | int indent = 0; |
313 | /* Detect the type of the line. */ | 314 | /* Detect the type of the line. */ |
@@ -429,12 +430,12 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
429 | } | 430 | } |
430 | /* Quote icon. */ | 431 | /* Quote icon. */ |
431 | if (type == quote_GmLineType && addQuoteIcon) { | 432 | if (type == quote_GmLineType && addQuoteIcon) { |
432 | addQuoteIcon = iFalse; | 433 | addQuoteIcon = iFalse; |
433 | iGmRun quoteRun = run; | 434 | iGmRun quoteRun = run; |
434 | quoteRun.font = heading1_FontId; | 435 | quoteRun.font = heading1_FontId; |
435 | quoteRun.text = range_CStr(quote); | 436 | quoteRun.text = range_CStr(quote); |
436 | quoteRun.color = tmQuoteIcon_ColorId; | 437 | quoteRun.color = tmQuoteIcon_ColorId; |
437 | iRect vis = visualBounds_Text(quoteRun.font, quoteRun.text); | 438 | iRect vis = visualBounds_Text(quoteRun.font, quoteRun.text); |
438 | quoteRun.visBounds.size = advance_Text(quoteRun.font, quote); | 439 | quoteRun.visBounds.size = advance_Text(quoteRun.font, quote); |
439 | quoteRun.visBounds.pos = | 440 | quoteRun.visBounds.pos = |
440 | add_I2(pos, | 441 | add_I2(pos, |
@@ -522,6 +523,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
522 | /* Image content. */ | 523 | /* Image content. */ |
523 | if (type == link_GmLineType) { | 524 | if (type == link_GmLineType) { |
524 | const iMediaId imageId = findLinkImage_Media(d->media, run.linkId); | 525 | const iMediaId imageId = findLinkImage_Media(d->media, run.linkId); |
526 | const iMediaId audioId = !imageId ? findLinkAudio_Media(d->media, run.linkId) : 0; | ||
525 | if (imageId) { | 527 | if (imageId) { |
526 | iGmImageInfo img; | 528 | iGmImageInfo img; |
527 | imageInfo_Media(d->media, imageId, &img); | 529 | imageInfo_Media(d->media, imageId, &img); |
@@ -532,7 +534,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
532 | link->flags |= permanent_GmLinkFlag; | 534 | link->flags |= permanent_GmLinkFlag; |
533 | } | 535 | } |
534 | } | 536 | } |
535 | const int margin = 0.5f * lineHeight_Text(paragraph_FontId); | 537 | const int margin = lineHeight_Text(paragraph_FontId) / 2; |
536 | pos.y += margin; | 538 | pos.y += margin; |
537 | run.bounds.pos = pos; | 539 | run.bounds.pos = pos; |
538 | run.bounds.size.x = d->size.x; | 540 | run.bounds.size.x = d->size.x; |
@@ -554,6 +556,28 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
554 | pushBack_Array(&d->layout, &run); | 556 | pushBack_Array(&d->layout, &run); |
555 | pos.y += run.bounds.size.y + margin; | 557 | pos.y += run.bounds.size.y + margin; |
556 | } | 558 | } |
559 | else if (audioId) { | ||
560 | iGmAudioInfo info; | ||
561 | audioInfo_Media(d->media, audioId, &info); | ||
562 | /* Mark the link as having content. */ { | ||
563 | iGmLink *link = at_PtrArray(&d->links, run.linkId - 1); | ||
564 | link->flags |= content_GmLinkFlag; | ||
565 | if (info.isPermanent) { | ||
566 | link->flags |= permanent_GmLinkFlag; | ||
567 | } | ||
568 | } | ||
569 | const int margin = lineHeight_Text(paragraph_FontId) / 2; | ||
570 | pos.y += margin; | ||
571 | run.bounds.pos = pos; | ||
572 | run.bounds.size.x = d->size.x; | ||
573 | run.bounds.size.y = 2 * lineHeight_Text(uiContent_FontId); | ||
574 | run.visBounds = run.bounds; | ||
575 | run.text = iNullRange; | ||
576 | run.color = 0; | ||
577 | run.audioId = audioId; | ||
578 | pushBack_Array(&d->layout, &run); | ||
579 | pos.y += run.bounds.size.y + margin; | ||
580 | } | ||
557 | } | 581 | } |
558 | prevType = type; | 582 | prevType = type; |
559 | } | 583 | } |
@@ -1120,10 +1144,14 @@ const iTime *linkTime_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | |||
1120 | return link ? &link->when : NULL; | 1144 | return link ? &link->when : NULL; |
1121 | } | 1145 | } |
1122 | 1146 | ||
1123 | uint16_t linkImage_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | 1147 | iMediaId linkImage_GmDocument(const iGmDocument *d, iGmLinkId linkId) { |
1124 | return findLinkImage_Media(d->media, linkId); | 1148 | return findLinkImage_Media(d->media, linkId); |
1125 | } | 1149 | } |
1126 | 1150 | ||
1151 | iMediaId linkAudio_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | ||
1152 | return findLinkAudio_Media(d->media, linkId); | ||
1153 | } | ||
1154 | |||
1127 | enum iColorId linkColor_GmDocument(const iGmDocument *d, iGmLinkId linkId, enum iGmLinkPart part) { | 1155 | enum iColorId linkColor_GmDocument(const iGmDocument *d, iGmLinkId linkId, enum iGmLinkPart part) { |
1128 | const iGmLink *link = link_GmDocument_(d, linkId); | 1156 | const iGmLink *link = link_GmDocument_(d, linkId); |
1129 | const int www_GmLinkFlag = http_GmLinkFlag | mailto_GmLinkFlag; | 1157 | const int www_GmLinkFlag = http_GmLinkFlag | mailto_GmLinkFlag; |